diff --git a/HACKING.rst b/HACKING.rst index 81d0ff271..3c26e1931 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -1,5 +1,5 @@ Barbican Style Commandments -============================ +=========================== - Step 1: Read the OpenStack Style Commandments https://docs.openstack.org/hacking/latest/ @@ -7,7 +7,7 @@ Barbican Style Commandments Barbican Specific Commandments -------------------------------- +------------------------------ - [B310] Check for improper use of logging format arguments. - [B311] Use assertIsNone(...) instead of assertEqual(None, ...). diff --git a/barbican/api/hooks.py b/barbican/api/hooks.py index 5b502e898..a6723b1e0 100644 --- a/barbican/api/hooks.py +++ b/barbican/api/hooks.py @@ -15,7 +15,7 @@ import pecan import webob -from oslo_serialization import jsonutils +from oslo_serialization import jsonutils as json try: import newrelic.agent @@ -29,7 +29,7 @@ from barbican.model import repositories class JSONErrorHook(pecan.hooks.PecanHook): def on_error(self, state, exc): if isinstance(exc, webob.exc.HTTPError): - exc.body = jsonutils.dump_as_bytes({ + exc.body = json.dump_as_bytes({ 'code': exc.status_int, 'title': exc.title, 'description': exc.detail diff --git a/barbican/cmd/pkcs11_kek_rewrap.py b/barbican/cmd/pkcs11_kek_rewrap.py index 38167575c..bc02d97ca 100644 --- a/barbican/cmd/pkcs11_kek_rewrap.py +++ b/barbican/cmd/pkcs11_kek_rewrap.py @@ -11,12 +11,13 @@ # 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 argparse import base64 -import json import traceback from oslo_db.sqlalchemy import session +from oslo_serialization import jsonutils as json from sqlalchemy import orm from sqlalchemy.orm import scoping diff --git a/barbican/cmd/pkcs11_migrate_kek_signatures.py b/barbican/cmd/pkcs11_migrate_kek_signatures.py index 8c4628118..9e6cc6089 100644 --- a/barbican/cmd/pkcs11_migrate_kek_signatures.py +++ b/barbican/cmd/pkcs11_migrate_kek_signatures.py @@ -11,13 +11,14 @@ # 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 argparse import base64 -import json import six import traceback from oslo_db.sqlalchemy import session +from oslo_serialization import jsonutils as json from sqlalchemy import orm from sqlalchemy.orm import scoping diff --git a/barbican/objects/fields.py b/barbican/objects/fields.py index 229c2eee3..25d5ba138 100644 --- a/barbican/objects/fields.py +++ b/barbican/objects/fields.py @@ -11,8 +11,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 json +from oslo_serialization import jsonutils as json from oslo_versionedobjects import fields import six diff --git a/barbican/tests/api/controllers/test_secretmeta.py b/barbican/tests/api/controllers/test_secretmeta.py index e947ef9cc..c7ff25b9e 100644 --- a/barbican/tests/api/controllers/test_secretmeta.py +++ b/barbican/tests/api/controllers/test_secretmeta.py @@ -12,9 +12,11 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -import json -import mock + import os + +import mock +from oslo_serialization import jsonutils as json from oslo_utils import uuidutils from barbican.tests import utils diff --git a/bin/demo_requests.py b/bin/demo_requests.py index a659b47b3..6bff33082 100755 --- a/bin/demo_requests.py +++ b/bin/demo_requests.py @@ -21,11 +21,12 @@ required including the Barbican Python client. Note that this script is not intended to replace DevStack or Tempest style testing. """ -import json import logging import requests import sys +from oslo_serialization import jsonutils as json + LOG = logging.getLogger(__name__) LOG.setLevel(logging.DEBUG) diff --git a/functionaltests/api/v1/behaviors/secretmeta_behaviors.py b/functionaltests/api/v1/behaviors/secretmeta_behaviors.py index d1e731e7b..00c6745be 100644 --- a/functionaltests/api/v1/behaviors/secretmeta_behaviors.py +++ b/functionaltests/api/v1/behaviors/secretmeta_behaviors.py @@ -13,7 +13,8 @@ WITHOUT 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 json + +from oslo_serialization import jsonutils as json from functionaltests.api.v1.behaviors import base_behaviors diff --git a/functionaltests/api/v1/functional/test_orders.py b/functionaltests/api/v1/functional/test_orders.py index 900ea9b75..57e2a07b8 100644 --- a/functionaltests/api/v1/functional/test_orders.py +++ b/functionaltests/api/v1/functional/test_orders.py @@ -12,10 +12,11 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -from oslo_serialization import jsonutils + import sys import time +from oslo_serialization import jsonutils as json import testtools from testtools import testcase @@ -296,7 +297,7 @@ class OrdersTestCase(base.TestCase): resp, order_ref = self.behaviors.create_order(test_model) # Make sure we actually get a message back - error_msg = jsonutils.loads(resp.content).get('title') + error_msg = json.loads(resp.content).get('title') self.assertEqual(400, resp.status_code) self.assertIsNotNone(error_msg) diff --git a/functionaltests/api/v1/functional/test_secretmeta.py b/functionaltests/api/v1/functional/test_secretmeta.py index 873d85660..fb381e055 100644 --- a/functionaltests/api/v1/functional/test_secretmeta.py +++ b/functionaltests/api/v1/functional/test_secretmeta.py @@ -12,7 +12,9 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -from oslo_serialization import jsonutils + +from oslo_serialization import jsonutils as json +from oslo_utils import uuidutils from testtools import testcase from barbican.tests import utils @@ -20,7 +22,6 @@ from functionaltests.api import base from functionaltests.api.v1.behaviors import secret_behaviors from functionaltests.api.v1.behaviors import secretmeta_behaviors from functionaltests.api.v1.models import secret_models -from oslo_utils import uuidutils @utils.parameterized_test_case @@ -107,7 +108,7 @@ class SecretMetadataTestCase(base.TestCase): get_resp = self.behaviors.get_metadata(secret_ref) self.assertEqual(200, get_resp.status_code) - self.assertEqual(jsonutils.loads(get_resp.content), + self.assertEqual(json.loads(get_resp.content), self.valid_metadata) @testcase.attr('negative') @@ -171,7 +172,7 @@ class SecretMetadataTestCase(base.TestCase): get_resp = self.behaviors.get_metadatum(secret_ref, self.valid_metadatum_key) self.assertEqual(200, get_resp.status_code) - self.assertEqual(jsonutils.loads(get_resp.content), + self.assertEqual(json.loads(get_resp.content), self.valid_metadatum) @testcase.attr('negative') diff --git a/functionaltests/api/v1/functional/test_secrets.py b/functionaltests/api/v1/functional/test_secrets.py index cef41f50e..a92dbce27 100644 --- a/functionaltests/api/v1/functional/test_secrets.py +++ b/functionaltests/api/v1/functional/test_secrets.py @@ -15,7 +15,7 @@ import datetime from oslo_serialization import base64 as oslo_base64 -from oslo_serialization import jsonutils +from oslo_serialization import jsonutils as json import six import sys import testtools @@ -512,7 +512,7 @@ class SecretsTestCase(base.TestCase): # first, ensure that the return code is 400 self.assertEqual(400, resp.status_code) - resp_dict = jsonutils.loads(resp.content) + resp_dict = json.loads(resp.content) self.assertIn( "Provided object does not match schema 'Secret': " diff --git a/functionaltests/api/v1/models/base_models.py b/functionaltests/api/v1/models/base_models.py index a56a72e51..69dc94798 100644 --- a/functionaltests/api/v1/models/base_models.py +++ b/functionaltests/api/v1/models/base_models.py @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. """ import logging -from oslo_serialization import jsonutils +from oslo_serialization import jsonutils as json LOG = logging.getLogger(__name__) @@ -34,7 +34,7 @@ class BaseModel(object): :return: A string of JSON containing the fields in this object """ - return jsonutils.dump_as_bytes(self.obj_to_dict()) + return json.dump_as_bytes(self.obj_to_dict()) def obj_to_dict(self): """Create a dict of the values for this model object. @@ -74,7 +74,7 @@ class BaseModel(object): :return: a secret object """ try: - json_dict = jsonutils.loads(serialized_str) + json_dict = json.loads(serialized_str) return cls.dict_to_obj(json_dict) except TypeError as e: LOG.error('Couldn\'t deserialize input: %s\n Because: %s',