Parse a single queue and fetch additional attributes

        :param global_params:           Parameters shared for all regions
        :param region:                  Name of the AWS region
        :param queue_url:               URL of the AWS queue
761587
def parse_queue(self, global_params, region, queue_url):
        
        queue = {'QueueUrl': queue_url}
        attributes = api_clients[region].get_queue_attributes(QueueUrl = queue_url, AttributeNames = ['CreatedTimestamp', 'Policy', 'QueueArn'])['Attributes']
        queue['arn'] = attributes.pop('QueueArn')
        for k in ['CreatedTimestamp']:
            queue[k] = attributes[k] if k in attributes else None
        if 'Policy' in attributes:
            queue['Policy'] = json.loads(attributes['Policy'])
        else:
            queue['Policy'] = {'Statement': []}

        queue['name'] = queue['arn'].split(':')[-1]
        self.queues[queue['name']] = queue
703538
def parse_identitie(self, global_params, region, identity_name):
        
        identity = {'name': identity_name, 'policies': {}}
        policy_names = api_clients[region].list_identity_policies(Identity = identity_name)['PolicyNames']
        if len(policy_names):
            policies = api_clients[region].get_identity_policies(Identity = identity_name, PolicyNames = policy_names)['Policies']
            for policy_name in policies:
                identity['policies'][policy_name] = json.loads(policies[policy_name])
        dkim = api_clients[region].get_identity_dkim_attributes(Identities = [ identity_name ])['DkimAttributes'][identity_name]
        identity['DkimEnabled'] = dkim['DkimEnabled']
        identity['DkimVerificationStatus'] = dkim['DkimVerificationStatus']
        self.identities[self.get_non_aws_id(identity_name)] = identity
677181
def get_service_url(region, endpoint_list, lookup):
    

    for endpoint in endpoint_list:
        region_get = endpoint.get('region', '')
        if region.lower() == region_get.lower():
            return http.parse_url(url=endpoint.get(lookup))
    else:
        raise exceptions.AuthenticationProblem(
            'Region "%s" was not found in your Service Catalog.',
            region
        )
881148
def get_region_from_metadata():
    '''
    
    '''
    global __Location__

    if __Location__ == 'do-not-get-from-metadata':
        log.debug('Previously failed to get AWS region from metadata. Not trying again.')
        return None

    # Cached region
    if __Location__ != '':
        return __Location__

    try:
        # Connections to instance meta-data must fail fast and never be proxied
        result = requests.get(
            "http://169.254.169.254/latest/dynamic/instance-identity/document",
            proxies={'http': ''}, timeout=AWS_METADATA_TIMEOUT,
        )
    except requests.exceptions.RequestException:
        log.warning('Failed to get AWS region from instance metadata.', exc_info=True)
        # Do not try again
        __Location__ = 'do-not-get-from-metadata'
        return None

    try:
        region = result.json()['region']
        __Location__ = region
        return __Location__
    except (ValueError, KeyError):
        log.warning('Failed to decode JSON from instance metadata.')
        return None

    return None
556353
def parse_instance(self, global_params, region, dbi):
        
        vpc_id = dbi['DBSubnetGroup']['VpcId'] if 'DBSubnetGroup' in dbi and 'VpcId' in dbi['DBSubnetGroup'] and dbi['DBSubnetGroup']['VpcId'] else ec2_classic
        instance = {}
        instance['name'] = dbi.pop('DBInstanceIdentifier')
        for key in ['InstanceCreateTime', 'Engine', 'DBInstanceStatus', 'AutoMinorVersionUpgrade',
                    'DBInstanceClass', 'MultiAZ', 'Endpoint', 'BackupRetentionPeriod', 'PubliclyAccessible',
                    'StorageEncrypted', 'VpcSecurityGroups', 'DBSecurityGroups', 'DBParameterGroups',
                    'EnhancedMonitoringResourceArn', 'StorageEncrypted']:
                    # parameter_groups , security_groups, vpc_security_groups
            instance[key] = dbi[key] if key in dbi else None
        # If part of a cluster, multi AZ information is only available via cluster information
        if 'DBClusterIdentifier' in dbi:
            api_client = api_clients[region]
            cluster = api_client.describe_db_clusters(DBClusterIdentifier = dbi['DBClusterIdentifier'])['DBClusters'][0]
            instance['MultiAZ'] = cluster['MultiAZ']
        # Save
        manage_dictionary(self.vpcs, vpc_id, VPCConfig(self.vpc_resource_types))
        self.vpcs[vpc_id].instances[instance['name']] = instance
125293
def _ep_for_region(self, region):
        
        rgn = region.upper()
        try:
            rgn_ep = [ep for ep in list(self.endpoints.values())
                    if ep.region.upper() == rgn][0]
        except IndexError:
            # See if there is an 'ALL' region.
            try:
                rgn_ep = [ep for ep in list(self.endpoints.values())
                        if ep.region.upper() == "ALL"][0]
            except IndexError:
                rgn_ep = None
        return rgn_ep
1131294
def get_region():
    
    log = logging.getLogger(mod_logger + '.get_region')

    # First get the availability zone
    availability_zone = get_availability_zone()

    if availability_zone is None:
        msg = 'Unable to determine the Availability Zone for this system, cannot determine the AWS Region'
        log.error(msg)
        return

    # Strip of the last character to get the region
    region = availability_zone[:-1]
    return region
1067274
def parse_topic(self, params, region, topic):
        
        topic['arn'] = topic.pop('TopicArn')
        topic['name'] = topic['arn'].split(':')[-1]
        (prefix, partition, service, region, account, name) = topic['arn'].split(':')
        api_client = api_clients[region]
        attributes = api_client.get_topic_attributes(TopicArn=topic['arn'])['Attributes']
        for k in ['Owner', 'DisplayName']:
            topic[k] = attributes[k] if k in attributes else None
        for k in ['Policy', 'DeliveryPolicy', 'EffectiveDeliveryPolicy']:
            topic[k] = json.loads(attributes[k]) if k in attributes else None
        topic['name'] = topic['arn'].split(':')[-1]
        manage_dictionary(topic, 'subscriptions', {})
        manage_dictionary(topic, 'subscriptions_count', 0)
        self.topics[topic['name']] = topic
1354216
def __CombineGlobalParams(self, global_params, default_params):
        """"""
        util.Typecheck(global_params, (type(None), self.__client.params_type))
        result = self.__client.params_type()
        global_params = global_params or self.__client.params_type()
        for field in result.all_fields():
            value = global_params.get_assigned_value(field.name)
            if value is None:
                value = default_params.get_assigned_value(field.name)
            if value not in (None, [], ()):
                setattr(result, field.name, value)
        return result
1356681
function takeGlobalQueue() {
            //Push all the globalDefQueue items into the context's defQueue
            if (globalDefQueue.length) {
                //Array splice in the values since the context code has a
                //local var ref to defQueue, so cannot just reassign the one
                //on context.
                apsp.apply(defQueue,
                           [defQueue.length - 1, 0].concat(globalDefQueue));
                globalDefQueue = [];
            }
        }
566540
def system_global_search(input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/system/globalSearch', input_params, always_retry=always_retry, **kwargs)
1226962
def get_region(cls, resource=None):
        
        if resource:
            resource_info = cls.parse_remote(resource)
            if resource_info.region:
                return resource_info.region

        return os.environ.get("AWS_DEFAULT_REGION", cls._DEFAULT_REGION)
373337
def _parse_queues(queues):
        
        if not queues:
            raise ConfigurationException('The queue(s) to use are not defined')

        if isinstance(queues, (list, tuple)):
            for queue_name in queues:
                if not isinstance(queue_name, str):
                    raise ConfigurationException('Queue name "%s" is not a (base)string')

        elif isinstance(queues, basestring):
            queues = str(queues).split(',')

        else:
            raise ConfigurationException('Invalid format for queues names')

        return list(queues)
731865
def get_arn(name, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    if name.startswith('arn:aws:sns:'):
        return name

    account_id = __salt__['boto_iam.get_account_id'](
        region=region, key=key, keyid=keyid, profile=profile
    )
    return 'arn:aws:sns:{0}:{1}:{2}'.format(_get_region(region, profile),
                                            account_id, name)
872011
def get_queue(name, options = {})
      response = action("GetQueueUrl", {"QueueName" => Queue.sanitize_name("#{queue_prefix}#{name}")}.merge(options))
      
      if response.success?
        Queue.new(self, response.doc.xpath("//QueueUrl").text)
      end

    rescue Bisques::AwsActionError => e
      raise unless e.code == "AWS.SimpleQueueService.NonExistentQueue"
    end
1223429
def get_elasticache_replication_groups_by_region(self, region):
        ''' '''

        # ElastiCache boto module doesn't provide a get_all_intances method,
        # that's why we need to call describe directly (it would be called by
        # the shorthand method anyway...)
        try:
            conn = elasticache.connect_to_region(region)
            if conn:
                response = conn.describe_replication_groups()

        except boto.exception.BotoServerError as e:
            error = e.reason

            if e.error_code == 'AuthFailure':
                error = self.get_auth_error_message()
            if not e.reason == "Forbidden":
                error = "Looks like AWS ElastiCache [Replication Groups] is down:\n%s" % e.message
            self.fail_with_error(error, 'getting ElastiCache clusters')

        try:
            # Boto also doesn't provide wrapper classes to ReplicationGroups
            # Because of that wo can't make use of the get_list method in the
            # AWSQueryConnection. Let's do the work manually
            replication_groups = response['DescribeReplicationGroupsResponse']['DescribeReplicationGroupsResult']['ReplicationGroups']

        except KeyError as e:
            error = "ElastiCache [Replication Groups] query to AWS failed (unexpected format)."
            self.fail_with_error(error, 'getting ElastiCache clusters')

        for replication_group in replication_groups:
            self.add_elasticache_replication_group(replication_group, region)
405324
def load_global_config(config_path):
    
    config = configparser.RawConfigParser()
    if os.path.exists(config_path):
        logger.debug("Checking and setting global parameters...")
        config.read(config_path)
    else:
        _initial_run()
        logger.info("Unable to find a global sprinter configuration!")
        logger.info("Creating one now. Please answer some questions" +
                    " about what you would like sprinter to do.")
        logger.info("")
    # checks and sets sections
    if not config.has_section('global'):
        config.add_section('global')

    configure_config(config)
    write_config(config, config_path)

    return config