From 40e77380e036a24fafe91a63d0cdefada4312348 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 1 Mar 2018 15:39:16 -0700 Subject: 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 --- cloudinit/sources/DataSourceGCE.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'cloudinit/sources') 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 -- cgit v1.2.3