Return the specified public key or keys based on a glob
180748
def key_str(self, match):
        '''
        
        '''
        ret = {}
        for status, keys in six.iteritems(self.name_match(match)):
            ret[status] = {}
            for key in salt.utils.data.sorted_ignorecase(keys):
                path = os.path.join(self.opts['pki_dir'], status, key)
                with salt.utils.files.fopen(path, 'r') as fp_:
                    ret[status][key] = \
                        salt.utils.stringutils.to_unicode(fp_.read())
        return ret
887093
def get_keys(self):
        '''
        
        '''
        # Make sure all key parent directories are accessible
        user = self.opts.get('user', 'root')
        salt.utils.verify.check_path_traversal(self.opts['pki_dir'], user)

        if not os.path.exists(self.rsa_path):
            log.info('Generating keys: %s', self.opts['pki_dir'])
            gen_keys(self.opts['pki_dir'],
                     'minion',
                     self.opts['keysize'],
                     self.opts.get('user'))
        key = get_rsa_key(self.rsa_path, None)
        log.debug('Loaded minion key: %s', self.rsa_path)
        return key
633411
def _get_key(key, scopes):
    """"""

    # If the key is a dot
    if key == '.':
        # Then just return the current scope
        return scopes[0]

    # Loop through the scopes
    for scope in scopes:
        try:
            # For every dot seperated key
            for child in key.split('.'):
                # Move into the scope
                try:
                    # Try subscripting (Normal dictionaries)
                    scope = scope[child]
                except (TypeError, AttributeError):
                    try:
                        # Try the dictionary (Complex types)
                        scope = scope.__dict__[child]
                    except (TypeError, AttributeError):
                        # Try as a list
                        scope = scope[int(child)]

            # Return an empty string if falsy, with two exceptions
            # 0 should return 0, and False should return False
            # While using is for this check is undefined it works and is fast
            if scope is 0:  # noqa: F632
                return 0
            if scope is False:
                return False

            try:
                # This allows for custom falsy data types
                # https://github.com/noahmorrison/chevron/issues/35
                if scope._CHEVRON_return_scope_when_falsy:
                    return scope
            except AttributeError:
                return scope or ''
        except (AttributeError, KeyError, IndexError, ValueError):
            # We couldn't find the key in the current scope
            # We'll try again on the next pass
            pass

    # We couldn't find the key in any of the scopes
    return ''
169180
def export_public_key(user_id, env=None, sp=subprocess):
    """"""
    args = gpg_command(['--export', user_id])
    result = check_output(args=args, env=env, sp=sp)
    if not result:
        log.error('could not find public key %r in local GPG keyring', user_id)
        raise KeyError(user_id)
    return result
406002
function runGlob(args, opts, cb) {
  var dotIdx = args.indexOf('.');
  if (dotIdx !== -1) {
    args.splice(dotIdx, 1);
  }
  glob(args, opts, function(err, globbed) {
    if (Array.isArray(globbed) && dotIdx !== -1) globbed.push('.');
    cb(err, globbed);
  });
}
888205
def public_keys(self):
        """"""
        if not self.public_keys_cache:
            conn = self.conn_factory()
            self.public_keys_cache = conn.export_public_keys(self.identities)
        return self.public_keys_cache
312826
def _storage_get_keys(bucket, pattern):
  
  return [item for item in list(bucket.items()) if fnmatch.fnmatch(item.metadata.name, pattern)]
1038116
def retrieve_blob(self, key, encoding=None):
        '''  '''
        blob_key = self.__retrieve(key)
        if blob_key is None:
            return None
        if not blob_key:
            raise Exception("Invalid blob_key")
        elif blob_key == JiCache.INTERNAL_BLOB:
            blob_data = self.__retrieve_internal_blob(key)
            return blob_data if not encoding else blob_data.decode(encoding)
        else:
            getLogger().debug("Key[{key}] -> [{blob_key}]".format(key=key, blob_key=blob_key))
            blob_file = os.path.join(self.blob_location, blob_key)
            return FileHelper.read(blob_file)
71732
def glob(*args):
    
    if len(args) is 1 and isinstance(args[0], list):
        args = args[0]
    matches = []
    for pattern in args:
        for item in glob2.glob(pattern):
            if not os.path.isdir(item):
                matches.append(item)
    return matches
1070816
def _get_key2sl(key):
    """"""
    if isinstance(key, (int, farray)) or key is Ellipsis:
        return key
    elif isinstance(key, slice):
        # Forbid slice steps
        if key.step is not None:
            raise ValueError("farray slice step is not supported")
        return key
    elif isinstance(key, boolfunc.Function):
        return farray([key])
    else:
        raise TypeError("expected int, slice, Function, farray, or ...")
357262
def get_key_files(kfiles, dirname, names):
    """"""
    for name in names:
        fullname = os.path.join(dirname, name)
        if os.path.isfile(fullname) and \
            fullname.endswith('_rsa') or \
                fullname.endswith('_dsa'):
            kfiles.put(fullname)
1017950
def glob_in_parents(dir, patterns, upper_limit=None):
    """"""

    assert(isinstance(dir, str))
    assert(isinstance(patterns, list))

    result = []

    absolute_dir = os.path.join(os.getcwd(), dir)
    absolute_dir = os.path.normpath(absolute_dir)
    while absolute_dir:
        new_dir = os.path.split(absolute_dir)[0]
        if new_dir == absolute_dir:
            break
        result = glob([new_dir], patterns)
        if result:
            break
        absolute_dir = new_dir

    return result
1162598
def get(key, default=None):
    '''
    
    '''
    store = load()

    if isinstance(key, six.string_types):
        return store.get(key, default)
    elif default is None:
        return [store[k] for k in key if k in store]
    else:
        return [store.get(k, default) for k in key]
47018
def super_glob(pattern):
    ''
    pieces = pattern.split('/')
    if '**' in pieces:
        prefix = '/'.join(pieces[:pieces.index('**')])
        postfix = '/'.join(pieces[pieces.index('**') + 1:])
        roots = [dirname
                 for dirname, dirnames, filenames in os.walk(prefix)]
        patterns = [root + '/' + postfix for root in roots]
    else:
        patterns = ['/'.join(pieces)]
    return chain.from_iterable(glob(pattern) for pattern in patterns)
335209
def get_tree(ident_hash, cursor, as_collated=False):
    """"""
    uuid, version = split_ident_hash(ident_hash)
    cursor.execute(SQL['get-tree-by-uuid-n-version'],
                   (uuid, version, as_collated,))
    try:
        tree = cursor.fetchone()[0]
    except TypeError:  # NoneType
        raise ContentNotFound()
    if type(tree) in (type(''), type(u'')):
        return json.loads(tree)
    else:
        return tree
1006673
def local_keys(self):
        '''
        
        '''
        ret = {'local': []}
        for fn_ in salt.utils.data.sorted_ignorecase(os.listdir(self.opts['pki_dir'])):
            if fn_.endswith('.pub') or fn_.endswith('.pem'):
                path = os.path.join(self.opts['pki_dir'], fn_)
                if os.path.isfile(path):
                    ret['local'].append(fn_)
        return ret
41915
def _get_filekey(self):
        """"""

        if not os.path.exists(self.keyfile):
            raise KPError('Keyfile not exists.')
        try:
            with open(self.keyfile, 'rb') as handler:
                handler.seek(0, os.SEEK_END)
                size = handler.tell()
                handler.seek(0, os.SEEK_SET)

                if size == 32:
                    return handler.read(32)
                elif size == 64:
                    try:
                        return binascii.unhexlify(handler.read(64))
                    except (TypeError, binascii.Error):
                        handler.seek(0, os.SEEK_SET)

                sha = SHA256.new()
                while True:
                    buf = handler.read(2048)
                    sha.update(buf)
                    if len(buf) < 2048:
                        break
                return sha.digest()
        except IOError as e:
            raise KPError('Could not read file: %s' % e)