diff --git a/meteosclient/api/base.py b/meteosclient/api/base.py index 5c6166b..19e30cf 100644 --- a/meteosclient/api/base.py +++ b/meteosclient/api/base.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import base64 import copy import json import logging @@ -172,7 +173,8 @@ class ResourceManager(object): resp = self.api.get(url) if resp.status_code == 200: result = get_json(resp) - data = result[response_key] + base64_params = ['args', 'params'] + data = decode_base64(result[response_key], base64_params) meta = result.get('markers') next, prev = None, None @@ -234,6 +236,16 @@ def get_json(response): return json.loads(response.content) +def decode_base64(data, base64_params): + + for item in data: + for key, value in item.items(): + if key in base64_params: + item[key] = base64.b64decode(value) + + return data + + class APIException(Exception): def __init__(self, error_code=None, error_name=None, error_message=None): super(APIException, self).__init__(error_message) diff --git a/meteosclient/api/shell.py b/meteosclient/api/shell.py index e27aeb7..87671bc 100644 --- a/meteosclient/api/shell.py +++ b/meteosclient/api/shell.py @@ -378,8 +378,7 @@ def do_learning_list(cs, args): 'status', 'args', 'stdout') - base64_params = ['args'] - utils.print_list(learnings, columns, base64_params=base64_params) + utils.print_list(learnings, columns) @utils.arg('id', diff --git a/meteosclient/openstack/common/cliutils.py b/meteosclient/openstack/common/cliutils.py index a1ac7f4..08dca38 100644 --- a/meteosclient/openstack/common/cliutils.py +++ b/meteosclient/openstack/common/cliutils.py @@ -18,7 +18,6 @@ from __future__ import print_function -import base64 import getpass import inspect import os @@ -139,13 +138,12 @@ def isunauthenticated(func): return getattr(func, 'unauthenticated', False) -def print_list(objs, fields, base64_params=[], formatters=None, sortby_index=0, +def print_list(objs, fields, formatters=None, sortby_index=0, mixed_case_fields=None, field_labels=None): """Print a list of objects as a table, one row per object. :param objs: iterable of :class:`Resource` :param fields: attributes that correspond to columns, in order - :param base64_params: indicate a column which encoded by base64 :param formatters: `dict` of callables for field formatting :param sortby_index: index of the field for sorting table rows :param mixed_case_fields: fields corresponding to object attributes that @@ -178,9 +176,6 @@ def print_list(objs, fields, base64_params=[], formatters=None, sortby_index=0, field_name = field.replace(' ', '_') else: field_name = field.lower().replace(' ', '_') - if field in base64_params: - data = base64.b64decode(getattr(o, field_name, '')) - else: data = getattr(o, field_name, '') row.append(data) pt.add_row(row)