@backstage/integration
Version:
Helpers for managing integrations towards external systems
54 lines (51 loc) • 1.53 kB
JavaScript
;
const AMAZON_AWS_HOST = "amazonaws.com";
function readAwsS3IntegrationConfig(config) {
const endpoint = config.getOptionalString("endpoint");
const s3ForcePathStyle = config.getOptionalBoolean("s3ForcePathStyle") ?? false;
let host;
let pathname;
if (endpoint) {
try {
const url = new URL(endpoint);
host = url.host;
pathname = url.pathname;
} catch {
throw new Error(
`invalid awsS3 integration config, endpoint '${endpoint}' is not a valid URL`
);
}
if (pathname !== "/") {
throw new Error(
`invalid awsS3 integration config, endpoints cannot contain path, got '${endpoint}'`
);
}
} else {
host = AMAZON_AWS_HOST;
}
const accessKeyId = config.getOptionalString("accessKeyId");
const secretAccessKey = config.getOptionalString("secretAccessKey")?.trim();
const roleArn = config.getOptionalString("roleArn");
const externalId = config.getOptionalString("externalId");
return {
host,
endpoint,
s3ForcePathStyle,
accessKeyId,
secretAccessKey,
roleArn,
externalId
};
}
function readAwsS3IntegrationConfigs(configs) {
const result = configs.map(readAwsS3IntegrationConfig);
if (!result.some((c) => c.host === AMAZON_AWS_HOST)) {
result.push({
host: AMAZON_AWS_HOST
});
}
return result;
}
exports.readAwsS3IntegrationConfig = readAwsS3IntegrationConfig;
exports.readAwsS3IntegrationConfigs = readAwsS3IntegrationConfigs;
//# sourceMappingURL=config.cjs.js.map