1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge branch 'andreasf-apt_key_format' into devel

This commit is contained in:
James Cammarata 2014-04-24 00:17:01 -05:00
commit 3a20291838

View file

@ -120,11 +120,11 @@ def check_missing_binaries(module):
if len(missing): if len(missing):
module.fail_json(msg="binaries are missing", names=missing) module.fail_json(msg="binaries are missing", names=missing)
def all_keys(module, keyring): def all_keys(module, keyring, short_format):
if keyring: if keyring:
cmd = "apt-key --keyring %s list" % keyring cmd = "apt-key --keyring %s adv --list-public-keys --keyid-format=long" % keyring
else: else:
cmd = "apt-key list" cmd = "apt-key adv --list-public-keys --keyid-format=long"
(rc, out, err) = module.run_command(cmd) (rc, out, err) = module.run_command(cmd)
results = [] results = []
lines = out.split('\n') lines = out.split('\n')
@ -134,11 +134,19 @@ def all_keys(module, keyring):
code = tokens[1] code = tokens[1]
(len_type, real_code) = code.split("/") (len_type, real_code) = code.split("/")
results.append(real_code) results.append(real_code)
if short_format:
results = shorten_key_ids(results)
return results return results
def key_present(module, key_id): def shorten_key_ids(key_id_list):
(rc, out, err) = module.run_command("apt-key list | 2>&1 grep -i -q %s" % pipes.quote(key_id), use_unsafe_shell=True) """
return rc == 0 Takes a list of key ids, and converts them to the 'short' format,
by reducing them to their last 8 characters.
"""
short = []
for key in key_id_list:
short.append(key[-8:])
return short
def download_key(module, url): def download_key(module, url):
# FIXME: move get_url code to common, allow for in-memory D/L, support proxies # FIXME: move get_url code to common, allow for in-memory D/L, support proxies
@ -217,7 +225,8 @@ def main():
# FIXME: I think we have a common facility for this, if not, want # FIXME: I think we have a common facility for this, if not, want
check_missing_binaries(module) check_missing_binaries(module)
keys = all_keys(module, keyring) short_format = (key_id is not None and len(key_id) == 8)
keys = all_keys(module, keyring, short_format)
return_values = {} return_values = {}
if state == 'present': if state == 'present':
@ -238,7 +247,7 @@ def main():
else: else:
add_key(module, "-", keyring, data) add_key(module, "-", keyring, data)
changed=False changed=False
keys2 = all_keys(module, keyring) keys2 = all_keys(module, keyring, short_format)
if len(keys) != len(keys2): if len(keys) != len(keys2):
changed=True changed=True
if key_id and not key_id in keys2: if key_id and not key_id in keys2: