fix: treat any url ending with amazonaws.com or amazonaws.com.cn as Amazon hosted
Signed-off-by: Travis O'Neal <wtravisoneal@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-defaults': patch
|
||||
---
|
||||
|
||||
Fixed `AwsS3UrlReader` failing to read files from S3 buckets configured with custom endpoint hosts. When an integration was configured with a specific endpoint like `https://bucket-1.s3.eu-central-1.amazonaws.com`, the URL parser incorrectly fell through to the non-AWS code path, always defaulting the region to `us-east-1` instead of extracting it from the hostname.
|
||||
@@ -128,6 +128,55 @@ describe('parseUrl', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('supports aws formats with custom endpoint hosts', () => {
|
||||
expect(
|
||||
parseUrl(
|
||||
'https://bucket-1.s3.eu-central-1.amazonaws.com/path/to/file.yaml',
|
||||
{
|
||||
host: 'bucket-1.s3.eu-central-1.amazonaws.com',
|
||||
},
|
||||
),
|
||||
).toEqual({
|
||||
path: 'path/to/file.yaml',
|
||||
bucket: 'bucket-1',
|
||||
region: 'eu-central-1',
|
||||
});
|
||||
expect(
|
||||
parseUrl('https://my-bucket.s3.cn-north-1.amazonaws.com.cn/data.json', {
|
||||
host: 'my-bucket.s3.cn-north-1.amazonaws.com.cn',
|
||||
}),
|
||||
).toEqual({
|
||||
path: 'data.json',
|
||||
bucket: 'my-bucket',
|
||||
region: 'cn-north-1',
|
||||
});
|
||||
expect(
|
||||
parseUrl(
|
||||
'https://s3.eu-central-1.amazonaws.com/my-bucket/path/to/file.yaml',
|
||||
{
|
||||
host: 's3.eu-central-1.amazonaws.com',
|
||||
},
|
||||
),
|
||||
).toEqual({
|
||||
path: 'path/to/file.yaml',
|
||||
bucket: 'my-bucket',
|
||||
region: 'eu-central-1',
|
||||
});
|
||||
expect(
|
||||
parseUrl(
|
||||
'https://s3.eu-central-1.amazonaws.com/my-bucket/path/to/file.yaml',
|
||||
{
|
||||
host: 's3.eu-central-1.amazonaws.com',
|
||||
s3ForcePathStyle: true,
|
||||
},
|
||||
),
|
||||
).toEqual({
|
||||
path: 'path/to/file.yaml',
|
||||
bucket: 'my-bucket',
|
||||
region: 'eu-central-1',
|
||||
});
|
||||
});
|
||||
|
||||
it('supports all non-aws formats', () => {
|
||||
expect(
|
||||
parseUrl('https://my-host.com/my.bucket-3/a/puppy.jpg', {
|
||||
|
||||
@@ -74,7 +74,10 @@ export function parseUrl(
|
||||
const host = parsedUrl.host;
|
||||
|
||||
// Treat Amazon hosted separately because it has special region logic
|
||||
if (config.host === 'amazonaws.com' || config.host === 'amazonaws.com.cn') {
|
||||
if (
|
||||
config.host.endsWith('amazonaws.com') ||
|
||||
config.host.endsWith('amazonaws.com.cn')
|
||||
) {
|
||||
const match = host.match(
|
||||
/^(?:([a-z0-9.-]+)\.)?s3(?:[.-]([a-z0-9-]+))?\.amazonaws\.com(\.cn)?$/,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user