Skip to content

Commit ebaf4d3

Browse files
committed
Adding profile to config and handling SSM err (prompt infra stack name issue)
1 parent 402d3bd commit ebaf4d3

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/base.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
112112
cfnStackPrefix: this.flags['cfn-stack-prefix'] ?? config.cfnStackPrefix,
113113
ecrAccessRoleArn:
114114
this.flags['ecr-access-role-arn'] ?? config.ecrAccessRoleArn,
115-
profile: this.flags.profile,
115+
profile: this.flags.profile ?? config.profile,
116116
ssmRootPrefix: this.flags['ssm-root-prefix'] ?? config.ssmRootPrefix,
117117
yes: this.flags.yes,
118118
};
@@ -123,7 +123,7 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
123123
* @author Benedikt Arnarsson
124124
* @param {string} msg error message to log before exiting.
125125
*/
126-
public exitWithError = (msg?: string) => {
126+
public exitWithError = (msg?: string): never => {
127127
this.bye(msg, 1);
128128
};
129129

@@ -132,7 +132,7 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
132132
* @author Benedikt Arnarsson
133133
* @param {string} msg message to log before exiting.
134134
*/
135-
public exitWithSuccess = (msg?: string) => {
135+
public exitWithSuccess = (msg?: string): never => {
136136
this.bye(msg);
137137
};
138138

@@ -217,9 +217,8 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
217217
profile = 'default',
218218
keepSecretArns = false,
219219
): Promise<DeployConfigData> {
220-
const { app } = this.flags;
221-
const appPrefix = this.getAppPrefix();
222220
try {
221+
const appPrefix = this.getAppPrefix();
223222
const deployConfig = await DeployConfig.fromSsmParams(
224223
appPrefix,
225224
keepSecretArns,
@@ -228,12 +227,20 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
228227

229228
return deployConfig;
230229
} catch (error) {
230+
const { app } = this.flags;
231231
if (error instanceof AppNotFound) {
232232
this.exitWithError(`${app} app configuration not found!`);
233+
} else {
234+
// Usually, this will be a profile/credential related error
235+
this.exitWithError(
236+
`Unknown error when fetching configuration for ${app}:\n\n${error}`,
237+
);
233238
}
234239
}
235240

236-
return DeployConfig.generate(this.context);
241+
// Need this to satisfy TS
242+
// Should never be reached, due to the try-catch and this.exitWithError
243+
throw new Error('This code is unreachable');
237244
}
238245

239246
/**
@@ -300,7 +307,7 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
300307
* @param {string} [msg='bye!'] message to display before exiting.
301308
* @param {number} [exitCode=0] exit code.
302309
*/
303-
private bye(msg = 'bye!', exitCode = 0) {
310+
private bye(msg = 'bye!', exitCode = 0): never {
304311
this.log(msg);
305312
this.exit(exitCode);
306313
}

src/types/CacclDeployConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const CacclDeployConfig = z.object({
88
cfnStackPrefix: z.string().default('CacclDeploy-'),
99
ecrAccessRoleArn: z.string().optional(),
1010
productionAccounts: z.array(z.string()).default([]),
11+
profile: z.string().default('default'),
1112
ssmRootPrefix: z.string().default('/caccl-deploy'),
1213
});
1314

src/types/CacclDeployContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import CacclDeployConfig from './CacclDeployConfig.js';
55
* @author Benedikt Arnarsson
66
*/
77
type CacclDeployContext = {
8-
profile: string;
98
yes: boolean;
109
} & CacclDeployConfig;
1110

0 commit comments

Comments
 (0)