From cfd2bf5882b72d6dbd09a1839b63ed41f3834365 Mon Sep 17 00:00:00 2001 From: Steve Martinelli Date: Sun, 18 Oct 2015 16:03:08 -0400 Subject: [PATCH] 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 --- openstackclient/api/object_store_v1.py | 8 ++++++++ openstackclient/common/utils.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/openstackclient/api/object_store_v1.py b/openstackclient/api/object_store_v1.py index b1c78d990a..ab75a78c29 100644 --- a/openstackclient/api/object_store_v1.py +++ b/openstackclient/api/object_store_v1.py @@ -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 diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index 51e2a2f9ca..8db4f35bc8 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -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