remove AMAZON_AWS_HOST export, fix regex per review feedback

Signed-off-by: Leon Stein <leons727@gmail.com>
This commit is contained in:
Leon Stein
2021-12-28 11:42:23 -05:00
parent 60dee60d9b
commit e662ee528b
2 changed files with 6 additions and 10 deletions
@@ -30,7 +30,6 @@ import getRawBody from 'raw-body';
import {
AwsS3Integration,
ScmIntegrations,
AMAZON_AWS_HOST,
AwsS3IntegrationConfig,
} from '@backstage/integration';
import { ForwardedError, NotModifiedError } from '@backstage/errors';
@@ -75,9 +74,9 @@ const parseURL = (
}
// Only extract region from *.amazonaws.com hosts
if (config.host === AMAZON_AWS_HOST) {
if (config.host === 'amazonaws.com') {
// At this point bucket prefix is removed from host for virtual hosted URLs
const match = host.match(/^s3\.([a-z\d-]+)\.amazonaws.com$/);
const match = host.match(/^s3\.([a-z\d-]+)\.amazonaws\.com$/);
if (!match) {
throw new Error(
`invalid AWS S3 URL, cannot parse region from host in ${url}`,
@@ -105,10 +104,7 @@ export class AwsS3UrlReader implements UrlReader {
const s3 = new S3({
apiVersion: '2006-03-01',
credentials: creds,
endpoint:
integration.config.host === AMAZON_AWS_HOST
? undefined
: integration.config.endpoint,
endpoint: integration.config.endpoint,
s3ForcePathStyle: integration.config.s3ForcePathStyle,
});
const reader = new AwsS3UrlReader(integration, {
+3 -3
View File
@@ -16,7 +16,7 @@
import { Config } from '@backstage/config';
export const AMAZON_AWS_HOST = 'amazonaws.com';
const AMAZON_AWS_HOST = 'amazonaws.com';
/**
* The configuration parameters for a single AWS S3 provider.
@@ -83,12 +83,12 @@ export function readAwsS3IntegrationConfig(
pathname = url.pathname;
} catch {
throw new Error(
`Invalid awsS3 integration config, endpoint '${endpoint}' is not a valid URL`,
`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}'`,
`invalid awsS3 integration config, endpoints cannot contain path, got '${endpoint}'`,
);
}
} else {