Get a key from the GPG keychain

    keyid
        The key ID (short or long) of the key to be retrieved.

    fingerprint
        The fingerprint of the key to be retrieved.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.get_key keyid=3FAD9F1E

        salt '*' gpg.get_key fingerprint=53C96788253E58416D20BCD352952C84C3252192

        salt '*' gpg.get_key keyid=3FAD9F1E user=username

def get_key(keyid=None, fingerprint=None, user=None, gnupghome=None):
    '''
    Get a key from the GPG keychain

    keyid
        The key ID (short or long) of the key to be retrieved.

    fingerprint
        The fingerprint of the key to be retrieved.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.get_key keyid=3FAD9F1E

        salt '*' gpg.get_key fingerprint=53C96788253E58416D20BCD352952C84C3252192

        salt '*' gpg.get_key keyid=3FAD9F1E user=username

    '''
    tmp = {}
    for _key in _list_keys(user, gnupghome):
        if (_key['fingerprint'] == fingerprint or
                _key['keyid'] == keyid or
                _key['keyid'][8:] == keyid):
            tmp['keyid'] = _key['keyid']
            tmp['fingerprint'] = _key['fingerprint']
            tmp['uids'] = _key['uids']

            expires = _key.get('expires', None)
            date = _key.get('date', None)
            length = _key.get('length', None)
            owner_trust = _key.get('ownertrust', None)
            trust = _key.get('trust', None)

            if expires:
                tmp['expires'] = time.strftime('%Y-%m-%d',
                                               time.localtime(float(_key['expires'])))
            if date:
                tmp['created'] = time.strftime('%Y-%m-%d',
                                               time.localtime(float(_key['date'])))
            if length:
                tmp['keyLength'] = _key['length']
            if owner_trust:
                tmp['ownerTrust'] = LETTER_TRUST_DICT[_key['ownertrust']]
            if trust:
                tmp['trust'] = LETTER_TRUST_DICT[_key['trust']]
    if not tmp:
        return False
    else:
        return tmp