Support bucketRootPath configuration for AWS and GCS in publish commands

Introduces command options `--awsBucketRootPath` and `--gcsBucketRootPath` which
map to respective publisher configurations, allowing users to upload files to S3
and GCS in a non-root directory.

Signed-off-by: Colton Padden <colton.padden@fastmail.com>
This commit is contained in:
Colton Padden
2021-11-17 08:48:28 -05:00
parent d701630972
commit b41e8f158c
4 changed files with 23 additions and 0 deletions
@@ -90,6 +90,10 @@ export function registerCommands(program: CommanderStatic) {
'--awsS3ForcePathStyle',
'Optional AWS S3 option to force path style.',
)
.option(
'--awsBucketRootPath',
'Optional sub-directory to store files in Amazon S3',
)
.option(
'--osCredentialId <OPENSTACK SWIFT APPLICATION CREDENTIAL ID>',
'(Required for OpenStack) specify when --publisher-type openStackSwift',
@@ -177,6 +181,10 @@ export function registerCommands(program: CommanderStatic) {
'--osSwiftUrl <OPENSTACK SWIFT SWIFTURL>',
'(Required for OpenStack) specify when --publisher-type openStackSwift',
)
.option(
'--gcsBucketRootPath',
'Optional sub-directory to store files in Google cloud storage',
)
.option(
'--directory <PATH>',
'Path of the directory containing generated files to publish',
@@ -68,6 +68,7 @@ describe('getValidPublisherConfig', () => {
const config = {
publisherType: 'awsS3',
storageName: 'someStorageName',
awsBucketRootPath: 'backstage-data/techdocs',
} as unknown as Command;
const actualConfig = PublisherConfig.getValidConfig(config);
@@ -75,6 +76,9 @@ describe('getValidPublisherConfig', () => {
expect(
actualConfig.getString('techdocs.publisher.awsS3.bucketName'),
).toBe('someStorageName');
expect(
actualConfig.getString('techdocs.publisher.awsS3.bucketRootPath'),
).toBe('backstage-data/techdocs');
});
});
@@ -127,6 +131,7 @@ describe('getValidPublisherConfig', () => {
const config = {
publisherType: 'googleGcs',
storageName: 'someStorageName',
gcsBucketRootPath: 'backstage-data/techdocs',
} as unknown as Command;
const actualConfig = PublisherConfig.getValidConfig(config);
@@ -136,6 +141,9 @@ describe('getValidPublisherConfig', () => {
expect(
actualConfig.getString('techdocs.publisher.googleGcs.bucketName'),
).toBe('someStorageName');
expect(
actualConfig.getString('techdocs.publisher.googleGcs.bucketRootPath'),
).toBe('backstage-data/techdocs');
});
});
});
@@ -85,6 +85,7 @@ export class PublisherConfig {
type: 'awsS3',
awsS3: {
bucketName: cmd.storageName,
...(cmd.awsBucketRootPath && { bucketRootPath: cmd.awsBucketRootPath }),
...(cmd.awsRoleArn && { credentials: { roleArn: cmd.awsRoleArn } }),
...(cmd.awsEndpoint && { endpoint: cmd.awsEndpoint }),
...(cmd.awsS3ForcePathStyle && { s3ForcePathStyle: true }),
@@ -122,6 +123,7 @@ export class PublisherConfig {
type: 'googleGcs',
googleGcs: {
bucketName: cmd.storageName,
...(cmd.gcsBucketRootPath && { bucketRootPath: cmd.gcsBucketRootPath }),
},
};
}