Accept a tag, a dict and a list of default keys to return from the dict, and
    check them against the cloud configuration for that tag
429020
def filter_event(tag, data, defaults):
    '''
    
    '''
    ret = {}
    keys = []
    use_defaults = True

    for ktag in __opts__.get('filter_events', {}):
        if tag != ktag:
            continue
        keys = __opts__['filter_events'][ktag]['keys']
        use_defaults = __opts__['filter_events'][ktag].get('use_defaults', True)

    if use_defaults is False:
        defaults = []

    # For PY3, if something like ".keys()" or ".values()" is used on a dictionary,
    # it returns a dict_view and not a list like in PY2. "defaults" should be passed
    # in with the correct data type, but don't stack-trace in case it wasn't.
    if not isinstance(defaults, list):
        defaults = list(defaults)

    defaults = list(set(defaults + keys))

    for key in defaults:
        if key in data:
            ret[key] = data[key]

    return ret
747959
def _load_mapping(self, tag, ssh=False):
        """"""
        mappings = {}
        for mapping in tag:
            if mapping.tag == "map":
                mappings[mapping.attrib["module"]] = mapping.attrib["file"]

        if ssh == False:
            self._vardict["mappings"] = mappings
        else:
            self._vardict["ssh.mappings"] = mappings
839106
def get_tag(self, tag):
        
        headers = {'Accept': 'text/plain'}
        j, _ = self.datacenter.request('GET', self.path + '/tags/' + tag)
        return j
1198797
function dict(schema, defaults, options) {
  if (kindOf(schema) !== 'array' || schema.length !== 2) {
    if (process.env.NODE_ENV !== 'production') {
      throw new Error(
        `Dict structs must be defined as an array with two elements, but you passed: ${schema}`
      )
    } else {
      throw new Error(`Invalid schema: ${schema}`)
    }
  }

  const obj = scalar('object', undefined, options)
  const keys = any(schema[0], undefined, options)
  const values = any(schema[1], undefined, options)
  const name = 'dict'
  const type = `dict<${keys.type},${values.type}>`
  const validate = value => {
    const resolved = resolveDefaults(defaults)
    value = resolved ? { ...resolved, ...value } : value
    const [error] = obj.validate(value)

    if (error) {
      error.type = type
      return [error]
    }

    const ret = {}
    const errors = []

    for (let k in value) {
      const v = value[k]
      const [e, r] = keys.validate(k)

      if (e) {
        const allE = e.errors || [e]
        allE.forEach(singleE => {
          singleE.path = [k].concat(singleE.path)
          singleE.data = value
          errors.push(singleE)
        })
        continue
      }

      k = r
      const [e2, r2] = values.validate(v)

      if (e2) {
        const allE2 = e2.errors || [e2]
        allE2.forEach(singleE => {
          singleE.path = [k].concat(singleE.path)
          singleE.data = value
          errors.push(singleE)
        })
        continue
      }

      ret[k] = r2
    }

    if (errors.length) {
      const first = errors[0]
      first.errors = errors
      return [first]
    }

    return [undefined, ret]
  }

  return new Kind(name, type, validate)
}
567732
def _read_tags(self):
        
        tags = self._config.get('tags', {})
        logging.info('Tags:')
        for tag_name in tags.keys():
            tag = {}
            tag['Key'] = tag_name
            tag['Value'] = tags[tag_name]
            self._tags.append(tag)
            logging.info('{} = {}'.format(tag_name, tags[tag_name]))

        logging.debug(json.dumps(
            self._tags,
            indent=2,
            sort_keys=True
        ))
        return True
1000769
def validate_config_parameters(config_json, allowed_keys, allowed_types):
    """"""
    custom_fields = config_json.get(defs.PARAMETERS, [])
    for field in custom_fields:
        validate_field(field, allowed_keys, allowed_types)
        default = field.get(defs.DEFAULT)
        field_type = field.get(defs.TYPE)
        if default:
            validate_field_matches_type(field[defs.VALUE], default, field_type)
122301
def get(self, key, default=None):
		
		if key in self._nodes: return self._nodes[key]
		else: return default
911049
def _cfg(key, default=None):
    '''
    
    '''
    root_cfg = __salt__.get('config.get', __opts__.get)
    kms_cfg = root_cfg('aws_kms', {})
    return kms_cfg.get(key, default)
834478
def config_(cls, key, default=None):
        
        return cls._app.config.get(key, default)
1366646
def get(self, key, default=None):
        
        if key in self.__cli:
            return self.__cli[key]
        if key in self.__config:
            return self.__config.get(key)
        if key in self.__defaults:
            return self.__defaults.get(key)
        return default
209146
def getConfig(self, key):
        
        if hasattr(self, key):
            return getattr(self, key)
        else:
            return False
594224
def get(config, key, default=None):
        

        if hasattr(config, key):
            return getattr(config, key)
        else:
            return default
1196976
def tag_value(self, p_key, p_default=None):
        
        return self.tag_values(p_key)[0] if p_key in self.fields['tags'] else p_default
995767
def _tags_present(name, tags, vpc_id=None, vpc_name=None, region=None,
                  key=None, keyid=None, profile=None):
    '''
    
    '''
    ret = {'result': True, 'comment': '', 'changes': {}}
    if tags:
        sg = __salt__['boto_secgroup.get_config'](name=name, group_id=None, region=region, key=key,
                                                  keyid=keyid, profile=profile, vpc_id=vpc_id,
                                                  vpc_name=vpc_name)
        if not sg:
            ret['comment'] = '{0} security group configuration could not be retrieved.'.format(name)
            ret['result'] = False
            return ret
        tags_to_add = tags
        tags_to_update = {}
        tags_to_remove = []
        if sg.get('tags'):
            for existing_tag in sg['tags']:
                if existing_tag not in tags:
                    if existing_tag not in tags_to_remove:
                        tags_to_remove.append(existing_tag)
                else:
                    if tags[existing_tag] != sg['tags'][existing_tag]:
                        tags_to_update[existing_tag] = tags[existing_tag]
                    tags_to_add.pop(existing_tag)
        if tags_to_remove:
            if __opts__['test']:
                msg = 'The following tag{0} set to be removed: {1}.'.format(
                        ('s are' if len(tags_to_remove) > 1 else ' is'), ', '.join(tags_to_remove))
                ret['comment'] = ' '.join([ret['comment'], msg])
                ret['result'] = None
            else:
                temp_ret = __salt__['boto_secgroup.delete_tags'](tags_to_remove,
                                                                 name=name,
                                                                 group_id=None,
                                                                 vpc_name=vpc_name,
                                                                 vpc_id=vpc_id,
                                                                 region=region,
                                                                 key=key,
                                                                 keyid=keyid,
                                                                 profile=profile)
                if not temp_ret:
                    ret['result'] = False
                    ret['comment'] = ' '.join([
                        ret['comment'],
                        'Error attempting to delete tags {0}.'.format(tags_to_remove)
                    ])
                    return ret
                if 'old' not in ret['changes']:
                    ret['changes'] = dictupdate.update(ret['changes'], {'old': {'tags': {}}})
                for rem_tag in tags_to_remove:
                    ret['changes']['old']['tags'][rem_tag] = sg['tags'][rem_tag]
        if tags_to_add or tags_to_update:
            if __opts__['test']:
                if tags_to_add:
                    msg = 'The following tag{0} set to be added: {1}.'.format(
                            ('s are' if len(tags_to_add.keys()) > 1 else ' is'),
                            ', '.join(tags_to_add.keys()))
                    ret['comment'] = ' '.join([ret['comment'], msg])
                    ret['result'] = None
                if tags_to_update:
                    msg = 'The following tag {0} set to be updated: {1}.'.format(
                            ('values are' if len(tags_to_update.keys()) > 1 else 'value is'),
                            ', '.join(tags_to_update.keys()))
                    ret['comment'] = ' '.join([ret['comment'], msg])
                    ret['result'] = None
            else:
                all_tag_changes = dictupdate.update(tags_to_add, tags_to_update)
                temp_ret = __salt__['boto_secgroup.set_tags'](all_tag_changes,
                                                              name=name,
                                                              group_id=None,
                                                              vpc_name=vpc_name,
                                                              vpc_id=vpc_id,
                                                              region=region,
                                                              key=key,
                                                              keyid=keyid,
                                                              profile=profile)
                if not temp_ret:
                    ret['result'] = False
                    msg = 'Error attempting to set tags.'
                    ret['comment'] = ' '.join([ret['comment'], msg])
                    return ret
                if 'old' not in ret['changes']:
                    ret['changes'] = dictupdate.update(ret['changes'], {'old': {'tags': {}}})
                if 'new' not in ret['changes']:
                    ret['changes'] = dictupdate.update(ret['changes'], {'new': {'tags': {}}})
                for tag in all_tag_changes:
                    ret['changes']['new']['tags'][tag] = tags[tag]
                    if 'tags' in sg:
                        if sg['tags']:
                            if tag in sg['tags']:
                                ret['changes']['old']['tags'][tag] = sg['tags'][tag]
        if not tags_to_update and not tags_to_remove and not tags_to_add:
            ret['comment'] = ' '.join([ret['comment'], 'Tags are already set.'])
    return ret
308920
def handle(self, key, value):
        '''
        
        '''
        # break down key
        elements = key.split(":")
        dict = {}
        dict['action'] = elements[1]
        dict['domain'] = elements[2]
        dict['appid'] = elements[3]
        value = ujson.loads(value)

        # the master dict to return
        master = {}
        master['uuid'] = value['uuid']
        master['server_time'] = int(self.get_current_time())
        master['action'] = dict['action']
        master['domain'] = dict['domain']
        master['appid'] = dict['appid']

        # log we received the info message
        extras = self.get_log_dict(dict['action'], appid=dict['appid'],
                                   uuid=master['uuid'])

        self.logger.info('Received zookeeper request', extra=extras)

        # get the current zk configuration
        data = None
        try:
            data = self.zoo_client.get(self.path)[0]
        except ZookeeperError:
            e = "Unable to load Zookeeper config"
            self.logger.error(e)
            master['error'] = e
        the_dict = {}
        if data is not None and len(data) > 0:
            the_dict = yaml.safe_load(data)

        # update the configuration
        if "domains" not in the_dict:
            the_dict['domains'] = {}

        if "blacklist" not in the_dict:
            the_dict['blacklist'] = []

        if dict['action'] == 'domain-update':
            the_dict['domains'][dict['domain']] = {
                "window": value['window'],
                "hits": value['hits'],
                "scale": value['scale']
            }
        elif dict['action'] == 'domain-remove':
            if dict['domain'] in the_dict['domains']:
                del the_dict['domains'][dict['domain']]
        elif dict['action'] == 'blacklist-update':
            the_dict['blacklist'].append(dict['domain'])
            the_dict['blacklist'] = list(set(the_dict['blacklist']))
        elif dict['action'] == 'blacklist-remove':
            if dict['domain'] in the_dict['blacklist']:
                the_dict['blacklist'].remove(dict['domain'])
        else:
            self.logger.warn("Unknown command given to Zookeeper Monitor")

        # write the configuration back to zookeeper
        the_string = yaml.dump(the_dict, default_flow_style=False)
        try:
            self.zoo_client.set(self.path, the_string)
        except ZookeeperError:
            e = "Unable to store Zookeeper config"
            self.logger.error(e)
            master['error'] = e

        # ack the data back to kafka
        if self._send_to_kafka(master):
            extras['success'] = True
            self.logger.info('Sent zookeeper update to kafka', extra=extras)
        else:
            extras['success'] = False
            self.logger.error('Failed to send zookeeper update to kafka',
                              extra=extras)
1233716
def has_tag(self, p_key, p_value=""):
        
        tags = self.fields['tags']
        return p_key in tags and (p_value == "" or p_value in tags[p_key])
880515
function tagSetMatch(tagSet, serverTags) {
  const keys = Object.keys(tagSet);
  const serverTagKeys = Object.keys(serverTags);
  for (let i = 0; i < keys.length; ++i) {
    const key = keys[i];
    if (serverTagKeys.indexOf(key) === -1 || serverTags[key] !== tagSet[key]) {
      return false;
    }
  }

  return true;
}