Merge pull request #21407 from efdigital/feat/EFD-8393
updated AWSS3UrlReader to support CN domain
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-common': patch
|
||||
---
|
||||
|
||||
Fixed the AwsS3UrlReader host regex and host to allow the S3 reading for CN AWS domain
|
||||
@@ -53,6 +53,39 @@ describe('parseUrl', () => {
|
||||
bucket: 'my.bucket-3',
|
||||
region: 'us-east-1',
|
||||
});
|
||||
expect(
|
||||
parseUrl('https://s3.amazonaws.com.cn/my.bucket-3/a/puppy.jpg', {
|
||||
host: 'amazonaws.com',
|
||||
}),
|
||||
).toEqual({
|
||||
path: 'a/puppy.jpg',
|
||||
bucket: 'my.bucket-3',
|
||||
region: 'us-east-1',
|
||||
});
|
||||
expect(
|
||||
parseUrl(
|
||||
'https://ec-backstage-staging.s3.cn-north-1.amazonaws.com.cn/payments-prod-oas30.json',
|
||||
{
|
||||
host: 'amazonaws.com',
|
||||
},
|
||||
),
|
||||
).toEqual({
|
||||
path: 'payments-prod-oas30.json',
|
||||
bucket: 'ec-backstage-staging',
|
||||
region: 'cn-north-1',
|
||||
});
|
||||
expect(
|
||||
parseUrl(
|
||||
'https://ec-backstage-staging.s3.cn-north-1.amazonaws.com.cn/payments-prod-oas30.json',
|
||||
{
|
||||
host: 'amazonaws.com.cn',
|
||||
},
|
||||
),
|
||||
).toEqual({
|
||||
path: 'payments-prod-oas30.json',
|
||||
bucket: 'ec-backstage-staging',
|
||||
region: 'cn-north-1',
|
||||
});
|
||||
expect(
|
||||
parseUrl('https://s3.us-west-2.amazonaws.com/my.bucket-3/a/puppy.jpg', {
|
||||
host: 'amazonaws.com',
|
||||
|
||||
@@ -69,9 +69,9 @@ export function parseUrl(
|
||||
const host = parsedUrl.host;
|
||||
|
||||
// Treat Amazon hosted separately because it has special region logic
|
||||
if (config.host === 'amazonaws.com') {
|
||||
if (config.host === 'amazonaws.com' || config.host === 'amazonaws.com.cn') {
|
||||
const match = host.match(
|
||||
/^(?:([a-z0-9.-]+)\.)?s3(?:[.-]([a-z0-9-]+))?\.amazonaws\.com$/,
|
||||
/^(?:([a-z0-9.-]+)\.)?s3(?:[.-]([a-z0-9-]+))?\.amazonaws\.com(\.cn)?$/,
|
||||
);
|
||||
if (!match) {
|
||||
throw new Error(`Invalid AWS S3 URL ${url}`);
|
||||
|
||||
Reference in New Issue
Block a user