packages/iam/src/cli/create-role.js
function executeCommand(parameters) {
    const configFilePath = path.join(process.cwd(), plugin.config.rolesPath);
    return mkdirpAsync(configFilePath)
    .then(() => {
      if (parameters.model !== 'none') {
        // Case a preset config has been choosen
        const src = path.join(__dirname, 'templates', 'roles', parameters.model + '.json');
        const dest = path.join(configFilePath, parameters.identifier + '.json');
        return ncpAsync(src, dest);
      } else {
        // Case no preset config has been choosen
        const config = {
          'managed-policies': parameters.policies,
          'inline-policies': [],
          'trust-relationship': {
            Version: '2012-10-17',
            Statement: [{
              Effect: 'Allow',
              Principal: { AWS: '*'},
              Action: 'sts:AssumeRole'
            }]
          }
        };
        // We save the specification in a json file
        return fs.writeFileAsync(configFilePath + path.sep + parameters.identifier + '.json', JSON.stringify(config, null, 2));
      }
    })
    .then(() => {
      const msg = '\n  The IAM role ' + icli.format.info(parameters.identifier)
                + ' has been created in ' + icli.format.info(configFilePath + path.sep + parameters.identifier + '.json') + '\n';
      icli.print(msg);
    });
  }
function executeCommand(parameters) {
    const configFilePath = path.join(process.cwd(), plugin.config.rolesPath);
    return mkdirpAsync(configFilePath)
    .then(() => {
      if (parameters.model !== 'none') {
        // Case a preset config has been choosen
        const src = path.join(__dirname, 'templates', 'roles', parameters.model + '.json');
        const dest = path.join(configFilePath, parameters.identifier + '.json');
        return ncpAsync(src, dest);
      } else {
        // Case no preset config has been choosen
        const config = {
          'managed-policies': parameters.policies,
          'inline-policies': [],
          'trust-relationship': {
            Version: '2012-10-17',
            Statement: [{
              Effect: 'Allow',
              Principal: { AWS: '*'},
              Action: 'sts:AssumeRole'
            }]
          }
        };
        // We save the specification in a json file
        return fs.writeFileAsync(configFilePath + path.sep + parameters.identifier + '.json', JSON.stringify(config, null, 2));
      }
    })
    .then(() => {
      const msg = '\n  The IAM role ' + icli.format.info(parameters.identifier)
                + ' has been created in ' + icli.format.info(configFilePath + path.sep + parameters.identifier + '.json') + '\n';
      icli.print(msg);
    });
  }
function executeCommand ( parameters ) { const configFilePath = path . join ( process . cwd ( ) , plugin . config . rolesPath ) ; return mkdirpAsync ( configFilePath ) . then ( ( ) => { if ( parameters . model !== 'none' ) { // Case a preset config has been choosen const src = path . join ( __dirname , 'templates' , 'roles' , parameters . model + '.json' ) ; const dest = path . join ( configFilePath , parameters . identifier + '.json' ) ; return ncpAsync ( src , dest ) ; } else { // Case no preset config has been choosen const config = { 'managed-policies' : parameters . policies , 'inline-policies' : [ ] , 'trust-relationship' : { Version : '2012-10-17' , Statement : [ { Effect : 'Allow' , Principal : { AWS : '*' } , Action : 'sts:AssumeRole' } ] } } ; // We save the specification in a json file return fs . writeFileAsync ( configFilePath + path . sep + parameters . identifier + '.json' , JSON . stringify ( config , null , 2 ) ) ; } } ) . then ( ( ) => { const msg = '\n  The IAM role ' + icli . format . info ( parameters . identifier ) + ' has been created in ' + icli . format . info ( configFilePath + path . sep + parameters . identifier + '.json' ) + '\n' ; icli . print ( msg ) ; } ) ; }
Create the new role
@param {Object} parameters - the parameters provided in the command and in the prompt
@returns {Promise<null>} - The execution stops here
Create the new role