Add key_text option to apt pkgrepo.managed (closes #37936)

It may not always possible or desirable to upload a GPG key to a
keyserver (`keyid`/`keyserver`) or to host it on remote server
(`key_url`). This just leaves storing the key in a state using a
`salt://` URL.

It seems like the states is the wrong place to hold this sort of data,
and would be more suited to being in the pillar.

Adding a `key_text` option to the apt `pkgrepo.managed` module, which
accepts a GPG key in string form, can assist in importing a GPG key from
pillar data.
This commit is contained in:
John Kristensen 2017-03-15 17:54:07 +11:00
parent f5d4334178
commit 8e92152533
2 changed files with 16 additions and 0 deletions

View file

@ -68497,6 +68497,9 @@ key id to load with the keyserver argument
.B key_url
URL to a GPG key to add to the APT GPG keyring
.TP
.B key_text
GPG key in string form to add to the APT GPG keyring
.TP
.B consolidate
if \fBTrue\fP, will attempt to de\-dup and consolidate sources
.TP

View file

@ -2106,6 +2106,9 @@ def mod_repo(repo, saltenv='base', **kwargs):
key_url
URL to a GPG key to add to the APT GPG keyring
key_text
GPG key in string form to add to the APT GPG keyring
consolidate
if ``True``, will attempt to de-dup and consolidate sources
@ -2305,6 +2308,16 @@ def mod_repo(repo, saltenv='base', **kwargs):
'Error: failed to add key from {0}'.format(key_url)
)
elif 'key_text' in kwargs:
key_text = kwargs['key_text']
cmd = ['apt-key', 'add', '-']
out = __salt__['cmd.run_stdout'](cmd, stdin=key_text,
python_shell=False, **kwargs)
if not out.upper().startswith('OK'):
raise CommandExecutionError(
'Error: failed to add key:\n{0}'.format(key_text)
)
if 'comps' in kwargs:
kwargs['comps'] = kwargs['comps'].split(',')
full_comp_list |= set(kwargs['comps'])