summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceSmartOS.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2015-01-27 15:03:52 -0500
committerBarry Warsaw <barry@python.org>2015-01-27 15:03:52 -0500
commit6e742d20e9ed56498925c7c850cd5da65d063b4b (patch)
tree3e584ae2381d72d2b77c6f2d98c9be93bcb9e413 /cloudinit/sources/DataSourceSmartOS.py
parent69c64029997599b3f1764ef48fe571094e2ee5f2 (diff)
downloadvyos-cloud-init-6e742d20e9ed56498925c7c850cd5da65d063b4b.tar.gz
vyos-cloud-init-6e742d20e9ed56498925c7c850cd5da65d063b4b.zip
Respond to review:
- Refactor both the base64 encoding and decoding into utility functions. Also: - Mechanically fix some other broken untested code.
Diffstat (limited to 'cloudinit/sources/DataSourceSmartOS.py')
-rw-r--r--cloudinit/sources/DataSourceSmartOS.py11
1 files changed, 1 insertions, 10 deletions
diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py
index f59ad3d6..9d48beab 100644
--- a/cloudinit/sources/DataSourceSmartOS.py
+++ b/cloudinit/sources/DataSourceSmartOS.py
@@ -351,16 +351,7 @@ def query_data(noun, seed_device, seed_timeout, strip=False, default=None,
if b64:
try:
- # Generally, we want native strings in the values. Python 3's
- # b64decode will return bytes though, so decode them to utf-8 if
- # possible. If that fails, return the bytes.
- decoded = base64.b64decode(resp)
- try:
- if isinstance(decoded, bytes):
- return decoded.decode('utf-8')
- except UnicodeDecodeError:
- pass
- return decoded
+ return util.b64d(resp)
# Bogus input produces different errors in Python 2 and 3; catch both.
except (TypeError, binascii.Error):
LOG.warn("Failed base64 decoding key '%s'", noun)