From 4597a67e0c7fc2f3d187877b718e4405432d158a Mon Sep 17 00:00:00 2001 From: Pino de Candia Date: Fri, 8 Dec 2017 22:21:25 +0000 Subject: [PATCH] Final pep8 fixes. --- tatu/api/models.py | 2 +- tatu/castellano.py | 1 + tatu/db/models.py | 6 +++--- tatu/db/persistence.py | 5 ++--- tatu/ftests/test_api.py | 2 +- tatu/notifications.py | 10 +++++----- tatu/tests/test_app.py | 5 +++-- tatu/utils.py | 3 +-- tox.ini | 14 +++++++------- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tatu/api/models.py b/tatu/api/models.py index beba558..11a5ee4 100644 --- a/tatu/api/models.py +++ b/tatu/api/models.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. +from Crypto.PublicKey import RSA import falcon import json import logging import uuid -from Crypto.PublicKey import RSA from tatu.db import models as db diff --git a/tatu/castellano.py b/tatu/castellano.py index 835ffaa..9c0679a 100644 --- a/tatu/castellano.py +++ b/tatu/castellano.py @@ -91,6 +91,7 @@ castellan library, it is not meant for direct usage within tatu. class TatuKeyManager(KeyManager): """Tatu specific key manager + This manager is a thin wrapper around the secret being stored. It is intended for backward compatible use only. It will not store keys or generate UUIDs but instead return the secret that is being stored. diff --git a/tatu/db/models.py b/tatu/db/models.py index 06feeee..b10a084 100644 --- a/tatu/db/models.py +++ b/tatu/db/models.py @@ -10,13 +10,13 @@ # License for the specific language governing permissions and limitations # under the License. +from Crypto.PublicKey import RSA +from datetime import datetime import falcon import sqlalchemy as sa -import sshpubkeys - from Crypto.PublicKey import RSA -from datetime import datetime from sqlalchemy.exc import IntegrityError from sqlalchemy.ext.declarative import declarative_base +import sshpubkeys from tatu.castellano import get_secret, store_secret from tatu.utils import generateCert, random_uuid diff --git a/tatu/db/persistence.py b/tatu/db/persistence.py index 248c128..1ee41df 100644 --- a/tatu/db/persistence.py +++ b/tatu/db/persistence.py @@ -23,9 +23,6 @@ def get_url(): class SQLAlchemySessionManager(object): - """ - Create scoped session for every request and close it when the request ends - """ def __init__(self): self.engine = create_engine(get_url()) @@ -33,10 +30,12 @@ class SQLAlchemySessionManager(object): self.Session = scoped_session(sessionmaker(self.engine)) def process_resource(self, req, resp, resource, params): + # Create a scoped session for every request resource.session = self.Session() def process_response(self, req, resp, resource, req_succeeded): if hasattr(resource, 'session'): if not req_succeeded: resource.session.rollback() + # Close the scoped session when the request ends self.Session.remove() diff --git a/tatu/ftests/test_api.py b/tatu/ftests/test_api.py index 01a4722..8fd241a 100644 --- a/tatu/ftests/test_api.py +++ b/tatu/ftests/test_api.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. +from Crypto.PublicKey import RSA import json import requests import sshpubkeys import uuid -from Crypto.PublicKey import RSA from tatu.utils import random_uuid diff --git a/tatu/notifications.py b/tatu/notifications.py index 68cf564..0351953 100644 --- a/tatu/notifications.py +++ b/tatu/notifications.py @@ -10,15 +10,15 @@ # License for the specific language governing permissions and limitations # under the License. -import oslo_messaging -import sys -import time -import uuid from oslo_config import cfg from oslo_log import log as logging +import oslo_messaging from oslo_serialization import jsonutils from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker +import sys +import time +import uuid from tatu.db.models import createAuthority from tatu.db.persistence import get_url @@ -65,7 +65,7 @@ class NotificationEndpoint(object): def main(): logging.register_options(CONF) log_levels = logging.get_default_log_levels() + \ - ['tatu=DEBUG', '__main__=DEBUG'] + ['tatu=DEBUG', '__main__=DEBUG'] logging.set_defaults(default_log_levels=log_levels) logging.setup(CONF, DOMAIN) diff --git a/tatu/tests/test_app.py b/tatu/tests/test_app.py index ede76fd..a5a6ee0 100644 --- a/tatu/tests/test_app.py +++ b/tatu/tests/test_app.py @@ -9,14 +9,15 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +from Crypto.PublicKey import RSA import falcon +from falcon import testing import json import pytest import sshpubkeys import time import uuid -from Crypto.PublicKey import RSA -from falcon import testing from tatu.api.app import create_app from tatu.db.persistence import SQLAlchemySessionManager diff --git a/tatu/utils.py b/tatu/utils.py index 4161178..4ece9a5 100644 --- a/tatu/utils.py +++ b/tatu/utils.py @@ -12,6 +12,7 @@ import os import subprocess +from tempfile import NamedTemporaryFile import uuid @@ -46,8 +47,6 @@ def generateCert(auth_key, entity_key, hostname=None, principals='root'): cert = '' with open(cert_file, 'r') as text_file: cert = text_file.read() - #except Exception as e: - # print e finally: # Delete temporary files for file in [ca_file, pub_file, cert_file]: diff --git a/tox.ini b/tox.ini index ea58070..a16642e 100644 --- a/tox.ini +++ b/tox.ini @@ -33,12 +33,16 @@ commands = python setup.py testr --coverage --testr-args='{posargs}' coverage report +[testenv:bandit] +# Skip B104 hardcoded_bind_all_interfaces +deps = -r{toxinidir}/test-requirements.txt +commands = bandit -r tatu -n5 -x tests -ll -s B104 + [flake8] # Following checks are ignored on purpose. -# +# H301 one import per line # E251 unexpected spaces around keyword / parameter equals -# reason: no improvement in readability -ignore = E251,D100,D101,D102,D202,D208 +ignore = E251,D100,D101,D102,D202,D208,H301 exclude = .git,.venv,.tox,dist,tools,doc,*egg,build max-complexity=30 @@ -48,7 +52,3 @@ deps = pylint commands = pylint --rcfile=pylintrc --output-format=colorized - -[hacking] -import_exceptions = dragonflow._i18n -local-check-factory = neutron_lib.hacking.checks.factory \ No newline at end of file