From 3da3825bed5ecf1e5a761136976e12fe8a3a88c8 Mon Sep 17 00:00:00 2001 From: Daniel Schep Date: Mon, 15 Jul 2019 16:18:46 -0400 Subject: [PATCH 1/2] if user has no profiles, always create them the default profile --- lib/plugins/interactiveCli/setupAws.js | 44 +++++++------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/lib/plugins/interactiveCli/setupAws.js b/lib/plugins/interactiveCli/setupAws.js index 729d4a67c..90d56a259 100644 --- a/lib/plugins/interactiveCli/setupAws.js +++ b/lib/plugins/interactiveCli/setupAws.js @@ -10,24 +10,6 @@ const isValidAwsProfileName = RegExp.prototype.test.bind(/^[a-zA-Z][a-zA-Z0-9-]{ const isValidAwsAccessKeyId = RegExp.prototype.test.bind(/^[A-Z0-9]{10,}$/); const isValidAwsSecretAccessKey = RegExp.prototype.test.bind(/^[a-zA-Z0-9/]{10,}$/); -const awsProfileNameInput = () => - inquirer - .prompt({ - message: 'AWS Profile name:', - type: 'input', - name: 'profileName', - validate: input => { - if (isValidAwsProfileName(input.trim())) return true; - return ( - 'AWS profile name is not valid.\n' + - ' - It should only contain alphanumeric and hyphens.\n' + - ' - It should start with an alphabetic character.\n' + - " - Shouldn't exceed 128 characters" - ); - }, - }) - .then(({ profileName }) => profileName.trim()); - const awsAccessKeyIdInput = () => inquirer .prompt({ @@ -79,21 +61,19 @@ module.exports = { 'https://github.com/serverless/enterprise/blob/master/docs/setup-aws-account.md' )}\nThen enter them here:\n\n` ); - return awsProfileNameInput().then(profileName => - awsAccessKeyIdInput().then(accessKeyId => - awsSecretAccessKeyInput().then(secretAccessKey => - awsCredentials - .saveFileProfiles(new Map([[profileName, { accessKeyId, secretAccessKey }]])) - .then(() => - process.stdout.write( - `\n${chalk.green( - `AWS credentials saved on your machine at ${chalk.bold( - '~/.aws/credentials' - )}. Go there to change them at any time.` - )}\n` - ) + return awsAccessKeyIdInput().then(accessKeyId => + awsSecretAccessKeyInput().then(secretAccessKey => + awsCredentials + .saveFileProfiles(new Map([['default', { accessKeyId, secretAccessKey }]])) + .then(() => + process.stdout.write( + `\n${chalk.green( + `AWS credentials saved on your machine at ${chalk.bold( + '~/.aws/credentials' + )}. Go there to change them at any time.` + )}\n` ) - ) + ) ) ); }); From 7fd05bb2955d207dc7480e854cb0b49b5c08c83d Mon Sep 17 00:00:00 2001 From: Daniel Schep Date: Tue, 16 Jul 2019 08:59:39 -0400 Subject: [PATCH 2/2] remove unused regex --- lib/plugins/interactiveCli/setupAws.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/plugins/interactiveCli/setupAws.js b/lib/plugins/interactiveCli/setupAws.js index 90d56a259..252673744 100644 --- a/lib/plugins/interactiveCli/setupAws.js +++ b/lib/plugins/interactiveCli/setupAws.js @@ -6,7 +6,6 @@ const inquirer = require('./inquirer'); const awsCredentials = require('../aws/utils/credentials'); const { confirm } = require('./utils'); -const isValidAwsProfileName = RegExp.prototype.test.bind(/^[a-zA-Z][a-zA-Z0-9-]{0,100}$/); const isValidAwsAccessKeyId = RegExp.prototype.test.bind(/^[A-Z0-9]{10,}$/); const isValidAwsSecretAccessKey = RegExp.prototype.test.bind(/^[a-zA-Z0-9/]{10,}$/);