mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
fix linting issues
This commit is contained in:
parent
3814837e30
commit
42ee9eb05e
@ -28,7 +28,7 @@ class Init {
|
||||
secret: {
|
||||
usage: 'Secret key for the provider',
|
||||
shortcut: 's',
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -40,18 +40,17 @@ class Init {
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
// Sanitize
|
||||
this.options.provider = this.options.provider.toLowerCase();
|
||||
|
||||
// Validate
|
||||
if (['aws'].indexOf(this.options.provider) < 0) {
|
||||
throw new this.serverless.classes.Error(`Only 'aws' is supported at this time.`);
|
||||
throw new this.serverless.classes.Error('Only \'aws\' is supported at this time.');
|
||||
}
|
||||
|
||||
// Init AWS
|
||||
return this.initAws();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Init AWS
|
||||
@ -59,45 +58,47 @@ class Init {
|
||||
*/
|
||||
|
||||
initAws() {
|
||||
|
||||
// Validate
|
||||
if (!this.options.key || !this.options.secret) {
|
||||
throw new this.serverless.classes.Error(`Please include --key and --secret options for AWS.`);
|
||||
throw new this.serverless.classes.Error('Please include --key and --secret options for AWS.');
|
||||
}
|
||||
|
||||
// Inform
|
||||
this.serverless.cli.log('Initializing AWS...');
|
||||
this.serverless.cli.log(`Storing an AWS profile on your local file system in '~/.aws/credentials'...`);
|
||||
this.serverless.cli.log('Storing an AWS profile on your local file system in' +
|
||||
' \'~/.aws/credentials\'...');
|
||||
|
||||
// Locate home directory on user's machine
|
||||
let env = process.env;
|
||||
let home = env.HOME ||
|
||||
const env = process.env;
|
||||
const home = env.HOME ||
|
||||
env.USERPROFILE ||
|
||||
(env.HOMEPATH ? ((env.HOMEDRIVE || 'C:/') + env.HOMEPATH) : null);
|
||||
|
||||
if (!home) {
|
||||
throw new this.serverless.classes.Error(`Can't find home directory on your local file system.`);
|
||||
throw new this.serverless.classes.Error('Can\'t find home directory ' +
|
||||
'on your local file system.');
|
||||
}
|
||||
|
||||
// Check if ~/.aws/credentials exists
|
||||
let configDir = path.join(home, '.aws'),
|
||||
credsPath = path.join(configDir, 'credentials');
|
||||
const configDir = path.join(home, '.aws');
|
||||
const credsPath = path.join(configDir, 'credentials');
|
||||
|
||||
if (this.serverless.utils.fileExistsSync(credsPath)) {
|
||||
|
||||
// Check if credentials files contains anything
|
||||
let credsFile = this.serverless.utils.readFileSync(credsPath);
|
||||
const credsFile = this.serverless.utils.readFileSync(credsPath);
|
||||
|
||||
// If credentials file is malformed, throw error and give guidance
|
||||
if ((credsFile.length && credsFile.indexOf('aws_access_key_id=') < 0) ||
|
||||
(credsFile.length && credsFile.indexOf('aws_secret_access_key=') < 0)) {
|
||||
// TODO: Add guidance in error message when the serverless error parser stops poorly reformatting everything.
|
||||
throw new this.serverless.classes.Error('~/.aws/credentials exists, but it\'s formatted incorrectly. Open it and make sure it\'s correctly formatted.');
|
||||
// TODO: Add guidance in error message when the serverless error parser gets neater
|
||||
throw new this.serverless.classes.Error('~/.aws/credentials exists, but it\'s ' +
|
||||
'formatted incorrectly. Open it and make sure it\'s correctly formatted.');
|
||||
}
|
||||
|
||||
// If credentials file exists and is fine, say so, then exit
|
||||
if (credsFile.length) {
|
||||
this.serverless.cli.log('Exiting... ~/.aws/credentials exists and is formatted correctly. Make sure you\'re using the correct profile in your serverless.yml');
|
||||
this.serverless.cli.log('Exiting... ~/.aws/credentials exists and is formatted ' +
|
||||
'correctly. Make sure you\'re using the correct profile in your serverless.yml');
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
}
|
||||
@ -105,12 +106,13 @@ class Init {
|
||||
// Write credentials file with 'default' profile
|
||||
this.serverless.utils.writeFileSync(
|
||||
credsPath,
|
||||
'[default]' + os.EOL +
|
||||
'aws_access_key_id=' + this.options.key + os.EOL +
|
||||
'aws_secret_access_key=' + this.options.secret + os.EOL);
|
||||
`[default]
|
||||
aws_access_key_id=${this.options.key}
|
||||
aws_secret_access_key=${this.options.secret}` + os.EOL);
|
||||
|
||||
// Inform
|
||||
this.serverless.cli.log('Success! ~/.aws/credentials was created and your access keys were stored under the \'default\' profile.');
|
||||
this.serverless.cli.log('Success! ~/.aws/credentials was created and your access keys ' +
|
||||
'were stored under the \'default\' profile.');
|
||||
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user