2.5 Ensure AWS Config is enabled in all regions (Scored)
505749
def audit_2_5(self):
        """"""
        import boto3
        for region in boto3.Session().get_available_regions("config"):
            aws_config = boto3.session.Session(region_name=region).client("config")
            res = aws_config.describe_configuration_recorder_status()
            self.assertGreater(len(res["ConfigurationRecordersStatus"]), 0)
266860
def apply_region_configs(env_config):
    
    new_config = env_config.copy()
    for region in env_config.get('regions', REGIONS):
        if isinstance(env_config.get('regions'), dict):
            region_specific_config = env_config['regions'][region]
            new_config[region] = dict(DeepChainMap(region_specific_config, env_config))
        else:
            new_config[region] = env_config.copy()
    LOG.debug('Region Specific Config:\n%s', new_config)
    return new_config
679778
async function initializeConfig() {
    process.stdout.write(chalk.cyan.bold('\nThis util will walk you through creating a .luisrc file\n\nPress ^C at any time to quit.\n\n'));
    //const validRegions = 'westus westus2 eastus eastus2 westcentralus southcentralus westeurope northeurope southeastasia eastasia australiaeast brazilsouth'.split(' ');
    const validRegions = 'westus westeurope australiaeast'.split(' ');
    const questions = [
        'What is your LUIS Authoring key (from luis.ai portal User Settings page)? ',
        `What is your region? [${validRegions.join(', ')}] `,
        'What is your LUIS App ID? [Default: skip] ',
        'What is your LUIS Version ID? [Default: 0.1] ',
    ];

    const prompt = readline.createInterface({
        input: process.stdin,
        output: process.stdout,
    });

    const answers = [];
    for (let i = 0; i < questions.length; i++) {
        const question = questions[i];
        const answer = await new Promise((resolve) => {

            function doPrompt(promptMessage) {
                prompt.question(promptMessage, response => {
                    if (i === 1 && (!response || !validRegions.includes(response))) {
                        doPrompt(chalk.red.bold(`${response} is not a valid region`) + '\n' + question);
                    } else {
                        resolve(response);
                    }
                });
            }

            doPrompt(question);
        });
        if (i == 2 && answer.trim().length == 0)
            break;
        answers.push(answer.trim());
    }

    const [authoringKey, region, appId, versionId] = answers;
    const config = Object.assign({}, {
        appId,
        authoringKey,
        versionId,
        region: region,
    });
    try {
        await new Promise((resolve, reject) => {
            const confirmation = `\n\nDoes this look ok?\n${JSON.stringify(config, null, 2)}\n[Yes]/No: `;
            prompt.question(confirmation, response => {
                /^(y|yes)$/.test((response || 'yes').toLowerCase()) ? resolve(response) : reject();
            });
        });
    } catch (e) {
        return false;
    }
    await fs.writeJson(path.join(process.cwd(), '.luisrc'), config, { spaces: 2 });
    return true;
}
655530
function onSyncComplete(projectInfo, awsDetails, backendProject, enabledFeatures, syncToDevFlag, callback){
    updateAWSExportFile(projectInfo, awsDetails, ()=>{
        console.log('contents in #current-backend-info/ is synchronized with the latest in the aws cloud')
        updateBackendSyncTime(projectInfo)
        if(!syncToDevFlag){
            syncToDevFlag = 0
        }
        if(syncToDevFlag > 0){
            syncAllToDev(projectInfo, backendProject, enabledFeatures)
            if(callback){
                callback()
            }
        }else if(syncToDevFlag == 0){
            let message = 'sync corresponding contents in backend/ with #current-backend-info/'
            inquirer.prompt([
            {
                type: 'confirm',
                name: 'syncToDevBackend',
                message: message,
                default: false
            }
            ]).then(function (answers) {
                if(answers.syncToDevBackend){
                    syncAllToDev(projectInfo, backendProject, enabledFeatures, true)
                }
                if(callback){
                    callback()
                }
            })
        }else{
            if(callback){
                callback()
            }
        }
    })
}
1049898
def assert_consistent_regions(from_spec, from_command_line, builder_exception):
    
    if from_spec is None or from_command_line is None:
        return
    if set(from_spec) != set(from_command_line):
        raise builder_exception("--region and the 'regionalOptions' key in the JSON file do not agree")
226600
def connect_to_region(region_name):
    
    logging.debug("Connecting to AWS region '%s'" % region_name)
    con = boto.vpc.connect_to_region(region_name)
    if not con:
        raise VpcRouteSetError("Could not establish connection to "
                               "region '%s'." % region_name)
    return con
752786
def preprocessing(aws_config, ip_ranges = [], ip_ranges_name_key = None):
    

    map_all_sgs(aws_config)
    map_all_subnets(aws_config)
    set_emr_vpc_ids(aws_config)
    #parse_elb_policies(aws_config)

    # Various data processing calls
    add_security_group_name_to_ec2_grants(aws_config['services']['ec2'], aws_config['aws_account_id'])
    process_cloudtrail_trails(aws_config['services']['cloudtrail'])
    add_cidr_display_name(aws_config, ip_ranges, ip_ranges_name_key)
    merge_route53_and_route53domains(aws_config)
    match_instances_and_roles(aws_config)
    match_iam_policies_and_buckets(aws_config)

    # Preprocessing dictated by metadata
    process_metadata_callbacks(aws_config)
28691
def _ensure_create_ha_compliant(self, router, router_type):
        """"""
        details = router.pop(ha.DETAILS, {})
        if details == ATTR_NOT_SPECIFIED:
            details = {}
        res = {ha.ENABLED: router.pop(ha.ENABLED, ATTR_NOT_SPECIFIED),
               ha.DETAILS: details}

        if not is_attr_set(res[ha.ENABLED]):
            res[ha.ENABLED] = router_type['ha_enabled_by_default']
        if res[ha.ENABLED] and not cfg.CONF.ha.ha_support_enabled:
            raise ha.HADisabled()
        if not res[ha.ENABLED]:
            return res
        if not is_attr_set(details.get(ha.TYPE, ATTR_NOT_SPECIFIED)):
            details[ha.TYPE] = cfg.CONF.ha.default_ha_mechanism
        if details[ha.TYPE] in cfg.CONF.ha.disabled_ha_mechanisms:
            raise ha.HADisabledHAType(ha_type=details[ha.TYPE])
        if not is_attr_set(details.get(ha.REDUNDANCY_LEVEL,
                                       ATTR_NOT_SPECIFIED)):
            details[ha.REDUNDANCY_LEVEL] = (
                cfg.CONF.ha.default_ha_redundancy_level)
        if not is_attr_set(details.get(ha.PROBE_CONNECTIVITY,
                                       ATTR_NOT_SPECIFIED)):
            details[ha.PROBE_CONNECTIVITY] = (
                cfg.CONF.ha.connectivity_probing_enabled_by_default)
        if not is_attr_set(details.get(ha.PROBE_TARGET, ATTR_NOT_SPECIFIED)):
            details[ha.PROBE_TARGET] = cfg.CONF.ha.default_probe_target
        if not is_attr_set(details.get(ha.PROBE_INTERVAL, ATTR_NOT_SPECIFIED)):
            details[ha.PROBE_INTERVAL] = cfg.CONF.ha.default_ping_interval
        return res
1041634
def get_all_launch_configurations(region=None, key=None, keyid=None,
                                  profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    retries = 30
    while True:
        try:
            return conn.get_all_launch_configurations()
        except boto.exception.BotoServerError as e:
            if retries and e.code == 'Throttling':
                log.debug('Throttled by AWS API, retrying in 5 seconds...')
                time.sleep(5)
                retries -= 1
                continue
            log.error(e)
            return []
28758
def check_config(db, level):
    """"""
    if level == 'global':
        configuration = config.read(config.HOMEDIR, '.passpierc')
    elif level == 'local':
        configuration = config.read(os.path.join(db.path))
    elif level == 'current':
        configuration = db.config

    if configuration:
        click.echo(yaml.safe_dump(configuration, default_flow_style=False))
350461
function hasCustomEndpoint(client) {
  //if set endpoint is set for specific client, enable endpoint discovery will raise an error.
  if (client._originalConfig && client._originalConfig.endpoint && client._originalConfig.endpointDiscoveryEnabled === true) {
    throw util.error(new Error(), {
      code: 'ConfigurationException',
      message: 'Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.'
    });
  };
  var svcConfig = AWS.config[client.serviceIdentifier] || {};
  return Boolean(AWS.config.endpoint || svcConfig.endpoint || (client._originalConfig && client._originalConfig.endpoint));
}
146724
private static ClientConfig createCOSClientConfig(String regionName,
      UnderFileSystemConfiguration conf) {
    ClientConfig config = new ClientConfig(new Region(regionName));
    config.setConnectionTimeout((int) conf.getMs(PropertyKey.COS_CONNECTION_TIMEOUT));
    config.setSocketTimeout((int) conf.getMs(PropertyKey.COS_SOCKET_TIMEOUT));
    config.setMaxConnectionsCount(conf.getInt(PropertyKey.COS_CONNECTION_MAX));
    return config;
  }
1065225
function ConnectionConfig(options, validateCredentials, qaMode, clientInfo)
{
  // if no value is specified for the validate credentials flag, default to true
  if (!Util.exists(validateCredentials))
  {
    validateCredentials = true;
  }

  // check for missing options
  Errors.checkArgumentExists(Util.exists(options),
      ErrorCodes.ERR_CONN_CREATE_MISSING_OPTIONS);

  // check for invalid options
  Errors.checkArgumentValid(Util.isObject(options),
      ErrorCodes.ERR_CONN_CREATE_INVALID_OPTIONS);

  // only validate credentials if necessary
  if (validateCredentials)
  {
    // check for missing username
    Errors.checkArgumentExists(Util.exists(options.username),
        ErrorCodes.ERR_CONN_CREATE_MISSING_USERNAME);

    // check for invalid username
    Errors.checkArgumentValid(Util.isString(options.username),
        ErrorCodes.ERR_CONN_CREATE_INVALID_USERNAME);

    // check for missing password
    Errors.checkArgumentExists(Util.exists(options.password),
        ErrorCodes.ERR_CONN_CREATE_MISSING_PASSWORD);

    // check for invalid password
    Errors.checkArgumentValid(Util.isString(options.password),
        ErrorCodes.ERR_CONN_CREATE_INVALID_PASSWORD);

    // check for missing account
    Errors.checkArgumentExists(Util.exists(options.account),
        ErrorCodes.ERR_CONN_CREATE_MISSING_ACCOUNT);

    // check for invalid account
    Errors.checkArgumentValid(Util.isString(options.account),
        ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT);

    // if region, cloud or any subdomain is included in account, split them
    // into account and region parameters.
    var dotPos = options.account.indexOf('.');
    if (dotPos > 0 && dotPos < options.account.length - 1)
    {
      options.region = options.account.substring(dotPos + 1);
      options.account = options.account.substring(0, dotPos);
    }

    // if no access url is specified, derive it from the account name and the
    // region if one is specified
    if (!Util.exists(options.accessUrl))
    {
      // extract the region if one is specified
      var region = '';
      if (Util.exists(options.region))
      {
        Errors.checkArgumentValid(Util.isString(options.region),
            ErrorCodes.ERR_CONN_CREATE_INVALID_REGION);

        if (options.region === 'us-west-2')
        {
          // if region is us-west-2, no subdomain is required.
          options.region = ''
        }
        else
        {
          // the region will look something like 'eu-central-1'; add a dot to the
          // beginning so we can insert it after the account name when building
          // the access url
          region = '.' + options.region;
        }
      }

      options.accessUrl = Util.format(
          'https://%s%s.snowflakecomputing.com', options.account, region);
    }
  }

  // check for missing accessUrl
  Errors.checkArgumentExists(Util.exists(options.accessUrl),
      ErrorCodes.ERR_CONN_CREATE_MISSING_ACCESS_URL);

  // check for invalid accessUrl
  Errors.checkArgumentValid(Util.isString(options.accessUrl),
      ErrorCodes.ERR_CONN_CREATE_INVALID_ACCESS_URL);

  var proxyHost = options.proxyHost;
  var proxyPort = options.proxyPort;

  // if we're running in node and some proxy information is specified
  var proxy;
  if (Util.isNode() && (Util.exists(proxyHost) || Util.exists(proxyPort)))
  {
    // check for missing proxyHost
    Errors.checkArgumentExists(Util.exists(proxyHost),
        ErrorCodes.ERR_CONN_CREATE_MISSING_PROXY_HOST);

    // check for invalid proxyHost
    Errors.checkArgumentValid(Util.isString(proxyHost),
        ErrorCodes.ERR_CONN_CREATE_INVALID_PROXY_HOST);

    // check for missing proxyPort
    Errors.checkArgumentExists(Util.exists(proxyPort),
        ErrorCodes.ERR_CONN_CREATE_MISSING_PROXY_PORT);

    // check for invalid proxyPort
    Errors.checkArgumentValid(Util.isNumber(proxyPort),
        ErrorCodes.ERR_CONN_CREATE_INVALID_PROXY_PORT);

    proxy =
    {
      host : proxyHost,
      port : proxyPort
    };
  }

  var warehouse = options.warehouse;
  var database  = options.database;
  var schema    = options.schema;
  var role      = options.role;

  // check for invalid warehouse
  if (Util.exists(warehouse))
  {
    Errors.checkArgumentValid(Util.isString(warehouse),
        ErrorCodes.ERR_CONN_CREATE_INVALID_WAREHOUSE);
  }

  // check for invalid database
  if (Util.exists(database))
  {
    Errors.checkArgumentValid(Util.isString(database),
        ErrorCodes.ERR_CONN_CREATE_INVALID_DATABASE);
  }

  // check for invalid schema
  if (Util.exists(schema))
  {
    Errors.checkArgumentValid(Util.isString(schema),
        ErrorCodes.ERR_CONN_CREATE_INVALID_SCHEMA);
  }

  // check for invalid role
  if (Util.exists(role))
  {
    Errors.checkArgumentValid(Util.isString(role),
        ErrorCodes.ERR_CONN_CREATE_INVALID_ROLE);
  }

  // check for invalid streamResult
  var streamResult = options.streamResult;
  if (Util.exists(streamResult))
  {
    Errors.checkArgumentValid(Util.isBoolean(streamResult),
        ErrorCodes.ERR_CONN_CREATE_INVALID_STREAM_RESULT);
  }

  // check for invalid fetchAsString
  var fetchAsString = options.fetchAsString;
  if (Util.exists(fetchAsString))
  {
    // check that the value is an array
    Errors.checkArgumentValid(Util.isArray(fetchAsString),
        ErrorCodes.ERR_CONN_CREATE_INVALID_FETCH_AS_STRING);

    // check that all the array elements are valid
    var invalidValueIndex = NativeTypes.findInvalidValue(fetchAsString);
    Errors.checkArgumentValid(invalidValueIndex === -1,
        ErrorCodes.ERR_CONN_CREATE_INVALID_FETCH_AS_STRING_VALUES,
        JSON.stringify(fetchAsString[invalidValueIndex]));
  }

  // check for invalid clientSessionKeepAlive
  var clientSessionKeepAlive = options.clientSessionKeepAlive;
  if (Util.exists(clientSessionKeepAlive))
  {
    Errors.checkArgumentValid(Util.isBoolean(clientSessionKeepAlive),
        ErrorCodes.ERR_CONN_CREATE_INVALID_KEEP_ALIVE);
  }

  // check for invalid clientSessionKeepAliveHeartbeatFrequency
  var clientSessionKeepAliveHeartbeatFrequency = options.clientSessionKeepAliveHeartbeatFrequency;
  if (Util.exists(clientSessionKeepAliveHeartbeatFrequency))
  {
    Errors.checkArgumentValid(Util.isNumber(clientSessionKeepAliveHeartbeatFrequency),
        ErrorCodes.ERR_CONN_CREATE_INVALID_KEEP_ALIVE_HEARTBEAT_FREQ);
    clientSessionKeepAliveHeartbeatFrequency = Util.validateClientSessionKeepAliveHeartbeatFrequency(clientSessionKeepAliveHeartbeatFrequency, 14400);
  }
  
  // remember if we're in qa mode
  this._qaMode = qaMode;

  // if a client-info argument is specified, validate it
  var clientVersion;
  var clientEnvironment;
  if (Util.exists(clientInfo))
  {
    Errors.assertInternal(Util.isObject(clientInfo));
    Errors.assertInternal(Util.isString(clientInfo.version));
    Errors.assertInternal(Util.isObject(clientInfo.environment));

    clientVersion     = clientInfo.version;
    clientEnvironment = clientInfo.environment;
  }

  /**
   * Returns an object that contains information about the proxy hostname, port,
   * etc. for when http requests are made.
   *
   * @returns {Object}
   */
  this.getProxy = function()
  {
    return proxy;
  };

  /**
   * Returns the warehouse to automatically use once a connection has been
   * established.
   *
   * @returns {String}
   */
  this.getWarehouse = function()
  {
    return warehouse;
  };

  /**
   * Returns the database to automatically use once a connection has been
   * established.
   *
   * @returns {String}
   */
  this.getDatabase = function()
  {
    return database;
  };

  /**
   * Returns the schema to automatically use once a connection has been
   * established.
   *
   * @returns {String}
   */
  this.getSchema = function()
  {
    return schema;
  };

  /**
   * Returns the role to automatically use once a connection has been
   * established.
   *
   * @returns {String}
   */
  this.getRole = function()
  {
    return role;
  };

  /**
   * Returns the streamResult flag.
   *
   * @returns {boolean}
   */
  this.getStreamResult = function()
  {
    return streamResult;
  };

  /**
   * Returns the fetchAsString array.
   *
   * @returns {String[]}
   */
  this.getFetchAsString = function()
  {
    return fetchAsString;
  };

  /**
   * Returns the client type.
   *
   * @returns {String}
   */
  this.getClientType = function()
  {
    return 'JavaScript';
  };

  /**
   * Returns the client version.
   *
   * @returns {String}
   */
  this.getClientVersion = function()
  {
    return clientVersion;
  };

  /**
   * Returns a JSON object containing version information for all the various
   * components of the runtime, e.g. node, v8, openssl, etc.
   *
   * @returns {Object}
   */
  this.getClientEnvironment = function()
  {
    return clientEnvironment;
  };

  /**
   * Returns the client session keep alive setting.
   *
   * @returns {String}
   */
  this.getClientSessionKeepAlive = function()
  {
    return clientSessionKeepAlive;
  };

  /**
   * Returns the client session keep alive heartbeat frequency setting.
   *
   * @returns {String}
   */
  this.getClientSessionKeepAliveHeartbeatFrequency = function()
  {
    return clientSessionKeepAliveHeartbeatFrequency;
  };

  // save config options
  this.username  = options.username;
  this.password  = options.password;
  this.accessUrl = options.accessUrl;
  this.account   = options.account;

  // create the parameters array
  var parameters = createParameters();

  // create a map in which the keys are the parameter names and the values are
  // the corresponding parameters
  var mapParameters = {};
  var index, length, parameter;
  for (index = 0, length = parameters.length; index < length; index++)
  {
    parameter = parameters[index];
    mapParameters[parameter.name] = parameter;

    // initialize the value to the default
    parameter.value = parameter.defaultValue;
  }

  // for each property in the options object that matches a known parameter name
  var propertyName, propertyValue;
  for (propertyName in options)
  {
    if (options.hasOwnProperty(propertyName) &&
        mapParameters.hasOwnProperty(propertyName))
    {
      // if the parameter matching the property is external and the specified
      // value is valid for the parameter, update the parameter value
      propertyValue = options[propertyName];
      parameter = mapParameters[propertyName];
      if (parameter.external && parameter.validate(propertyValue))
      {
        parameter.value = propertyValue;
      }
    }
  }

  // save the parameters map
  this._mapParameters = mapParameters;
}
363642
def _set_bucket_dns(self):
        """"""
        # Different regions have different s3 endpoint formats
        dotformat_regions = ["eu-west-2", "eu-central-1", "ap-northeast-2", "ap-south-1", "ca-central-1", "us-east-2"]
        if self.region in dotformat_regions:
            s3_endpoint = "{0}.s3-website.{1}.amazonaws.com".format(self.bucket, self.region)
        else:
            s3_endpoint = "{0}.s3-website-{1}.amazonaws.com".format(self.bucket, self.region)

        zone_ids = get_dns_zone_ids(env=self.env, facing="public")
        dns_kwargs = {
            'dns_name': self.bucket,
            'dns_name_aws': s3_endpoint,
            'dns_ttl': self.properties['dns']['ttl']
        }

        for zone_id in zone_ids:
            LOG.debug('zone_id: %s', zone_id)
            update_dns_zone_record(self.env, zone_id, **dns_kwargs)
        LOG.info("Created DNS %s for Bucket", self.bucket)
1079294
def _load_region(self, acct_id, region_name, path):
        """"""
        lim_path = os.path.join(path, 'limit_overrides.json')
        thresh_path = os.path.join(path, 'threshold_overrides.json')
        res = {'limit_overrides': {}, 'threshold_overrides': {}}
        if os.path.exists(lim_path):
            with open(lim_path, 'r') as fh:
                res['limit_overrides'] = json.loads(fh.read())
        if os.path.exists(thresh_path):
            with open(thresh_path, 'r') as fh:
                res['threshold_overrides'] = json.loads(fh.read())
        self._config[acct_id]['regions'][region_name] = res
985158
def setup_dns(endpoint):
    """"""
    print("Setting up DNS...")

    yass = Yass(CWD)
    target = endpoint.lower()

    sitename = yass.sitename
    if not sitename:
        raise ValueError("Missing site name")

    endpoint = yass.config.get("hosting.%s" % target)
    if not endpoint:
        raise ValueError(
            "%s endpoint is missing in the hosting config" % target.upper())

    if target == "s3":
        p = publisher.S3Website(sitename=sitename,
                                aws_access_key_id=endpoint.get("aws_access_key_id"),
                                aws_secret_access_key=endpoint.get("aws_secret_access_key"),
                                region=endpoint.get("aws_region"))

        print("Setting AWS Route53 for: %s ..." % p.sitename)
        p.setup_dns()
        print("")
        print("Yass! Route53 setup successfully!")
        print("You can now visit the site at :")
        print(p.sitename_endpoint)
    footer()
976363
def validate_regions(self):
        
        for region in self.aws_regions:
            if region not in aws_regions:
                print "Error: Specified region: {} is not a valid aws_region".format(region)
                print "Valid regions are: {}".format(aws_regions)