updated AWSS3UrlReader to support CN domain
Signed-off-by: tejashwikalptaru <ext.tejashwi.taru@ef.com>
This commit is contained in:
@@ -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