mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
If user has no profiles, always create them the default profile (#6378)
If user has no profiles, always create them the default profile
This commit is contained in:
commit
2ea13d5fec
@ -6,28 +6,9 @@ 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,}$/);
|
||||
|
||||
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({
|
||||
@ -84,21 +65,19 @@ https://serverless.com/framework/docs/providers/aws/guide/credentials#creating-a
|
||||
'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`
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user