Skip to content

Commit 99f0152

Browse files
mboersmaGabriel Monroy
authored andcommitted
fix(controller+client): utf-8 encode only string types
1 parent fd6bd50 commit 99f0152

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

client/deis.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,14 @@ def dictify(args):
303303
return data
304304

305305

306+
def encode(obj):
307+
"""Return UTF-8 encoding for string objects."""
308+
if isinstance(obj, basestring):
309+
return obj.encode('utf-8')
310+
else:
311+
return obj
312+
313+
306314
def readable_datetime(datetime_str):
307315
"""
308316
Return a human-readable datetime string from an ECMA-262 (JavaScript)
@@ -1123,14 +1131,13 @@ def config_list(self, args):
11231131
width = max(map(len, keys)) + 5
11241132
for k in keys:
11251133
v = values[k]
1126-
k, v = k.encode('utf-8'), v.encode('utf-8')
1127-
self._logger.info(("{k:<" + str(width) + "} {v}").format(**locals()))
1134+
self._logger.info("{:<" + str(width) + "} {}".format(
1135+
encode(k), encode(v)))
11281136
else:
11291137
output = []
11301138
for k in keys:
11311139
v = values[k]
1132-
k, v = k.encode('utf-8'), v.encode('utf-8')
1133-
output.append("{k}={v}".format(**locals()))
1140+
output.append("{}={}".format(encode(k), encode(v)))
11341141
self._logger.info(' '.join(output))
11351142
else:
11361143
raise ResponseError(response)
@@ -1175,8 +1182,7 @@ def config_set(self, args):
11751182
self._logger.info('No configuration')
11761183
return
11771184
for k, v in values.items():
1178-
k, v = k.encode('utf-8'), v.encode('utf-8')
1179-
self._logger.info("{k}: {v}".format(**locals()))
1185+
self._logger.info("{}: {}".format(encode(k), encode(v)))
11801186
else:
11811187
raise ResponseError(response)
11821188

controller/registry/private.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ def _put_tag(image_id, repository_path, tag):
158158

159159
# utility functions
160160

161+
def encode(obj):
162+
"""Return UTF-8 encoding for string objects."""
163+
if isinstance(obj, basestring):
164+
return obj.encode('utf-8')
165+
else:
166+
return obj
167+
161168

162169
def _construct_env(env, config):
163170
"Update current environment with latest config"
@@ -168,10 +175,10 @@ def _construct_env(env, config):
168175
if k in config:
169176
# update values defined by config
170177
v = config.pop(k)
171-
new_env.append("{}={}".format(k.encode('utf-8'), v.encode('utf-8')))
178+
new_env.append("{}={}".format(encode(k), encode(v)))
172179
# add other config ENV items
173180
for k, v in config.items():
174-
new_env.append("{}={}".format(k.encode('utf-8'), v.encode('utf-8')))
181+
new_env.append("{}={}".format(encode(k), encode(v)))
175182
return new_env
176183

177184

tests/config_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
var (
1212
configListCmd = "config:list --app={{.AppName}}"
1313
configSetCmd = "config:set FOO=讲台 --app={{.AppName}}"
14+
configSet2Cmd = "config:set FOO=10 --app={{.AppName}}"
1415
configUnsetCmd = "config:unset FOO --app={{.AppName}}"
1516
)
1617

@@ -52,11 +53,13 @@ func configListTest(
5253
}
5354

5455
func configSetTest(t *testing.T, params *utils.DeisTestConfig) {
55-
utils.Execute(t, configSetCmd, params, false, "")
56+
utils.Execute(t, configSetCmd, params, false, "讲台")
5657
utils.CheckList(t, appsInfoCmd, params, "(v3)", false)
58+
utils.Execute(t, configSet2Cmd, params, false, "10")
59+
utils.CheckList(t, appsInfoCmd, params, "(v4)", false)
5760
}
5861

5962
func configUnsetTest(t *testing.T, params *utils.DeisTestConfig) {
6063
utils.Execute(t, configUnsetCmd, params, false, "")
61-
utils.CheckList(t, appsInfoCmd, params, "(v4)", false)
64+
utils.CheckList(t, appsInfoCmd, params, "(v5)", false)
6265
}

0 commit comments

Comments
 (0)