summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-09-29 11:20:38 -0400
committerSimo Sorce <simo@redhat.com>2015-10-19 12:16:52 -0400
commit5fceed2d9be1001fc486d801e0a0f923d8dd3159 (patch)
treefc51762aa859135a1ebdaa9e96c95b25a847991c
parent18178ce292ae2f88528c7e6256c9956ec9ebf896 (diff)
downloadcustodia-5fceed2d9be1001fc486d801e0a0f923d8dd3159.tar.gz
custodia-5fceed2d9be1001fc486d801e0a0f923d8dd3159.tar.xz
custodia-5fceed2d9be1001fc486d801e0a0f923d8dd3159.zip
Make tox pep8 happy
Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Christian Heimes <cheimes@redhat.com>
-rw-r--r--Makefile6
-rw-r--r--custodia/httpd/server.py19
-rw-r--r--custodia/log.py4
-rw-r--r--custodia/message/formats.py4
-rw-r--r--custodia/message/kem.py50
-rw-r--r--custodia/message/simple.py6
-rw-r--r--custodia/root.py3
-rw-r--r--custodia/secrets.py24
-rw-r--r--custodia/store/enclite.py20
-rw-r--r--custodia/store/sqlite.py10
-rwxr-xr-xsetup.py25
-rw-r--r--tests/custodia.py10
-rw-r--r--tests/tests.py10
13 files changed, 100 insertions, 91 deletions
diff --git a/Makefile b/Makefile
index 9f8fe96..dc5291f 100644
--- a/Makefile
+++ b/Makefile
@@ -11,10 +11,6 @@ lint:
--disable=star-args \
./custodia
-pep8:
- # Check style consistency
- pep8 custodia
-
clean:
rm -fr build dist *.egg-info
find ./ -name '*.pyc' -exec rm -f {} \;
@@ -27,8 +23,8 @@ test:
--notes= \
--disable=star-args \
./tests
- pep8 tests
rm -f .coverage
+ tox -epep8
tox
DOCS_DIR = docs
diff --git a/custodia/httpd/server.py b/custodia/httpd/server.py
index 949c00b..8bd71e2 100644
--- a/custodia/httpd/server.py
+++ b/custodia/httpd/server.py
@@ -1,5 +1,13 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
+import errno
+import os
+import shutil
+import socket
+import struct
+
+import six
+
try:
# pylint: disable=import-error
from BaseHTTPServer import BaseHTTPRequestHandler
@@ -11,17 +19,12 @@ except ImportError:
from http.server import BaseHTTPRequestHandler
from socketserver import ForkingMixIn, UnixStreamServer
from urllib.parse import urlparse, parse_qs, unquote
-from custodia.log import stacktrace
+
from custodia.log import debug as log_debug
-import os
-import shutil
-import six
-import socket
-import struct
-import errno
+from custodia.log import stacktrace
SO_PEERCRED = 17
-MAX_REQUEST_SIZE = 10*1024*1024 # For now limit body to 10MiB
+MAX_REQUEST_SIZE = 10 * 1024 * 1024 # For now limit body to 10MiB
class HTTPError(Exception):
diff --git a/custodia/log.py b/custodia/log.py
index 3f258e5..a04288d 100644
--- a/custodia/log.py
+++ b/custodia/log.py
@@ -2,8 +2,8 @@
import io
import sys
-import traceback
import time
+import traceback
DEBUG = False
@@ -54,7 +54,7 @@ AUDIT_MESSAGES = [
]
-class audit_log(object):
+class AuditLog(object):
def __init__(self, config):
if config is None:
diff --git a/custodia/message/formats.py b/custodia/message/formats.py
index 8093ba7..5c4763d 100644
--- a/custodia/message/formats.py
+++ b/custodia/message/formats.py
@@ -1,10 +1,10 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
from custodia.message.common import InvalidMessage
-from custodia.message.common import UnknownMessageType
from custodia.message.common import UnallowedMessage
-from custodia.message.simple import SimpleKey
+from custodia.message.common import UnknownMessageType
from custodia.message.kem import KEMHandler
+from custodia.message.simple import SimpleKey
default_types = ['simple', 'kem']
diff --git a/custodia/message/kem.py b/custodia/message/kem.py
index c1bd31f..6001f49 100644
--- a/custodia/message/kem.py
+++ b/custodia/message/kem.py
@@ -1,17 +1,21 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
-from custodia.httpd.authorizers import SimplePathAuthz
-from custodia.message.common import InvalidMessage
-from custodia.message.common import MessageHandler
-from custodia import log
+import os
+import time
+import unittest
+
from jwcrypto.common import json_decode
from jwcrypto.common import json_encode
from jwcrypto.jwe import JWE
from jwcrypto.jwk import JWK
from jwcrypto.jws import JWS
from jwcrypto.jwt import JWT
-import os
-import time
+
+from custodia import log
+from custodia.httpd.authorizers import SimplePathAuthz
+from custodia.message.common import InvalidMessage
+from custodia.message.common import MessageHandler
+from custodia.store.sqlite import SqliteStore
KEY_USAGE_SIG = 0
@@ -212,11 +216,11 @@ class KEMClient(object):
self.server_keys[KEY_USAGE_ENC], encalg)
def parse_reply(self, name, message):
- E = JWT(jwt=message,
- key=self.client_keys[KEY_USAGE_ENC])
- S = JWT(jwt=E.claims,
- key=self.server_keys[KEY_USAGE_SIG])
- claims = json_decode(S.claims)
+ jwe = JWT(jwt=message,
+ key=self.client_keys[KEY_USAGE_ENC])
+ jws = JWT(jwt=jwe.claims,
+ key=self.server_keys[KEY_USAGE_SIG])
+ claims = json_decode(jws.claims)
check_kem_claims(claims, name)
return claims['value']
@@ -226,24 +230,20 @@ def make_sig_kem(name, value, key, alg):
claims = {'sub': name, 'exp': int(time.time() + (5 * 60))}
if value is not None:
claims['value'] = value
- S = JWT(header, claims)
- S.make_signed_token(key)
- return S.serialize(compact=True)
+ jwt = JWT(header, claims)
+ jwt.make_signed_token(key)
+ return jwt.serialize(compact=True)
def make_enc_kem(name, value, sig_key, alg, enc_key, enc):
plaintext = make_sig_kem(name, value, sig_key, alg)
eprot = {'kid': enc_key.key_id, 'alg': enc[0], 'enc': enc[1]}
- E = JWE(plaintext, json_encode(eprot))
- E.add_recipient(enc_key)
- return E.serialize(compact=True)
+ jwe = JWE(plaintext, json_encode(eprot))
+ jwe.add_recipient(enc_key)
+ return jwe.serialize(compact=True)
# unit tests
-import unittest
-from custodia.store.sqlite import SqliteStore
-
-
test_keys = ({
"kty": "RSA",
"kid": "65d64463-7448-499e-8acc-55db2ce67039",
@@ -346,7 +346,7 @@ class KEMTests(unittest.TestCase):
_store_keys(cls.kk.store, KEY_USAGE_ENC, cls.client_keys)
@classmethod
- def tearDownClass(self):
+ def tearDownClass(cls):
try:
os.unlink('kemtests.db')
except OSError:
@@ -359,9 +359,9 @@ class KEMTests(unittest.TestCase):
"alg": alg}
plaintext = {"sub": name,
"exp": int(time.time()) + (5 * 60)}
- S = JWS(payload=json_encode(plaintext))
- S.add_signature(pri_key, None, json_encode(protected))
- return S.serialize()
+ jws = JWS(payload=json_encode(plaintext))
+ jws.add_signature(pri_key, None, json_encode(protected))
+ return jws.serialize()
def test_1_Parse_GET(self):
cli_skey = JWK(**self.client_keys[0])
diff --git a/custodia/message/simple.py b/custodia/message/simple.py
index 1df1310..7186d12 100644
--- a/custodia/message/simple.py
+++ b/custodia/message/simple.py
@@ -1,9 +1,11 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
+import json
+
+from six import string_types
+
from custodia.message.common import InvalidMessage
from custodia.message.common import MessageHandler
-from six import string_types
-import json
class SimpleKey(MessageHandler):
diff --git a/custodia/root.py b/custodia/root.py
index 4cde152..aba49c3 100644
--- a/custodia/root.py
+++ b/custodia/root.py
@@ -1,8 +1,9 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
+import json
+
from custodia.httpd.consumer import HTTPConsumer
from custodia.secrets import Secrets
-import json
class Root(HTTPConsumer):
diff --git a/custodia/secrets.py b/custodia/secrets.py
index 9f894a8..558bc39 100644
--- a/custodia/secrets.py
+++ b/custodia/secrets.py
@@ -1,16 +1,19 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
+import json
+import os
+import unittest
+
+from custodia import log
+from custodia.httpd.authorizers import HTTPAuthorizer
from custodia.httpd.consumer import HTTPConsumer
from custodia.httpd.server import HTTPError
-from custodia.httpd.authorizers import HTTPAuthorizer
-from custodia.message.formats import Validator
-from custodia.message.common import UnknownMessageType
from custodia.message.common import UnallowedMessage
+from custodia.message.common import UnknownMessageType
+from custodia.message.formats import Validator
from custodia.store.interface import CSStoreError
from custodia.store.interface import CSStoreExists
-from custodia import log
-import json
-import os
+from custodia.store.sqlite import SqliteStore
class Namespaces(HTTPAuthorizer):
@@ -50,7 +53,7 @@ class Secrets(HTTPConsumer):
kt = self.config['allowed_keytypes'].split()
self.allowed_keytypes = kt
self._validator = Validator(self.allowed_keytypes)
- self._auditlog = log.audit_log(self.config)
+ self._auditlog = log.AuditLog(self.config)
def _db_key(self, trail):
if len(trail) < 2:
@@ -282,11 +285,8 @@ class Secrets(HTTPConsumer):
response['code'] = 204
-# unit tests
-import unittest
-from custodia.store.sqlite import SqliteStore
-
+# unit tests
class SecretsTests(unittest.TestCase):
@classmethod
@@ -296,7 +296,7 @@ class SecretsTests(unittest.TestCase):
cls.authz = Namespaces({})
@classmethod
- def tearDownClass(self):
+ def tearDownClass(cls):
try:
os.unlink('test.audit.log')
os.unlink('testdb.sqlite')
diff --git a/custodia/store/enclite.py b/custodia/store/enclite.py
index c22f537..3f88d6b 100644
--- a/custodia/store/enclite.py
+++ b/custodia/store/enclite.py
@@ -1,8 +1,10 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
-from custodia.store.sqlite import SqliteStore
from jwcrypto.common import json_decode, json_encode
-from jwcrypto import jwk, jwe
+from jwcrypto.jwe import JWE
+from jwcrypto.jwk import JWK
+
+from custodia.store.sqlite import SqliteStore
class EncryptedStore(SqliteStore):
@@ -17,7 +19,7 @@ class EncryptedStore(SqliteStore):
with open(config['master_key']) as f:
data = f.read()
key = json_decode(data)
- self.mkey = jwk.JWK(**key)
+ self.mkey = JWK(**key)
if 'master_enctype' in config:
self.enc = config['master_enctype']
@@ -26,12 +28,12 @@ class EncryptedStore(SqliteStore):
def get(self, key):
value = super(EncryptedStore, self).get(key)
- E = jwe.JWE()
- E.deserialize(value, self.mkey)
- return E.payload.decode('utf-8')
+ jwe = JWE()
+ jwe.deserialize(value, self.mkey)
+ return jwe.payload.decode('utf-8')
def set(self, key, value, replace=False):
- E = jwe.JWE(value, json_encode({'alg': 'dir', 'enc': self.enc}))
- E.add_recipient(self.mkey)
- cvalue = E.serialize(compact=True)
+ jwe = JWE(value, json_encode({'alg': 'dir', 'enc': self.enc}))
+ jwe.add_recipient(self.mkey)
+ cvalue = jwe.serialize(compact=True)
return super(EncryptedStore, self).set(key, cvalue, replace)
diff --git a/custodia/store/sqlite.py b/custodia/store/sqlite.py
index e96848f..44d139f 100644
--- a/custodia/store/sqlite.py
+++ b/custodia/store/sqlite.py
@@ -1,10 +1,13 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
from __future__ import print_function
-from custodia.store.interface import CSStore, CSStoreError, CSStoreExists
+
import os
import sqlite3
import sys
+import unittest
+
+from custodia.store.interface import CSStore, CSStoreError, CSStoreExists
def log_error(error):
@@ -104,9 +107,6 @@ class SqliteStore(CSStore):
return False
-import unittest
-
-
class SqliteStoreTests(unittest.TestCase):
@classmethod
@@ -114,7 +114,7 @@ class SqliteStoreTests(unittest.TestCase):
cls.store = SqliteStore({'dburi': 'testdbstore.sqlite'})
@classmethod
- def tearDownClass(self):
+ def tearDownClass(cls):
try:
os.unlink('testdbstore.sqlite')
except OSError:
diff --git a/setup.py b/setup.py
index 892048d..666227d 100755
--- a/setup.py
+++ b/setup.py
@@ -5,18 +5,17 @@
from distutils.core import setup
setup(
- name = 'custodia',
- version = '0.1.0',
- license = 'GPLv3+',
- maintainer = 'Custodia project Contributors',
- maintainer_email = 'simo@redhat.com',
+ name='custodia',
+ version='0.1.0',
+ license='GPLv3+',
+ maintainer='Custodia project Contributors',
+ maintainer_email='simo@redhat.com',
url='https://github.com/simo5/custodia',
- packages = ['custodia', 'custodia.httpd', 'custodia.store',
- 'custodia.message', 'tests'],
- data_files = [('share/man/man7', ["man/custodia.7"]),
- ('share/doc/custodia', ['LICENSE', 'README', 'API.md']),
- ('share/doc/custodia/examples', ['custodia.conf']),
- ],
- scripts = ['custodia/custodia']
+ packages=['custodia', 'custodia.httpd', 'custodia.store',
+ 'custodia.message', 'tests'],
+ data_files=[('share/man/man7', ["man/custodia.7"]),
+ ('share/doc/custodia', ['LICENSE', 'README', 'API.md']),
+ ('share/doc/custodia/examples', ['custodia.conf']),
+ ],
+ scripts=['custodia/custodia']
)
-
diff --git a/tests/custodia.py b/tests/custodia.py
index e14f091..f536dc3 100644
--- a/tests/custodia.py
+++ b/tests/custodia.py
@@ -1,13 +1,15 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
from __future__ import absolute_import
-from tests.client import LocalConnection
+
import json
import os
import subprocess
import time
import unittest
+from tests.client import LocalConnection
+
class CustodiaTests(unittest.TestCase):
@@ -25,9 +27,9 @@ class CustodiaTests(unittest.TestCase):
'Content-Type': 'application/json'}
@classmethod
- def tearDownClass(self):
- self.custodia_process.kill()
- self.custodia_process.wait()
+ def tearDownClass(cls):
+ cls.custodia_process.kill()
+ cls.custodia_process.wait()
for fname in ['server_socket', 'secrets.db']:
try:
os.unlink(fname)
diff --git a/tests/tests.py b/tests/tests.py
index 5a2837e..02a3268 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -1,9 +1,13 @@
from __future__ import absolute_import
+
+import unittest
+
+from tests.custodia import CustodiaTests
+
+from custodia.message.kem import KEMTests
from custodia.secrets import SecretsTests
from custodia.store.sqlite import SqliteStoreTests
-from custodia.message.kem import KEMTests
-from tests.custodia import CustodiaTests
-import unittest
+
if __name__ == '__main__':
testLoad = unittest.TestLoader()