Decode base64 before printing
Decode base64 before printing so that meteos-ui does not need to decode. Change-Id: If0a3d8589f953fe8840375727878ebdd71c6a75d
This commit is contained in:
parent
5a1100b954
commit
fe9c622e2d
@ -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)
|
||||
|
@ -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',
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user