Skip to content

Commit f564f87

Browse files
author
uid10804
committed
fix(cli): validate apiname to avoid issues in deployment with s3 or cloudformation stack
1 parent abcffd0 commit f564f87

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

packages/cli/src/commands/create-stack.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,23 @@ export class CreateStackCommand extends Command {
7272
cli.action.stop();
7373
this.log();
7474

75-
const stackName = await cli.prompt(
76-
`${chalk.magenta('What is the name of the api ?')}`
77-
);
75+
const s3BucketValidator = async (input: string) => {
76+
const s3regex = new RegExp(
77+
'(?=^.{3,63}$)(?!^(d+.)+d+$)(^(([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9]).)*([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])$)'
78+
);
79+
const test = s3regex.test(input);
80+
if (!test) {
81+
return 'Sorry this is not valid \n=> allowed pattern: ?=^.{3,63}$)(?!^(d+.)+d+$)(^(([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9]).)*([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])$)';
82+
}
83+
return true;
84+
};
85+
const apiAnswer = await inquirer.prompt({
86+
name: 'answer',
87+
message: `${chalk.magenta('What is the name of the api ?')}`,
88+
type: 'input',
89+
validate: s3BucketValidator,
90+
});
91+
const stackName = apiAnswer.answer;
7892
this.log();
7993
const region = await this.getRegion();
8094
let filePath = path.normalize(args.file);

0 commit comments

Comments
 (0)