Ensure Flask uses our JSON Encoder
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
This commit is contained in:
parent
516bce30a6
commit
154ab91a19
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue