'Extract config templates for an identifier from a K/V store and returns it as a dict object.'

def _get_config_templates(self, identifier, **platform_kwargs):

    config_backend = self.agentConfig.get('sd_config_backend')
    templates = []
    if (config_backend is None):
        auto_conf = True
    else:
        auto_conf = False
    raw_tpls = self.config_store.get_check_tpls(identifier, auto_conf=auto_conf, **platform_kwargs)
    for tpl in raw_tpls:
        try:
            (source, (check_name, init_config_tpl, instance_tpl)) = tpl
        except (TypeError, IndexError, ValueError):
            log.debug(('No    template    was    found    for    identifier    %s,    leaving    it    alone:    %s' % (identifier, tpl)))
            return None
        try:
            variables = (self.PLACEHOLDER_REGEX.findall(str(init_config_tpl)) + self.PLACEHOLDER_REGEX.findall(str(instance_tpl)))
            variables = map((lambda x: x.strip('%')), variables)
            if (not isinstance(init_config_tpl, dict)):
                init_config_tpl = json.loads((init_config_tpl or '{}'))
            if ((not isinstance(instance_tpl, dict)) and (not isinstance(instance_tpl, list))):
                instance_tpl = json.loads((instance_tpl or '{}'))
        except json.JSONDecodeError:
            log.exception('Failed    to    decode    the    JSON    template    fetched    for    check    {0}.    Its    configuration    by    service    discovery    failed    for    ident        {1}.'.format(check_name, identifier))
            return None
        templates.append((source, (check_name, init_config_tpl, instance_tpl, variables)))
    return templates
