-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from Cox-Automotive/develop
2.17.0
- Loading branch information
Showing
14 changed files
with
963 additions
and
909 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
process.title = 'ALKS'; | ||
|
||
var program = require('commander'), | ||
_ = require('underscore'), | ||
clc = require('cli-color'), | ||
alks = require('alks-node'), | ||
Iam = require('../lib/iam'), | ||
utils = require('../lib/utils'), | ||
Developer = require('../lib/developer'), | ||
config = require('../package.json'); | ||
|
||
var logger = 'iam-createtrustrole', | ||
roleNameDesc = 'alphanumeric including @+=._-', | ||
trustArnDesc = 'arn:aws|aws-us-gov:iam::d{12}:role/TestRole'; | ||
|
||
program | ||
.version(config.version) | ||
.description('creates a new IAM Trust role') | ||
.option('-n, --rolename [rolename]', 'the name of the role, ' + roleNameDesc) | ||
.option('-t, --roletype [roletype]', 'the role type: Cross Account or Inner Account') | ||
.option('-T, --trustarn [trustarn]', 'trust arn, ' + trustArnDesc) | ||
.option('-a, --account [alksAccount]', 'alks account to use') | ||
.option('-r, --role [alksRole]', 'alks role to use') | ||
.option('-F, --favorites', 'filters favorite accounts') | ||
.option('-v, --verbose', 'be verbose') | ||
.parse(process.argv); | ||
|
||
var ROLE_NAME_REGEX = /^[a-zA-Z0-9!@+=._-]+$/g, | ||
TRUST_ARN_REGEX = /arn:(aws|aws-us-gov):iam::\d{12}:role\/?[a-zA-Z_0-9+=,.@-_/]+/g, | ||
roleName = program.rolename, | ||
roleType = program.roletype, | ||
trustArn = program.trustarn, | ||
alksAccount = program.account, | ||
alksRole = program.role, | ||
filterFaves = program.favorites || false; | ||
|
||
utils.log(program, logger, 'validating role name: ' + roleName); | ||
if(_.isEmpty(roleName) || !ROLE_NAME_REGEX.test(roleName)){ | ||
utils.errorAndExit('The role name provided contains illegal characters. It must be ' + roleNameDesc); | ||
} | ||
|
||
utils.log(program, logger, 'validating role type: ' + roleType); | ||
if(_.isEmpty(roleType) || (roleType !== "Cross Account" && roleType !== "Inner Account")){ | ||
utils.errorAndExit('The role type is required'); | ||
} | ||
|
||
utils.log(program, logger, 'validating trust arn: ' + trustArn); | ||
if(_.isEmpty(trustArn) || !TRUST_ARN_REGEX.test(trustArn)){ | ||
utils.errorAndExit('The trust arn provided contains illegal characters. It must be ' + trustArnDesc); | ||
} | ||
|
||
if(!_.isUndefined(alksAccount) && _.isUndefined(alksRole)){ | ||
utils.log(program, logger, 'trying to extract role from account'); | ||
alksRole = utils.tryToExtractRole(alksAccount); | ||
} | ||
|
||
Iam.getIAMKey(program, logger, alksAccount, alksRole, false, filterFaves, function(err, key, developer){ | ||
if(err){ | ||
return utils.errorAndExit(err); | ||
} | ||
|
||
// create the role | ||
var data = _.extend({}, developer, key); | ||
utils.log(program, logger, 'calling api to create trust role: ' + roleName); | ||
delete data.userid | ||
alks.createIamTrustRole(data, null, roleName, roleType, trustArn, { debug: program.verbose, ua: utils.getUA() }, function(err, data){ | ||
if(err){ | ||
return utils.errorAndExit(err); | ||
} | ||
|
||
console.error(clc.white(['The role: ', data.roleName, ' was created with the ARN: '].join('')) + clc.white.underline(data.roleArn)); | ||
if(data.instanceProfileArn){ | ||
console.error(clc.white(['An instance profile was also created with the ARN: '].join('')) + clc.white.underline(data.instanceProfileArn)); | ||
} | ||
utils.log(program, logger, 'checking for updates'); | ||
utils.checkForUpdate(); | ||
Developer.trackActivity(logger); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.