Skip to content

Commit

Permalink
Fixed pylint report.
Browse files Browse the repository at this point in the history
Previously pylint report was saved it into a file which may not be
accessible on a build system. The pylint-build-scan.sh has been
changed to display the report so it will appear in the build log.

The pylint configuration has also been modified to disable C and R
messages by default. This way when other errors or warnings occur
the build will fail without having to check for specific codes.

Some Python codes have been modified to reduce the number of pylint
warnings.

https://fedorahosted.org/pki/ticket/703
  • Loading branch information
edewata committed Feb 5, 2015
1 parent 8fc5acb commit dfe5598
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 206 deletions.
14 changes: 7 additions & 7 deletions base/common/python/pki/__init__.py
Expand Up @@ -27,10 +27,10 @@
import requests


CONF_DIR = '/etc/pki'
CONF_DIR = '/etc/pki'
SHARE_DIR = '/usr/share/pki'
BASE_DIR = '/var/lib'
LOG_DIR = '/var/log/pki'
BASE_DIR = '/var/lib'
LOG_DIR = '/var/log/pki'

PACKAGE_VERSION = SHARE_DIR + '/VERSION'
CERT_HEADER = "-----BEGIN CERTIFICATE-----"
Expand Down Expand Up @@ -117,7 +117,7 @@ def implementation_version():
raise Exception('Missing implementation version.')


#pylint: disable-msg=R0903
#pylint: disable=R0903
class Attribute(object):
"""
Class representing a key/value pair.
Expand All @@ -131,15 +131,15 @@ def __init__(self, name, value):
self.value = value


#pylint: disable-msg=R0903
#pylint: disable=R0903
class AttributeList(object):
"""
Class representing a list of attributes.
This class is needed because of a JavaMapper used in the REST API.
"""

# pylint: disable-msg=C0103
# pylint: disable=C0103
def __init__(self):
""" Constructor """
self.Attribute = []
Expand All @@ -151,7 +151,7 @@ class ResourceMessage(object):
It is essentially a list of attributes.
"""

# pylint: disable-msg=C0103
# pylint: disable=C0103
def __init__(self, class_name):
""" Constructor """
self.Attributes = AttributeList()
Expand Down
130 changes: 65 additions & 65 deletions base/common/python/pki/cert.py
Expand Up @@ -344,9 +344,9 @@ def __init__(self, **cert_search_params):
setattr(self, CertSearchRequest.search_params[param], value)
setattr(self, 'serialNumberRangeInUse', True)

if param in {
'email', 'common_name', 'user_id', 'org_unit', 'org',
'locality', 'state', 'country', 'match_exactly'
if param in {\
'email', 'common_name', 'user_id', 'org_unit', 'org',\
'locality', 'state', 'country', 'match_exactly'\
}:
setattr(self, CertSearchRequest.search_params[param], value)
setattr(self, 'subjectInUse', True)
Expand Down Expand Up @@ -382,16 +382,16 @@ def __init__(self, **cert_search_params):
setattr(self, CertSearchRequest.search_params[param], value)
setattr(self, 'validNotAfterInUse', True)

if param in {
'validity_operation', 'validity_count', 'validity_unit'
if param in {\
'validity_operation', 'validity_count', 'validity_unit'\
}:
setattr(self, CertSearchRequest.search_params[param], value)
setattr(self, 'validityLengthInUse', True)

if param in {
'cert_type_sub_email_ca', 'cert_type_sub_ssl_ca',
'cert_type_secure_email', 'cert_type_ssl_client',
'cert_type_ssl_server'
if param in {\
'cert_type_sub_email_ca', 'cert_type_sub_ssl_ca',\
'cert_type_secure_email', 'cert_type_ssl_client',\
'cert_type_ssl_server'\
}:
setattr(self, CertSearchRequest.search_params[param], value)
setattr(self, 'certTypeInUse', True)
Expand Down Expand Up @@ -1045,8 +1045,8 @@ def main():
cert_client.get_enrollment_template('caUserCert')

#Enrolling an user certificate
print('Enrolling an user certificate')
print('-----------------------------')
print 'Enrolling an user certificate'
print '-----------------------------'

inputs = dict()
inputs['cert_request_type'] = 'crmf'
Expand All @@ -1072,19 +1072,19 @@ def main():
for enrollment_result in enrollment_results:
request_data = enrollment_result.request
cert_data = enrollment_result.cert
print('Request ID: ' + request_data.request_id)
print('Request Status:' + request_data.request_status)
print('Serial Number: ' + cert_data.serial_number)
print('Issuer: ' + cert_data.issuer_dn)
print('Subject: ' + cert_data.subject_dn)
print('Pretty Print:')
print(cert_data.pretty_repr)
print 'Request ID: ' + request_data.request_id
print 'Request Status:' + request_data.request_status
print 'Serial Number: ' + cert_data.serial_number
print 'Issuer: ' + cert_data.issuer_dn
print 'Subject: ' + cert_data.subject_dn
print 'Pretty Print:'
print cert_data.pretty_repr

print

# Enrolling a server certificate
print("Enrolling a server certificate")
print('------------------------------')
print "Enrolling a server certificate"
print '------------------------------'

inputs = dict()
inputs['cert_request_type'] = 'pkcs10'
Expand All @@ -1109,40 +1109,40 @@ def main():
for enrollment_result in enrollment_results_2:
request_data = enrollment_result.request
cert_data = enrollment_result.cert
print('Request ID: ' + request_data.request_id)
print('Request Status:' + request_data.request_status)
print 'Request ID: ' + request_data.request_id
print 'Request Status:' + request_data.request_status
if cert_data is not None:
# store cert_id for usage later
cert_id = cert_data.serial_number
print('Serial Number: ' + cert_id)
print('Issuer: ' + cert_data.issuer_dn)
print('Subject: ' + cert_data.subject_dn)
print('Pretty Print:')
print(cert_data.pretty_repr)
print 'Serial Number: ' + cert_id
print 'Issuer: ' + cert_data.issuer_dn
print 'Subject: ' + cert_data.subject_dn
print 'Pretty Print:'
print cert_data.pretty_repr

print

# List all the VALID certs
print('An example listing all VALID certs')
print('----------------------------------')
print 'An example listing all VALID certs'
print '----------------------------------'

search_params = {'status': 'VALID'}
cert_data_list = cert_client.list_certs(**search_params)
for cert_data_info in cert_data_list:
print("Serial Number: " + cert_data_info.serial_number)
print("Subject DN: " + cert_data_info.subject_dn)
print("Status: " + cert_data_info.status)
print "Serial Number: " + cert_data_info.serial_number
print "Subject DN: " + cert_data_info.subject_dn
print "Status: " + cert_data_info.status
print

#Trying to get a non-existing cert
#Assuming that there is no certificate with serial number = 100
try:
cert_data = cert_client.get_cert(100)
print('Serial Number: ' + cert_data.serial_number)
print('Issuer: ' + cert_data.issuer_dn)
print('Subject: ' + cert_data.subject_dn)
print 'Serial Number: ' + cert_data.serial_number
print 'Issuer: ' + cert_data.issuer_dn
print 'Subject: ' + cert_data.subject_dn
except pki.CertNotFoundException:
print("Certificate with ID 100 does not exist")
print "Certificate with ID 100 does not exist"
print

# Certificate Serial Number used for CertClient methods.
Expand All @@ -1151,54 +1151,54 @@ def main():
# before.

#Get certificate data
print('Getting information of a certificate')
print('------------------------------------')
print 'Getting information of a certificate'
print '------------------------------------'

cert_data = cert_client.get_cert(cert_id)
# Print the certificate information
print('Serial Number: ' + cert_data.serial_number)
print('Issuer: ' + cert_data.issuer_dn)
print('Subject: ' + cert_data.subject_dn)
print('Status: ' + cert_data.status)
print('Not Before: ' + cert_data.not_before)
print('Not After: ' + cert_data.not_after)
print('Encoded: ')
print(cert_data.encoded)
print("Pretty print format: ")
print(cert_data.pretty_repr)
print 'Serial Number: ' + cert_data.serial_number
print 'Issuer: ' + cert_data.issuer_dn
print 'Subject: ' + cert_data.subject_dn
print 'Status: ' + cert_data.status
print 'Not Before: ' + cert_data.not_before
print 'Not After: ' + cert_data.not_after
print 'Encoded: '
print cert_data.encoded
print "Pretty print format: "
print cert_data.pretty_repr
print

# Review a certificate - used to get a nonce for revoke request.
print('Reviewing a certificate')
print('-----------------------')
print 'Reviewing a certificate'
print '-----------------------'

cert_data = cert_client.review_cert(cert_id)
print('Serial Number: ' + cert_data.serial_number)
print('Issuer: ' + cert_data.issuer_dn)
print('Subject: ' + cert_data.subject_dn)
print('Status: ' + cert_data.status)
print('Nonce: ' + str(cert_data.nonce))
print 'Serial Number: ' + cert_data.serial_number
print 'Issuer: ' + cert_data.issuer_dn
print 'Subject: ' + cert_data.subject_dn
print 'Status: ' + cert_data.status
print 'Nonce: ' + str(cert_data.nonce)
print

#Revoke a certificate
print('Revoking a certificate')
print('----------------------')
print 'Revoking a certificate'
print '----------------------'

cert_request_info = cert_client.hold_cert(cert_data.serial_number,
comments="Test revoking a cert")
print('Request ID: ' + cert_request_info.request_id)
print('Request Type: ' + cert_request_info.request_type)
print('Request Status: ' + cert_request_info.request_status)
print 'Request ID: ' + cert_request_info.request_id
print 'Request Type: ' + cert_request_info.request_type
print 'Request Status: ' + cert_request_info.request_status
print

#Un-revoke a certificate
print('Un-revoking a certificate')
print('-------------------------')
print 'Un-revoking a certificate'
print '-------------------------'

cert_request_info = cert_client.unrevoke_cert(cert_data.serial_number)
print('Request ID: ' + cert_request_info.request_id)
print('Request Type: ' + cert_request_info.request_type)
print('Request Status: ' + cert_request_info.request_status)
print 'Request ID: ' + cert_request_info.request_id
print 'Request Type: ' + cert_request_info.request_type
print 'Request Status: ' + cert_request_info.request_status
print


Expand Down
2 changes: 1 addition & 1 deletion base/common/python/pki/cli.py
Expand Up @@ -124,7 +124,7 @@ def execute(self, args):
# Module doesn't have children. Keep looking.

# If there's no more dashes, stop.
if i<0:
if i < 0:
break

position = i + 1
Expand Down
4 changes: 2 additions & 2 deletions base/common/python/pki/encoder.py
Expand Up @@ -31,7 +31,7 @@ class CustomTypeEncoder(json.JSONEncoder):
http://stackoverflow.com/questions/12949064/python-what-happens-
when-instance-variable-name-is-same-as-method-name
"""
# pylint: disable-msg=E0202
# pylint: disable=E0202
def default(self, obj):
for k, v in TYPES.items():
if isinstance(obj, v):
Expand All @@ -44,7 +44,7 @@ def default(self, obj):
def attr_name_conversion(attr_dict, object_class):
if not hasattr(object_class, 'json_attribute_names'):
return attr_dict
reverse_dict = {v: k for k,v in
reverse_dict = {v: k for k, v in
object_class.json_attribute_names.iteritems()}
new_dict = dict()
for k, v in attr_dict.items():
Expand Down
32 changes: 16 additions & 16 deletions base/common/python/pki/key.py
Expand Up @@ -34,7 +34,7 @@


#should be moved to request.py
#pylint: disable-msg=R0903
#pylint: disable=R0903
class RequestId(object):
"""
Class representing a Request ID
Expand All @@ -45,7 +45,7 @@ def __init__(self, req_id):
self.value = req_id


#pylint: disable-msg=R0903
#pylint: disable=R0903
class KeyData(object):
"""
This is the object that contains the encoded wrapped secret
Expand All @@ -57,7 +57,7 @@ class KeyData(object):
'nonceData': 'nonce_data', 'wrappedPrivateData': 'wrapped_private_data'
}

# pylint: disable-msg=C0103
# pylint: disable=C0103
def __init__(self):
""" Constructor """
self.algorithm = None
Expand Down Expand Up @@ -108,7 +108,7 @@ class KeyInfo(object):
'ownerName': 'owner_name', 'publicKey': 'public_key'
}

# pylint: disable-msg=C0103
# pylint: disable=C0103
def __init__(self):
""" Constructor """
self.client_key_id = None
Expand Down Expand Up @@ -140,7 +140,7 @@ def get_key_id(self):
return None


#pylint: disable-msg=R0903
#pylint: disable=R0903
class KeyInfoCollection(object):
"""
This class represents data returned when searching the DRM archived
Expand Down Expand Up @@ -176,7 +176,7 @@ class KeyRequestInfo(object):
'keyURL': 'key_url', 'requestStatus': 'request_status'
}

# pylint: disable-msg=C0103
# pylint: disable=C0103
def __init__(self):
""" Constructor """
self.request_url = None
Expand Down Expand Up @@ -212,7 +212,7 @@ def get_key_id(self):
return None


#pylint: disable-msg=R0903
#pylint: disable=R0903
class KeyRequestInfoCollection(object):
"""
This class represents the data returned when searching the key
Expand Down Expand Up @@ -248,7 +248,7 @@ class KeyRequestResponse(object):
which contains the wrapped secret (if that operation is supported).
"""

# pylint: disable-msg=C0103
# pylint: disable=C0103
def __init__(self):
""" Constructor """
self.request_info = None
Expand Down Expand Up @@ -705,14 +705,14 @@ def archive_key(self, client_key_id, data_type, private_data,
key_size=key_size)

@pki.handle_exceptions()
def archive_encrypted_data(self,
client_key_id,
data_type,
encrypted_data,
wrapped_session_key,
algorithm_oid=None,
nonce_iv=None,
key_algorithm=None,
def archive_encrypted_data(self,\
client_key_id,\
data_type,\
encrypted_data,\
wrapped_session_key,\
algorithm_oid=None,\
nonce_iv=None,\
key_algorithm=None,\
key_size=None):
"""
Archive a secret (symmetric key or passphrase) on the DRM.
Expand Down

0 comments on commit dfe5598

Please sign in to comment.