From dc99893b0ab1fc62b2f67999400c0e626b31a8b8 Mon Sep 17 00:00:00 2001 From: Marko Malenic Date: Fri, 23 Feb 2024 07:35:44 +1100 Subject: [PATCH] fix: queue service name and secret name --- config/constants.ts | 34 ++++++++++++++++++++----- lib/workload/orcabus-stateless-stack.ts | 2 +- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/config/constants.ts b/config/constants.ts index 451fcecd9..e8c8d0a39 100644 --- a/config/constants.ts +++ b/config/constants.ts @@ -10,7 +10,10 @@ import { EventSourceProps } from '../lib/workload/stateful/event_source/componen const regName = 'OrcaBusSchemaRegistry'; const eventBusName = 'OrcaBusMain'; const lambdaSecurityGroupName = 'OrcaBusLambdaSecurityGroup'; -const rdsMasterSecretName = 'orcabus/rds-master'; // pragma: allowlist secret + +// Note, this should not end with a hyphen and 6 characters, otherwise secrets manager won't be +// able to find the secret using a partial ARN. +const rdsMasterSecretName = 'orcabus/master-rds'; // pragma: allowlist secret const orcaBusStatefulConfig = { schemaRegistryProps: { @@ -90,12 +93,25 @@ interface EnvironmentConfig { orcaBusStatelessConfig: OrcaBusStatelessConfig; }; } + +/** + * Validate the secret name so that it doesn't end with 6 characters and a hyphen. + */ +export const validateSecretName = (secretName: string) => { + // If there are more config validation requirements like this it might be good to use + // a dedicated library like zod. + if (/-(.){6}$/.test(secretName)) { + throw new Error('the secret name should not end with a hyphen and 6 characters'); + } +}; + export const getEnvironmentConfig = ( accountName: 'beta' | 'gamma' | 'prod' ): EnvironmentConfig | null => { + let config = null; switch (accountName) { case 'beta': - return { + config = { name: 'beta', accountId: '843407916570', // umccr_development stackProps: { @@ -126,9 +142,10 @@ export const getEnvironmentConfig = ( }, }, }; + break; case 'gamma': - return { + config = { name: 'gamma', accountId: '455634345446', // umccr_staging stackProps: { @@ -155,9 +172,10 @@ export const getEnvironmentConfig = ( orcaBusStatelessConfig: orcaBusStatelessConfig, }, }; + break; case 'prod': - return { + config = { name: 'prod', accountId: '472057503814', // umccr_production stackProps: { @@ -182,8 +200,10 @@ export const getEnvironmentConfig = ( orcaBusStatelessConfig: orcaBusStatelessConfig, }, }; - - default: - return null; + break; } + + validateSecretName(config.stackProps.orcaBusStatefulConfig.databaseProps.masterSecretName); + + return config; }; diff --git a/lib/workload/orcabus-stateless-stack.ts b/lib/workload/orcabus-stateless-stack.ts index b4ff767f0..db61af5b2 100644 --- a/lib/workload/orcabus-stateless-stack.ts +++ b/lib/workload/orcabus-stateless-stack.ts @@ -83,7 +83,7 @@ export class OrcaBusStatelessStack extends cdk.Stack { Arn.format( { resource: dependencies.eventSourceQueueName, - service: 'Queue', + service: 'sqs', }, this )