def execute(client, args): template = { 'intermediateCertificate': '', 'certificateSigningRequest': '', 'notes': args['--notes'], } try: template['certificate'] = open(args['--crt']).read() template['privateKey'] = open(args['--key']).read() if args['--csr']: template['intermediateCertificate'] = \ open(args['--csr']).read() if args['--icc']: template['certificateSigningRequest'] = \ open(args['--icc']).read() except IOError: raise ValueError("File does not exist") exit(1) manager = SSLManager(client) cert = manager.add_certificate(template) return ( "Created certificate: %s" % cert['commonName'], "Created certificate: %s" % cert['name'])
def execute(client, args): manager = SSLManager(client) certificates = manager.list_certs(args['--status']) t = Table(['id', 'common_name', 'days_until_expire', 'notes']) for certificate in certificates: t.add_row([ certificate['id'], certificate['commonName'], certificate['validityDays'], certificate.get('notes', None) ]) t.sortby = args['--sortby'] return t
def execute(client, args): template = {'id': args['<id>']} if args['--crt']: template['certificate'] = open(args['--crt']).read() if args['--key']: template['privateKey'] = open(args['--key']).read() if args['--csr']: template['intermediateCertificate'] = open(args['--csr']).read() if args['--icc']: template['certificateSigningRequest'] = open(args['--icc']).read() if args['--notes']: template['notes'] = args['--notes'] manager = SSLManager(client) manager.edit_certificate(template)
def execute(client, args): def write_cert(filename, content): try: fo = open(filename, 'w') fo.write(content) finally: fo.close() manager = SSLManager(client) certificate = manager.get_certificate(args['<id>']) write_cert( certificate['commonName'] + '.crt', certificate['certificate']) write_cert( certificate['commonName'] + '.key', certificate['privateKey']) if 'intermediateCertificate' in certificate: write_cert( certificate['commonName'] + '.icc', certificate['intermediateCertificate']) if 'certificateSigningRequest' in certificate: write_cert( certificate['commonName'] + '.csr', certificate['certificateSigningRequest'])
class SSLTests_unittests(unittest.TestCase): def setUp(self): self.client = MagicMock() self.ssl = SSLManager(self.client) self.test_id = 10 def test_list_certs(self): self.ssl.list_certs('valid') self.client.__getitem__() \ .getValidSecurityCertificates.assert_called_once_with(mask=ANY) self.ssl.list_certs('expired') self.client.__getitem__() \ .getExpiredSecurityCertificates.assert_called_once_with(mask=ANY) self.ssl.list_certs('all') self.client.__getitem__() \ .getSecurityCertificates.assert_called_once_with(mask=ANY) def test_add_certificate(self): test_cert = { 'certificate': 'cert', 'privateKey': 'key', } self.ssl.add_certificate(test_cert) self.client.__getitem__().createObject.assert_called_once_with( test_cert) def test_remove_certificate(self): self.ssl.remove_certificate(self.test_id) self.client.__getitem__() \ .deleteObject.assert_called_once_with(id=self.test_id) def test_edit_certificate(self): test_cert = { 'id': self.test_id, 'certificate': 'cert', 'privateKey': 'key' } self.ssl.edit_certificate(test_cert) self.client.__getitem__().editObject.assert_called_once_with( { 'id': self.test_id, 'certificate': 'cert', 'privateKey': 'key' }, id=self.test_id) def test_get_certificate(self): self.ssl.get_certificate(self.test_id) self.client.__getitem__().getObject.assert_called_once_with( id=self.test_id)
def setUp(self): self.client = MagicMock() self.ssl = SSLManager(self.client) self.test_id = 10
def execute(client, args): manager = SSLManager(client) if args['--really'] or no_going_back('yes'): manager.remove_certificate(args['<id>']) return "Deleted certificate: %s" % args['<id>'] raise CLIAbort("Aborted.")