summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2016-01-15 13:51:13 +0100
committerChristian Heimes <cheimes@redhat.com>2016-01-25 15:55:53 +0100
commitcb6b0c4855885c03d056acb8f98c96de986e081e (patch)
treed622bc6e4e2ef9e4b4fcb46b8b70e80f6b0b17af
parent0d2d97f9bf6802f6f81090eca6e135e50fea7883 (diff)
downloadpki-cb6b0c4855885c03d056acb8f98c96de986e081e.tar.gz
pki-cb6b0c4855885c03d056acb8f98c96de986e081e.tar.xz
pki-cb6b0c4855885c03d056acb8f98c96de986e081e.zip
Fix flake8 / PEP 8 violations
https://fedorahosted.org/pki/ticket/1738
-rw-r--r--base/common/python/pki/nssdb.py56
-rw-r--r--base/kra/functional/drmclient_deprecated.py11
-rw-r--r--base/server/python/pki/server/__init__.py2
-rw-r--r--base/server/python/pki/server/cli/nuxwdog.py6
-rw-r--r--base/server/python/pki/server/cli/subsystem.py2
-rw-r--r--base/server/python/pki/server/deployment/pkihelper.py32
-rw-r--r--base/server/python/pki/server/deployment/scriptlets/configuration.py12
-rw-r--r--base/server/python/pki/server/deployment/scriptlets/selinux_setup.py12
-rwxr-xr-xbase/server/upgrade/10.3.0/01-AllowEncodedSlash1
-rw-r--r--tests/python/test_authority.py5
-rw-r--r--tests/python/test_pki.py2
-rw-r--r--tox.ini2
12 files changed, 62 insertions, 81 deletions
diff --git a/base/common/python/pki/nssdb.py b/base/common/python/pki/nssdb.py
index 44e286853..c6beab317 100644
--- a/base/common/python/pki/nssdb.py
+++ b/base/common/python/pki/nssdb.py
@@ -18,6 +18,7 @@
# All rights reserved.
#
+from __future__ import absolute_import
import base64
import os
import shutil
@@ -36,7 +37,6 @@ PKCS7_FOOTER = '-----END PKCS7-----'
def convert_data(data, input_format, output_format, header=None, footer=None):
-
if input_format == output_format:
return data
@@ -46,7 +46,7 @@ def convert_data(data, input_format, output_format, header=None, footer=None):
data = data.replace('\r', '').replace('\n', '')
# re-split the line into fixed-length lines
- lines = [data[i:i+64] for i in range(0, len(data), 64)]
+ lines = [data[i:i + 64] for i in range(0, len(data), 64)]
# add header and footer
return '%s\n%s\n%s\n' % (header, '\n'.join(lines), footer)
@@ -67,20 +67,20 @@ def convert_data(data, input_format, output_format, header=None, footer=None):
raise Exception('Unable to convert data from %s to %s' % (input_format, output_format))
-def convert_csr(csr_data, input_format, output_format):
+def convert_csr(csr_data, input_format, output_format):
return convert_data(csr_data, input_format, output_format, CSR_HEADER, CSR_FOOTER)
-def convert_cert(cert_data, input_format, output_format):
+def convert_cert(cert_data, input_format, output_format):
return convert_data(cert_data, input_format, output_format, CERT_HEADER, CERT_FOOTER)
-def convert_pkcs7(pkcs7_data, input_format, output_format):
+def convert_pkcs7(pkcs7_data, input_format, output_format):
return convert_data(pkcs7_data, input_format, output_format, PKCS7_HEADER, PKCS7_FOOTER)
-def get_file_type(filename):
+def get_file_type(filename):
with open(filename, 'r') as f:
data = f.read()
@@ -118,11 +118,7 @@ class NSSDatabase(object):
def close(self):
shutil.rmtree(self.tmpdir)
- def add_cert(self,
- nickname,
- cert_file,
- trust_attributes=',,'):
-
+ def add_cert(self, nickname, cert_file, trust_attributes=',,'):
cmd = [
'certutil',
'-A',
@@ -136,10 +132,7 @@ class NSSDatabase(object):
subprocess.check_call(cmd)
- def modify_cert(self,
- nickname,
- trust_attributes):
-
+ def modify_cert(self, nickname, trust_attributes):
cmd = [
'certutil',
'-M',
@@ -153,7 +146,6 @@ class NSSDatabase(object):
subprocess.check_call(cmd)
def create_noise(self, noise_file, size=2048):
-
subprocess.check_call([
'openssl',
'rand',
@@ -161,15 +153,9 @@ class NSSDatabase(object):
str(size)
])
- def create_request(self,
- subject_dn,
- request_file,
- noise_file=None,
- key_type=None,
- key_size=None,
- curve=None,
- hash_alg=None):
-
+ def create_request(self, subject_dn, request_file, noise_file=None,
+ key_type=None, key_size=None, curve=None,
+ hash_alg=None):
tmpdir = tempfile.mkdtemp()
try:
@@ -229,12 +215,8 @@ class NSSDatabase(object):
finally:
shutil.rmtree(tmpdir)
- def create_self_signed_ca_cert(self,
- subject_dn,
- request_file,
- cert_file,
- serial='1',
- validity=240):
+ def create_self_signed_ca_cert(self, subject_dn, request_file, cert_file,
+ serial='1', validity=240):
cmd = [
'certutil',
@@ -256,7 +238,8 @@ class NSSDatabase(object):
'--extAIA'
]
- p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
keystroke = ''
@@ -367,7 +350,7 @@ class NSSDatabase(object):
try:
file_type = get_file_type(cert_chain_file)
- if file_type == 'cert': # import single PEM cert
+ if file_type == 'cert': # import single PEM cert
self.add_cert(
nickname=nickname,
cert_file=cert_chain_file,
@@ -376,14 +359,14 @@ class NSSDatabase(object):
nickname=nickname,
output_format='base64')
- elif file_type == 'pkcs7': # import PKCS #7 cert chain
+ elif file_type == 'pkcs7': # import PKCS #7 cert chain
return self.import_pkcs7(
pkcs7_file=cert_chain_file,
nickname=nickname,
trust_attributes=trust_attributes,
output_format='base64')
- else: # import PKCS #7 data without header/footer
+ else: # import PKCS #7 data without header/footer
with open(cert_chain_file, 'r') as f:
base64_data = f.read()
pkcs7_data = convert_pkcs7(base64_data, 'base64', 'pem')
@@ -501,7 +484,8 @@ class NSSDatabase(object):
finally:
shutil.rmtree(tmpdir)
- def export_pkcs12(self, pkcs12_file, nickname, pkcs12_password=None, pkcs12_password_file=None):
+ def export_pkcs12(self, pkcs12_file, nickname, pkcs12_password=None,
+ pkcs12_password_file=None):
tmpdir = tempfile.mkdtemp()
diff --git a/base/kra/functional/drmclient_deprecated.py b/base/kra/functional/drmclient_deprecated.py
index 6d06d7405..e33391321 100644
--- a/base/kra/functional/drmclient_deprecated.py
+++ b/base/kra/functional/drmclient_deprecated.py
@@ -41,6 +41,8 @@ import nss.nss as nss
from ipapython import nsslib, ipautil
from nss.error import NSPRError
from ipalib.errors import NetworkError, CertificateOperationError
+import argparse
+from base64 import b64decode, b64encode
from urllib import urlencode, quote_plus
from datetime import datetime
import logging
@@ -51,9 +53,6 @@ CERT_HEADER = "-----BEGIN NEW CERTIFICATE REQUEST-----"
CERT_FOOTER = "-----END NEW CERTIFICATE REQUEST-----"
-from base64 import b64decode, b64encode
-
-
def _(string):
return string
@@ -444,8 +443,8 @@ class KRA:
try:
nss.nss_init(self.sec_dir)
except Exception as e:
- raise CertificateOperationError(error=_('Error in initializing certdb (%s)')
- + e.strerror)
+ raise CertificateOperationError(
+ error=_('Error in initializing certdb (%s)') % e.strerror)
self.transport_cert = nss.find_cert_from_nickname(
self.transport_cert_nickname)
@@ -1010,8 +1009,6 @@ class KRA:
pass
""" Sample Test execution starts here """
-import argparse
-
parser = argparse.ArgumentParser(description="Sample Test execution")
parser.add_argument(
'-d',
diff --git a/base/server/python/pki/server/__init__.py b/base/server/python/pki/server/__init__.py
index 604a56e7a..cb246aaa1 100644
--- a/base/server/python/pki/server/__init__.py
+++ b/base/server/python/pki/server/__init__.py
@@ -467,7 +467,7 @@ class PKIServerException(pki.PKIException):
class Tomcat(object):
@classmethod
- def get_major_version(self):
+ def get_major_version(cls):
# run "tomcat version"
output = subprocess.check_output(['/usr/sbin/tomcat', 'version'])
diff --git a/base/server/python/pki/server/cli/nuxwdog.py b/base/server/python/pki/server/cli/nuxwdog.py
index ca9c7c39b..afbd438ff 100644
--- a/base/server/python/pki/server/cli/nuxwdog.py
+++ b/base/server/python/pki/server/cli/nuxwdog.py
@@ -222,8 +222,7 @@ class NuxwdogEnableCLI(pki.cli.CLI):
'/etc/systemd/system/pki-tomcatd.target.wants',
old_systemd_unit_file)
- new_systemd_unit_file = ('pki-tomcatd-nuxwdog@' + instance.name
- + '.service')
+ new_systemd_unit_file = 'pki-tomcatd-nuxwdog@%s.service' % instance.name
new_systemd_link = os.path.join(
'/etc/systemd/system/pki-tomcatd-nuxwdog.target.wants',
new_systemd_unit_file)
@@ -373,8 +372,7 @@ class NuxwdogDisableCLI(pki.cli.CLI):
os.chown(filename, instance.uid, instance.gid)
def change_systemd_links(self, instance):
- old_systemd_unit_file = ('pki-tomcatd-nuxwdog@' + instance.name
- + '.service')
+ old_systemd_unit_file = 'pki-tomcatd-nuxwdog@%s.service' % instance.name
old_systemd_link = os.path.join(
'/etc/systemd/system/pki-tomcatd-nuxwdog.target.wants',
old_systemd_unit_file)
diff --git a/base/server/python/pki/server/cli/subsystem.py b/base/server/python/pki/server/cli/subsystem.py
index 1be91b10e..f0e38b65e 100644
--- a/base/server/python/pki/server/cli/subsystem.py
+++ b/base/server/python/pki/server/cli/subsystem.py
@@ -448,7 +448,7 @@ class SubsystemCertExportCLI(pki.cli.CLI):
super(SubsystemCertExportCLI, self).__init__(
'export', 'Export subsystem certificate')
- def usage(self):
+ def usage(self): # flake8: noqa
print('Usage: pki-server subsystem-cert-export [OPTIONS] <subsystem ID> <cert ID>')
print()
print(' -i, --instance <instance ID> Instance ID (default: pki-tomcat).')
diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py
index c5c71ef99..0f5485a46 100644
--- a/base/server/python/pki/server/deployment/pkihelper.py
+++ b/base/server/python/pki/server/deployment/pkihelper.py
@@ -43,8 +43,18 @@ from pwd import getpwuid
import xml.etree.ElementTree as ET
from lxml import etree
import zipfile
-import selinux
+# PKI Deployment Imports
+from . import pkiconfig as config
+from .pkiconfig import pki_selinux_config_ports as ports
+from . import pkimanifest as manifest
+from . import pkimessages as log
+from .pkiparser import PKIConfigParser
+import pki.client
+import pki.system
+
+# special care for SELinux
+import selinux
seobject = None
if selinux.is_selinux_enabled():
try:
@@ -56,16 +66,6 @@ if selinux.is_selinux_enabled():
raise
-# PKI Deployment Imports
-from . import pkiconfig as config
-from .pkiconfig import pki_selinux_config_ports as ports
-from . import pkimanifest as manifest
-from . import pkimessages as log
-from .pkiparser import PKIConfigParser
-import pki.client
-import pki.system
-
-
# PKI Deployment Helper Functions
def pki_copytree(src, dst, symlinks=False, ignore=None):
"""Recursively copy a directory tree using copy2().
@@ -3908,8 +3908,8 @@ class ConfigClient:
message = root.findall('.//Message')[0].text
if message is not None:
config.pki_log.error(
- log.PKI_CONFIG_JAVA_CONFIGURATION_EXCEPTION + " "
- + message,
+ log.PKI_CONFIG_JAVA_CONFIGURATION_EXCEPTION + " " +
+ message,
extra=config.PKI_INDENTATION_LEVEL_2)
raise
@@ -4125,7 +4125,8 @@ class ConfigClient:
cert1.req_ext_data = \
self.mdict['pki_req_ext_data']
- if self.external and self.external_step_two: # external/existing CA step 2
+ if self.external and self.external_step_two:
+ # external/existing CA step 2
# If specified, load the externally-signed CA cert
if self.mdict['pki_external_ca_cert_path']:
@@ -4143,7 +4144,8 @@ class ConfigClient:
systemCerts.append(cert1)
- elif self.standalone and self.external_step_two: # standalone KRA/OCSP step 2
+ elif self.standalone and self.external_step_two:
+ # standalone KRA/OCSP step 2
cert1 = pki.system.SystemCertData()
cert1.tag = self.mdict['pki_ca_signing_tag']
diff --git a/base/server/python/pki/server/deployment/scriptlets/configuration.py b/base/server/python/pki/server/deployment/scriptlets/configuration.py
index 5ec46c86f..7ecb4d76f 100644
--- a/base/server/python/pki/server/deployment/scriptlets/configuration.py
+++ b/base/server/python/pki/server/deployment/scriptlets/configuration.py
@@ -99,7 +99,7 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
external_csr_path = deployer.configuration_file.external_csr_path
try:
- if external and step_one: # external/existing CA step 1
+ if external and step_one: # external/existing CA step 1
key_type = deployer.mdict['pki_ca_signing_key_type']
key_alg = deployer.mdict['pki_ca_signing_key_algorithm']
@@ -147,7 +147,7 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
subsystem.save()
- elif external and step_two: # external/existing CA step 2
+ elif external and step_two: # external/existing CA step 2
# If specified, import existing CA cert request into CS.cfg.
if external_csr_path:
@@ -157,7 +157,8 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
subsystem.config['ca.signing.certreq'] = signing_csr
# If specified, import external CA cert into NSS database.
- external_ca_cert_chain_nickname = deployer.mdict['pki_external_ca_cert_chain_nickname']
+ external_ca_cert_chain_nickname = \
+ deployer.mdict['pki_external_ca_cert_chain_nickname']
external_ca_cert_chain_file = deployer.mdict['pki_external_ca_cert_chain_path']
if external_ca_cert_chain_file:
cert_chain = nssdb.import_cert_chain(
@@ -189,11 +190,12 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
subsystem.config['ca.signing.tokenname'] = deployer.mdict['pki_ca_signing_token']
subsystem.config['ca.signing.cert'] = signing_cert_data
subsystem.config['ca.signing.cacertnickname'] = signing_nickname
- subsystem.config['ca.signing.defaultSigningAlgorithm'] = deployer.mdict['pki_ca_signing_signing_algorithm']
+ subsystem.config['ca.signing.defaultSigningAlgorithm'] = \
+ deployer.mdict['pki_ca_signing_signing_algorithm']
subsystem.save()
- else: # self-signed CA
+ else: # self-signed CA
# To be implemented in ticket #1692.
diff --git a/base/server/python/pki/server/deployment/scriptlets/selinux_setup.py b/base/server/python/pki/server/deployment/scriptlets/selinux_setup.py
index cff6acf31..c559370a5 100644
--- a/base/server/python/pki/server/deployment/scriptlets/selinux_setup.py
+++ b/base/server/python/pki/server/deployment/scriptlets/selinux_setup.py
@@ -23,6 +23,12 @@ import selinux
import sys
import time
+# PKI Deployment Imports
+from .. import pkiconfig as config
+from ..pkiconfig import pki_selinux_config_ports as ports
+from .. import pkimessages as log
+from .. import pkiscriptlet
+
seobject = None
if selinux.is_selinux_enabled():
try:
@@ -33,12 +39,6 @@ if selinux.is_selinux_enabled():
if sys.version_info.major == 2:
raise
-# PKI Deployment Imports
-from .. import pkiconfig as config
-from ..pkiconfig import pki_selinux_config_ports as ports
-from .. import pkimessages as log
-from .. import pkiscriptlet
-
# PKI Deployment Selinux Setup Scriptlet
class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
diff --git a/base/server/upgrade/10.3.0/01-AllowEncodedSlash b/base/server/upgrade/10.3.0/01-AllowEncodedSlash
index 3225d3a7e..281f94ea6 100755
--- a/base/server/upgrade/10.3.0/01-AllowEncodedSlash
+++ b/base/server/upgrade/10.3.0/01-AllowEncodedSlash
@@ -22,6 +22,7 @@ from __future__ import absolute_import
import os.path
import pki.server.upgrade
+
class AllowEncodedSlash(pki.server.upgrade.PKIServerUpgradeScriptlet):
def __init__(self):
diff --git a/tests/python/test_authority.py b/tests/python/test_authority.py
index f48b9deb9..b25816c23 100644
--- a/tests/python/test_authority.py
+++ b/tests/python/test_authority.py
@@ -20,7 +20,6 @@
#
import mock
-import requests
import unittest
import uuid
@@ -38,7 +37,7 @@ class AuthorityTests(unittest.TestCase):
self.authority_client = authority.AuthorityClient(self.connection)
self.top_level_aid = str(uuid.uuid4())
self.aid = str(uuid.uuid4())
- self.aid2 = str(uuid.uuid4())
+ self.aid2 = str(uuid.uuid4())
self.dn = "cn=subordinate ca, o=example.com"
self.dn2 = "cn=subordinate ca2, o=example.com"
self.description = "subordinate CA1"
@@ -127,5 +126,3 @@ class AuthorityTests(unittest.TestCase):
self.assertEquals(ca.dn, self.dn2)
else:
self.assertEquals(ca.dn, self.dn)
-
-
diff --git a/tests/python/test_pki.py b/tests/python/test_pki.py
index 606a89232..dcab79947 100644
--- a/tests/python/test_pki.py
+++ b/tests/python/test_pki.py
@@ -33,6 +33,7 @@ class TestHTTPError(requests.exceptions.HTTPError):
self.response._content = body
self.response.encoding = 'utf-8'
+
class PKITests(unittest.TestCase):
def test_handle_exceptions(self):
@@ -78,7 +79,6 @@ class PKITests(unittest.TestCase):
'com.netscape.certsrv.base.BadRequestException'
)
-
with self.assertRaises(TestHTTPError) as e:
raiser(b'no json body')
diff --git a/tox.ini b/tox.ini
index 748e3d0db..4024f1df4 100644
--- a/tox.ini
+++ b/tox.ini
@@ -90,7 +90,7 @@ python_files = tests/python/*.py
[flake8]
ignore = N802,N806,N812
-exclude = .tox,*.egg,dist,build,conf.py,tests/*,.git
+exclude = .tox,*.egg,dist,build,conf.py,tests/dogtag/*,.git
filename = *.py,pki,pkidestroy,pki-upgrade,pki-server,pki-server-upgrade,pkispawn,[0-9][0-9]-*
show-source = true
max-line-length = 99