summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/config/cc_apt_configure.py4
-rw-r--r--cloudinit/gpg.py24
-rw-r--r--tests/unittests/test_handler/test_handler_apt_source.py4
3 files changed, 15 insertions, 17 deletions
diff --git a/cloudinit/config/cc_apt_configure.py b/cloudinit/config/cc_apt_configure.py
index ba080930..96c4a43d 100644
--- a/cloudinit/config/cc_apt_configure.py
+++ b/cloudinit/config/cc_apt_configure.py
@@ -22,9 +22,9 @@ import glob
import os
import re
+from cloudinit import gpg
from cloudinit import templater
from cloudinit import util
-from cloudinit import gpg
distros = ['ubuntu', 'debian']
@@ -168,7 +168,7 @@ def add_apt_key(ent):
keyserver = "keyserver.ubuntu.com"
if 'keyserver' in ent:
keyserver = ent['keyserver']
- ent['key'] = gpg.gpg_getkeybyid(ent['keyid'], keyserver)
+ ent['key'] = gpg.get_key_by_id(ent['keyid'], keyserver)
if 'key' in ent:
add_apt_key_raw(ent['key'])
diff --git a/cloudinit/gpg.py b/cloudinit/gpg.py
index baa8b534..6a76d785 100644
--- a/cloudinit/gpg.py
+++ b/cloudinit/gpg.py
@@ -4,8 +4,6 @@
# Copyright (C) 2016 Canonical Ltd.
#
# Author: Scott Moser <scott.moser@canonical.com>
-# Author: Juerg Haefliger <juerg.haefliger@hp.com>
-# Author: Joshua Harlow <harlowja@yahoo-inc.com>
# Author: Christian Ehrhardt <christian.ehrhardt@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
@@ -20,13 +18,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from cloudinit import util
from cloudinit import log as logging
+from cloudinit import util
LOG = logging.getLogger(__name__)
-def gpg_export_armour(key):
+def export_armour(key):
"""Export gpg key, armoured key gets returned"""
try:
(armour, _) = util.subp(["gpg", "--export", "--armour", key],
@@ -38,11 +36,11 @@ def gpg_export_armour(key):
return armour
-def gpg_recv_key(key, keyserver):
+def receive_key(key, keyserver):
"""Receive gpg key from the specified keyserver"""
LOG.debug('Receive gpg key "%s"', key)
try:
- util.subp(["gpg", "--keyserver", keyserver, "--recv", key],
+ util.subp(["gpg", "--keyserver", keyserver, "--recv-keys", key],
capture=True)
except util.ProcessExecutionError as error:
raise ValueError(('Failed to import key "%s" '
@@ -50,7 +48,7 @@ def gpg_recv_key(key, keyserver):
(key, keyserver, error))
-def gpg_delete_key(key):
+def delete_key(key):
"""Delete the specified key from the local gpg ring"""
try:
util.subp(["gpg", "--batch", "--yes", "--delete-keys", key],
@@ -59,18 +57,18 @@ def gpg_delete_key(key):
LOG.warn('Failed delete key "%s": %s', key, error)
-def gpg_getkeybyid(keyid, keyserver):
+def get_key_by_id(keyid, keyserver="keyserver.ubuntu.com"):
"""get gpg keyid from keyserver"""
- armour = gpg_export_armour(keyid)
+ armour = export_armour(keyid)
if not armour:
try:
- gpg_recv_key(keyid, keyserver=keyserver)
- armour = gpg_export_armour(keyid)
+ receive_key(keyid, keyserver=keyserver)
+ armour = export_armour(keyid)
except ValueError:
LOG.exception('Failed to obtain gpg key %s', keyid)
raise
finally:
# delete just imported key to leave environment as it was before
- gpg_delete_key(keyid)
+ delete_key(keyid)
- return armour.rstrip('\n')
+ return armour
diff --git a/tests/unittests/test_handler/test_handler_apt_source.py b/tests/unittests/test_handler/test_handler_apt_source.py
index 5b52f709..99a4d860 100644
--- a/tests/unittests/test_handler/test_handler_apt_source.py
+++ b/tests/unittests/test_handler/test_handler_apt_source.py
@@ -13,8 +13,8 @@ except ImportError:
from mock import call
from cloudinit.config import cc_apt_configure
-from cloudinit import util
from cloudinit import gpg
+from cloudinit import util
from ..helpers import TestCase
@@ -405,7 +405,7 @@ class TestAptSourceConfig(TestCase):
params = self._get_default_params()
with mock.patch.object(cc_apt_configure, 'add_apt_key_raw') as mockkey:
- with mock.patch.object(gpg, 'gpg_getkeybyid',
+ with mock.patch.object(gpg, 'get_key_by_id',
return_value=expectedkey) as mockgetkey:
cc_apt_configure.add_apt_sources([cfg], params)