validate non-ascii values for swift properties

skip properties that are non-ascii values, but proceed
with properties that work. log these failed values back
to the user.

Change-Id: Iaca8909f4465a01c8aebfd290b1a322823702359
Closes-Bug: 1503898
This commit is contained in:
Steve Martinelli 2015-10-18 16:03:08 -04:00 committed by Dean Troyer
parent 6fdc9a891f
commit cfd2bf5882
2 changed files with 16 additions and 0 deletions

View File

@ -14,6 +14,7 @@
"""Object Store v1 API Library"""
import io
import logging
import os
import six
@ -25,6 +26,7 @@ except ImportError:
from urlparse import urlparse # noqa
from openstackclient.api import api
from openstackclient.common import utils
class APIv1(api.BaseAPI):
@ -551,8 +553,14 @@ class APIv1(api.BaseAPI):
# property we use: "X-Add-Container-Meta-Book: MobyDick", and the same
# logic applies for Object properties
log = logging.getLogger(__name__ + '._set_properties')
headers = {}
for k, v in properties.iteritems():
if not utils.is_ascii(k) or not utils.is_ascii(v):
log.error('Cannot set property %s to non-ascii value', k)
continue
header_name = header_tag % k
headers[header_name] = v
return headers

View File

@ -419,3 +419,11 @@ def build_kwargs_dict(arg_name, value):
if value:
kwargs[arg_name] = value
return kwargs
def is_ascii(string):
try:
string.decode('ascii')
return True
except UnicodeDecodeError:
return False