From b8cb1200921552e1f12e087a6a09c8f20dc05a4c Mon Sep 17 00:00:00 2001 From: Sean Tan Date: Mon, 26 Jul 2021 09:47:04 -0700 Subject: [PATCH] Started changes from suggestions made on recent PR. Signed-off-by: Sean Tan --- .changeset/beige-trainers-run.md | 6 ------ .changeset/wicked-spoons-perform.md | 6 ++++++ .../backend-common/src/reading/AwsS3UrlReader.ts | 13 ++++++++++--- packages/integration/config.d.ts | 14 ++++++++++++++ packages/integration/src/awsS3/config.ts | 2 +- 5 files changed, 31 insertions(+), 10 deletions(-) delete mode 100644 .changeset/beige-trainers-run.md create mode 100644 .changeset/wicked-spoons-perform.md diff --git a/.changeset/beige-trainers-run.md b/.changeset/beige-trainers-run.md deleted file mode 100644 index 70632a3e48..0000000000 --- a/.changeset/beige-trainers-run.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -'@backstage/backend-common': minor -'@backstage/integration': minor ---- - -Add AWS S3 Url Reader diff --git a/.changeset/wicked-spoons-perform.md b/.changeset/wicked-spoons-perform.md new file mode 100644 index 0000000000..61c489df13 --- /dev/null +++ b/.changeset/wicked-spoons-perform.md @@ -0,0 +1,6 @@ +--- +'@backstage/backend-common': patch +'@backstage/integration': patch +--- + +Add AWS S3 URL Reader diff --git a/packages/backend-common/src/reading/AwsS3UrlReader.ts b/packages/backend-common/src/reading/AwsS3UrlReader.ts index b92edc7514..e178c2a104 100644 --- a/packages/backend-common/src/reading/AwsS3UrlReader.ts +++ b/packages/backend-common/src/reading/AwsS3UrlReader.ts @@ -34,8 +34,15 @@ const parseURL = ( ): { path: string; bucket: string; region: string } => { let { host, pathname } = new URL(url); + /** + * Removes the trailing '/' from the pathname to be processed + * by AWS S3 SDK methods. + */ pathname = pathname.substr(1); - + /** * + * This checks that the given URL is a valid S3 object url. + * Format of a Valid URL: https://bucket-name.s3.Region.amazonaws.com/keyname + */ const validHost = new RegExp( /^[a-z\d][a-z\d\.-]{1,61}[a-z\d]\.s3\.[a-z\d-]+\.amazonaws.com$/, ); @@ -64,8 +71,8 @@ export class AwsS3UrlReader implements UrlReader { ); let s3: S3; if (!awsS3Config.accessKeyId || !awsS3Config.secretAccessKey) { - logger.info( - 'awsS3 credentials not found in config. Using default credentials provider.', + logger.debug( + 'integrations.awsS3 not found in app config. AWS S3 integration will use default AWS credentials if set in environment.', ); s3 = new S3({}); } else { diff --git a/packages/integration/config.d.ts b/packages/integration/config.d.ts index 501373de53..d4721776d7 100644 --- a/packages/integration/config.d.ts +++ b/packages/integration/config.d.ts @@ -163,5 +163,19 @@ export interface Config { */ privateKey?: string; }; + + /** Integration configuration for AWS S3 Service */ + awsS3?: { + /** + * Account access key used to authenticate requests. + * @visibility backend + */ + accessKeyID?: string; + /** + * Account secret key used to authenticate requests. + * @visibility secret + */ + secretAccessKey?: string; + }; }; } diff --git a/packages/integration/src/awsS3/config.ts b/packages/integration/src/awsS3/config.ts index f896bbbef2..3e52ccb694 100644 --- a/packages/integration/src/awsS3/config.ts +++ b/packages/integration/src/awsS3/config.ts @@ -53,5 +53,5 @@ export function readAwsS3IntegrationConfig( const secretAccessKey = config.getString('secretAccessKey'); - return { accessKeyId: accessKeyId, secretAccessKey: secretAccessKey }; + return { accessKeyId, secretAccessKey }; }