Skip to content

Commit

Permalink
refactor(CLI): Modern logs for config credentials command
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 1, 2021
1 parent 16133f0 commit 678db89
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/plugins/aws/configCredentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const os = require('os');
const credentials = require('./utils/credentials');
const ServerlessError = require('../../serverless-error');
const cliCommandsSchema = require('../../cli/commands-schema');
const { legacy, log } = require('@serverless/utils/log');

class AwsConfigCredentials {
constructor(serverless, options) {
Expand Down Expand Up @@ -51,17 +52,18 @@ class AwsConfigCredentials {
);
}

this.serverless.cli.log('Setting up AWS...');
legacy.log('Setting up AWS...');

const profiles = await credentials.resolveFileProfiles();
if (profiles.has(this.options.profile)) {
// Only update the profile if the overwrite flag was set
if (!this.options.overwrite) {
const message = [
`Failed! ~/.aws/credentials already has a "${this.options.profile}" profile.`,
' Use the overwrite flag ("-o" or "--overwrite") to force the update',
].join('');
this.serverless.cli.log(message);
legacy.log(
`Failed! ~/.aws/credentials already has a "${this.options.profile}" profile. Use the overwrite flag ("-o" or "--overwrite") to force the update`
);
log.notice.skip(
`Profile "${this.options.profile}" is already configured in ~/.aws/credentials. Use the overwrite flag ("-o" or "--overwrite") to force the update.`
);
return null;
}
}
Expand All @@ -70,7 +72,9 @@ class AwsConfigCredentials {
secretAccessKey: this.options.secret,
});

return credentials.saveFileProfiles(profiles);
const result = await credentials.saveFileProfiles(profiles);
log.notice.success(`Profile "${this.options.profile}" has been configured`);
return result;
}
}

Expand Down

0 comments on commit 678db89

Please sign in to comment.