diff options
author | Scott Moser <smoser@ubuntu.com> | 2018-03-01 15:39:16 -0700 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2018-03-01 15:39:16 -0700 |
commit | 40e77380e036a24fafe91a63d0cdefada4312348 (patch) | |
tree | 5f8dc8166537a70cdce5c6b6dbb3862efcb803d5 /cloudinit | |
parent | 417a5c03523ac477983dd830957190858b045d62 (diff) | |
download | vyos-cloud-init-40e77380e036a24fafe91a63d0cdefada4312348.tar.gz vyos-cloud-init-40e77380e036a24fafe91a63d0cdefada4312348.zip |
GCE: fix reading of user-data that is not base64 encoded.
Last set of changes to GCE datasource broke reading of user-data
unless the user had base64 encoded their user-data and also set
user-data-encoding to 'base64'.
This fixes the issue.
LP: #1752711
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/sources/DataSourceGCE.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py index 2da34a99..bebc9918 100644 --- a/cloudinit/sources/DataSourceGCE.py +++ b/cloudinit/sources/DataSourceGCE.py @@ -213,16 +213,15 @@ def read_md(address=None, platform_check=True): if md['availability-zone']: md['availability-zone'] = md['availability-zone'].split('/')[-1] - encoding = instance_data.get('user-data-encoding') - if encoding: + if 'user-data' in instance_data: + # instance_data was json, so values are all utf-8 strings. + ud = instance_data['user-data'].encode("utf-8") + encoding = instance_data.get('user-data-encoding') if encoding == 'base64': - md['user-data'] = b64decode(instance_data.get('user-data')) - else: + ud = b64decode(ud) + elif encoding: LOG.warning('unknown user-data-encoding: %s, ignoring', encoding) - - if 'user-data' in md: - ret['user-data'] = md['user-data'] - del md['user-data'] + ret['user-data'] = ud ret['meta-data'] = md ret['success'] = True |