diff --git a/tatu/api/models.py b/tatu/api/models.py index 0809e30..beba558 100644 --- a/tatu/api/models.py +++ b/tatu/api/models.py @@ -104,7 +104,7 @@ class Authority(object): class UserCerts(object): @falcon.before(validate) def on_post(self, req, resp): - # TODO: validation + # TODO(pino): validation try: user = db.createUserCert( self.session, diff --git a/tatu/db/models.py b/tatu/db/models.py index 89be1f2..06feeee 100644 --- a/tatu/db/models.py +++ b/tatu/db/models.py @@ -11,11 +11,9 @@ # under the License. import falcon -import os import sqlalchemy as sa import sshpubkeys -import uuid -from Crypto.PublicKey import RSA + from Crypto.PublicKey import RSA from datetime import datetime from sqlalchemy.exc import IntegrityError from sqlalchemy.ext.declarative import declarative_base @@ -125,7 +123,7 @@ def createToken(session, host_id, auth_id, hostname): token = session.query(Token).filter(Token.host_id == host_id).one() if token is not None: return token - except: + except Exception: pass token = Token(host_id=host_id, @@ -164,12 +162,12 @@ def createHostCert(session, token_id, host_id, pub): if token.used: if token.fingerprint_used != fingerprint: raise falcon.HTTPConflict( - description='The token was previously used with a different public key') + description='Token already signed a different public key') # The token was already used for same host and pub key. Return record. host = session.query(HostCert).get([host_id, fingerprint]) if host is None: raise falcon.HTTPInternalServerError( - description='The token was used, but no corresponding Host record was found.') + description='Token already used, but Host record not found.') if host.token_id == token_id: return host raise falcon.HTTPConflict( diff --git a/tatu/db/persistence.py b/tatu/db/persistence.py index 861bf90..248c128 100644 --- a/tatu/db/persistence.py +++ b/tatu/db/persistence.py @@ -22,7 +22,7 @@ def get_url(): # return os.getenv("DATABASE_URL", "sqlite:///:memory:") -class SQLAlchemySessionManager: +class SQLAlchemySessionManager(object): """ Create scoped session for every request and close it when the request ends """ diff --git a/tatu/ftests/test_api.py b/tatu/ftests/test_api.py index d5184bd..01a4722 100644 --- a/tatu/ftests/test_api.py +++ b/tatu/ftests/test_api.py @@ -11,7 +11,6 @@ # under the License. import json -import os import requests import sshpubkeys import uuid diff --git a/tatu/notifications.py b/tatu/notifications.py index 9d889da..68cf564 100644 --- a/tatu/notifications.py +++ b/tatu/notifications.py @@ -18,7 +18,7 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils from sqlalchemy import create_engine -from sqlalchemy.orm import sessionmaker, scoped_session +from sqlalchemy.orm import scoped_session, sessionmaker from tatu.db.models import createAuthority from tatu.db.persistence import get_url @@ -64,9 +64,9 @@ class NotificationEndpoint(object): def main(): logging.register_options(CONF) - extra_log_level_defaults = ['tatu=DEBUG', '__main__=DEBUG'] - logging.set_defaults(default_log_levels=logging.get_default_log_levels() + - extra_log_level_defaults) + log_levels = logging.get_default_log_levels() + \ + ['tatu=DEBUG', '__main__=DEBUG'] + logging.set_defaults(default_log_levels=log_levels) logging.setup(CONF, DOMAIN) transport = oslo_messaging.get_notification_transport(CONF) diff --git a/tatu/utils.py b/tatu/utils.py index e5c1d9a..4161178 100644 --- a/tatu/utils.py +++ b/tatu/utils.py @@ -46,14 +46,14 @@ 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 + #except Exception as e: + # print e finally: # Delete temporary files for file in [ca_file, pub_file, cert_file]: try: os.remove(file) pass - except: + except Exception: pass return cert