summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKiall Mac Innes <kiall@hp.com>2014-01-13 14:44:24 +0000
committerKiall Mac Innes <kiall@hp.com>2014-01-13 14:57:22 +0000
commit154ab91a19c9ce546297f75acdf190db8e094fee (patch)
tree0685f716d99619ee52834097a49ae72197d0b931
parent516bce30a69dfc27ad80a9828695eef4ade4f4e4 (diff)
downloaddesignate-stable/havana.tar.gz
Ensure Flask uses our JSON Encoderhavana-eol2013.2.1stable/havana
Since the upgrade to Flask 0.10, we've not been using the correct JSONEncoder. Up until today, we this was "not a problem", as python-keystoneclient depended on simplejson, which provided the necessary features. python-keystoneclient 0.4.2 was released today, causing the issue to finally surface. Change-Id: Idc0e8f03608c80e097db2ea48b30f2bc0b8dbe5d Closes-Bug: 1268607
-rw-r--r--designate/api/__init__.py7
-rw-r--r--designate/api/v1/__init__.py8
2 files changed, 9 insertions, 6 deletions
diff --git a/designate/api/__init__.py b/designate/api/__init__.py
index 2b19a7b9..9016ab32 100644
--- a/designate/api/__init__.py
+++ b/designate/api/__init__.py
@@ -13,9 +13,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
-import flask
from oslo.config import cfg
-from designate.openstack.common import jsonutils as json
+
cfg.CONF.register_group(cfg.OptGroup(
name='service:api', title="Configuration for API Service"
@@ -37,7 +36,3 @@ cfg.CONF.register_opts([
cfg.BoolOpt('enable-api-v1', default=True),
cfg.BoolOpt('enable-api-v2', default=False),
], group='service:api')
-
-
-# Allows us to serialize datetime's etc
-flask.helpers.json = json
diff --git a/designate/api/v1/__init__.py b/designate/api/v1/__init__.py
index 31817fd2..090335e0 100644
--- a/designate/api/v1/__init__.py
+++ b/designate/api/v1/__init__.py
@@ -23,6 +23,7 @@ from werkzeug.routing import ValidationError
from oslo.config import cfg
from designate.openstack.common import log as logging
from designate.openstack.common import uuidutils
+from designate.openstack.common import jsonutils
from designate import exceptions
LOG = logging.getLogger(__name__)
@@ -54,6 +55,12 @@ class DesignateRequest(flask.Request, wrappers.AcceptMixin,
raise exceptions.UnsupportedAccept(msg)
+class JSONEncoder(flask.json.JSONEncoder):
+ @staticmethod
+ def default(o):
+ return jsonutils.to_primitive(o)
+
+
def factory(global_config, **local_conf):
if not cfg.CONF['service:api'].enable_api_v1:
def disabled_app(environ, start_response):
@@ -65,6 +72,7 @@ def factory(global_config, **local_conf):
app = flask.Flask('designate.api.v1')
app.request_class = DesignateRequest
+ app.json_encoder = JSONEncoder
app.config.update(
PROPAGATE_EXCEPTIONS=True
)