.. versionadded:: 2015.8.0

    Remove a repo key using ``apt-key del``

    name
        Repo from which to remove the key. Unnecessary if ``keyid`` is passed.

    keyid
        The KeyID of the GPG key to remove

    keyid_ppa : False
        If set to ``True``, the repo's GPG key ID will be looked up from
        ppa.launchpad.net and removed.

        .. note::

            Setting this option to ``True`` requires that the ``name`` param
            also be passed.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.del_repo_key keyid=0123ABCD
        salt '*' pkg.del_repo_key name='ppa:foo/bar' keyid_ppa=True

def del_repo_key(name=None, **kwargs):
    '''
    .. versionadded:: 2015.8.0

    Remove a repo key using ``apt-key del``

    name
        Repo from which to remove the key. Unnecessary if ``keyid`` is passed.

    keyid
        The KeyID of the GPG key to remove

    keyid_ppa : False
        If set to ``True``, the repo's GPG key ID will be looked up from
        ppa.launchpad.net and removed.

        .. note::

            Setting this option to ``True`` requires that the ``name`` param
            also be passed.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.del_repo_key keyid=0123ABCD
        salt '*' pkg.del_repo_key name='ppa:foo/bar' keyid_ppa=True
    '''
    if kwargs.get('keyid_ppa', False):
        if isinstance(name, six.string_types) and name.startswith('ppa:'):
            owner_name, ppa_name = name[4:].split('/')
            ppa_info = _get_ppa_info_from_launchpad(
                owner_name, ppa_name)
            keyid = ppa_info['signing_key_fingerprint'][-8:]
        else:
            raise SaltInvocationError(
                'keyid_ppa requires that a PPA be passed'
            )
    else:
        if 'keyid' in kwargs:
            keyid = kwargs.get('keyid')
        else:
            raise SaltInvocationError(
                'keyid or keyid_ppa and PPA name must be passed'
            )

    result = _call_apt(['apt-key', 'del', keyid], scope=False)
    if result['retcode'] != 0:
        msg = 'Failed to remove keyid {0}'
        if result['stderr']:
            msg += ': {0}'.format(result['stderr'])
        raise CommandExecutionError(msg)
    return keyid