[Pki-devel] [PATCH] Added --token-password in pki-server instance-externalcert-add / del command.

2016-06-22 Thread Amol Kahat

Hi,

Please review this patch.

Fixes : https://bugzilla.redhat.com/show_bug.cgi?id=1348531

Thanks
Amol K
>From d0e514e4f3c96ce5f8c6dba9efc05aaa819d94e6 Mon Sep 17 00:00:00 2001
From: Amol Kahat <aka...@redhat.com>
Date: Wed, 22 Jun 2016 13:36:33 +0530
Subject: [PATCH] Added --token-password option in pki-server-externalcert-add
 / del command.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1348531
---
 base/server/python/pki/server/cli/instance.py | 76 ++-
 1 file changed, 63 insertions(+), 13 deletions(-)

diff --git a/base/server/python/pki/server/cli/instance.py b/base/server/python/pki/server/cli/instance.py
index b2b31e1b806162caf74277504cfb08f79810a3ef..0cf60cb8a2db615aa1f5e987c5f5621b934a5981 100644
--- a/base/server/python/pki/server/cli/instance.py
+++ b/base/server/python/pki/server/cli/instance.py
@@ -629,6 +629,7 @@ class InstanceExternalCertAddCLI(pki.cli.CLI):
 print('  --trust-args   Trust args (default \",,\").')
 print('  --nickname   Nickname to be used.')
 print('  --tokenToken (default: internal).')
+print('  --token-password Token password.')
 print('  -v, --verbose  Run in verbose mode.')
 print('  --help Show help message.')
 print()
@@ -636,8 +637,8 @@ class InstanceExternalCertAddCLI(pki.cli.CLI):
 def execute(self, argv):
 try:
 opts, _ = getopt.gnu_getopt(argv, 'i:v', [
-'instance=',
-'cert-file=', 'trust-args=', 'nickname=','token=',
+'instance=', 'cert-file=', 'trust-args=',
+'nickname=','token=', 'token-password=',
 'verbose', 'help'])
 
 except getopt.GetoptError as e:
@@ -650,6 +651,7 @@ class InstanceExternalCertAddCLI(pki.cli.CLI):
 trust_args = '\",,\"'
 nickname = None
 token = 'internal'
+token_password = None
 
 for o, a in opts:
 if o in ('-i', '--instance'):
@@ -667,6 +669,9 @@ class InstanceExternalCertAddCLI(pki.cli.CLI):
 elif o == '--token':
 token = a
 
+elif o == '--token-password':
+token_password = a
+
 elif o in ('-v', '--verbose'):
 self.set_verbose(True)
 
@@ -683,12 +688,27 @@ class InstanceExternalCertAddCLI(pki.cli.CLI):
 print('ERROR: missing input file containing certificate')
 self.print_help()
 sys.exit(1)
+
+if os.path.isfile(cert_file):
+pass
+
+else:
+print('ERROR: Invalid certificate file, no such file or directory.')
+sys.exit(1)
 
 if not nickname:
 print('ERROR: missing nickname')
 self.print_help()
 sys.exit(1)
 
+if token is 'internal' and token_password is None:
+pass
+
+elif token is not 'internal' and token_password is None:
+print('ERROR: Specify token password')
+self.print_help()
+sys.exit(1)
+
 instance = pki.server.PKIInstance(instance_name)
 
 if instance.is_valid():
@@ -703,14 +723,23 @@ class InstanceExternalCertAddCLI(pki.cli.CLI):
 sys.exit(1)
 
 nicks = self.import_certs(
-instance, cert_file, nickname, token, trust_args)
-self.update_instance_config(instance, nicks, token)
+instance, cert_file, nickname, token, trust_args, token_password)
+
+try:
+self.update_instance_config(instance, nicks, token)
 
-self.print_message('Certificate imported for instance %s.' %
+self.print_message('Certificate imported for instance %s.' %
instance_name)
+except:
+print('ERROR: Failed to run pki-server instance-externalcert-add command')
+sys.exit(1)
+
+def import_certs(self, instance, cert_file, nickname, token, trust_args, token_password):
+if not token_password:
+password = instance.get_password(token)
+else:
+password = token_password
 
-def import_certs(self, instance, cert_file, nickname, token, trust_args):
-password = instance.get_password(token)
 certdb = pki.nssdb.NSSDatabase(
 directory=instance.nssdb_dir,
 password=password,
@@ -737,6 +766,7 @@ class InstanceExternalCertDeleteCLI(pki.cli.CLI):
 print('  -i, --instanceInstance ID (default: pki-tomcat).')
 print('  --nickname   Nickname to be used.')
 print('  --tokenToken (default: internal).')
+print('  --token-password Token password.')
 print('  -v, --verbose  Run in verbose mode.')
 print('  --help Show help message.')

[Pki-devel] Fixes exception while invalid module.

2016-06-21 Thread Amol Kahat

Hi,

Please review this patch.
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1348446

Thanks
Amol K
>From 8ec731ecade07c269c735401ba15619be88544b9 Mon Sep 17 00:00:00 2001
From: Amol Kahat <aka...@redhat.com>
Date: Tue, 21 Jun 2016 13:45:06 +0530
Subject: [PATCH] Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1348446

---
 base/common/python/pki/cli/__init__.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/base/common/python/pki/cli/__init__.py b/base/common/python/pki/cli/__init__.py
index 3be9cce2e5583e2ee519cdb2860e6346f90426da..cae2b13d2792ef4620f8563a4ba2e8bd1851fae5 100644
--- a/base/common/python/pki/cli/__init__.py
+++ b/base/common/python/pki/cli/__init__.py
@@ -156,7 +156,7 @@ class CLI(object):
 (module, sub_command) = self.parse_command(command)
 
 if not module:
-raise Exception('Invalid module "%s".' % command)
+print('ERROR: Invalid module "%s".' % command)
 
 # Prepare module arguments.
 if sub_command:
@@ -200,4 +200,5 @@ class CLI(object):
 
 (module, module_args) = self.parse_args(argv)
 
-module.execute(module_args)
+if module:
+module.execute(module_args)
-- 
2.5.5

___
Pki-devel mailing list
Pki-devel@redhat.com
https://www.redhat.com/mailman/listinfo/pki-devel

[Pki-devel] Invalid instance exception fix.

2016-06-21 Thread Amol Kahat

Hi,

Please review this patch.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1348433


Thanks
Amol K.
>From adaef8e7ca9d0c2a57eda09c52d0ed149e176224 Mon Sep 17 00:00:00 2001
From: Amol Kahat <aka...@redhat.com>
Date: Tue, 21 Jun 2016 13:20:59 +0530
Subject: [PATCH] Fixes: Invalid instance exception issue.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1348433
---
 base/server/python/pki/server/cli/instance.py | 56 ++-
 1 file changed, 46 insertions(+), 10 deletions(-)

diff --git a/base/server/python/pki/server/cli/instance.py b/base/server/python/pki/server/cli/instance.py
index 6e336e3cb8b9af7745143440ede95022cb7b..b2b31e1b806162caf74277504cfb08f79810a3ef 100644
--- a/base/server/python/pki/server/cli/instance.py
+++ b/base/server/python/pki/server/cli/instance.py
@@ -157,7 +157,11 @@ class InstanceCertExportCLI(pki.cli.CLI):
 sys.exit(1)
 
 instance = pki.server.PKIInstance(instance_name)
-instance.load()
+if instance.is_active():
+ instance.load()
+else:
+print('ERROR: Invalid tomcat instance specified.')
+sys.exit(1)
 
 if not pkcs12_password and not pkcs12_password_file:
 pkcs12_password = getpass.getpass(prompt='Enter password for PKCS #12 file: ')
@@ -233,7 +237,11 @@ class InstanceFindCLI(pki.cli.CLI):
 print()
 
 instance = pki.server.PKIInstance(instance_name)
-instance.load()
+if instance.is_valid():
+instance.load()
+else:
+print('ERROR: Invalid tomcat instance specfified.')
+sys.exit(1)
 
 InstanceCLI.print_instance(instance)
 
@@ -282,8 +290,12 @@ class InstanceShowCLI(pki.cli.CLI):
 instance_name = args[0]
 
 instance = pki.server.PKIInstance(instance_name)
-instance.load()
-
+if instance.is_valid():
+instance.load()
+else:
+print('ERROR: Invalid tomcat instance specified.')
+sys.exit(1)
+
 InstanceCLI.print_instance(instance)
 
 
@@ -470,7 +482,12 @@ class InstanceMigrateCLI(pki.cli.CLI):
 module.set_debug(self.debug)
 
 instance = pki.server.PKIInstance(instance_name)
-instance.load()
+
+if instance.is_valid():
+instance.load()
+else:
+print('ERROR: Invalid tomcat instance specified.')
+sys.exit(1)
 
 module.migrate(  # pylint: disable=no-member,maybe-no-member
 instance,
@@ -526,7 +543,12 @@ class InstanceNuxwdogEnableCLI(pki.cli.CLI):
 module.set_verbose(self.verbose)
 
 instance = pki.server.PKIInstance(instance_name)
-instance.load()
+
+if instance.is_valid():
+instance.load()
+else:
+print('ERROR: Invalid tomcat instance specified.')
+sys.exit(1)
 
 module.enable_nuxwdog(  # pylint: disable=no-member,maybe-no-member
 instance)
@@ -580,7 +602,11 @@ class InstanceNuxwdogDisableCLI(pki.cli.CLI):
 module.set_verbose(self.verbose)
 
 instance = pki.server.PKIInstance(instance_name)
-instance.load()
+if instance.is_valid():
+instance.load()
+else:
+print('ERROR: Invalid tomcat instance specified.')
+sys.exit(1)
 
 module.disable_nuxwdog(
 instance)  # pylint: disable=no-member,maybe-no-member
@@ -664,7 +690,12 @@ class InstanceExternalCertAddCLI(pki.cli.CLI):
 sys.exit(1)
 
 instance = pki.server.PKIInstance(instance_name)
-instance.load()
+
+if instance.is_valid():
+instance.load()
+else:
+print('ERROR: Invalid tomcat instance specified.')
+sys.exit(1)
 
 if instance.external_cert_exists(nickname, token):
 print('ERROR: Certificate already imported for instance %s.' %
@@ -753,8 +784,13 @@ class InstanceExternalCertDeleteCLI(pki.cli.CLI):
 sys.exit(1)
 
 instance = pki.server.PKIInstance(instance_name)
-instance.load()
-
+
+if instance.is_valid():
+instance.load()
+else:
+print('ERROR: Invalid tomcat instance specified.')
+sys.exit(1)
+
 self.remove_cert(instance, nickname, token)
 instance.delete_external_cert(nickname, token)
 
-- 
2.5.5

___
Pki-devel mailing list
Pki-devel@redhat.com
https://www.redhat.com/mailman/listinfo/pki-devel

[Pki-devel] Fixes pki-server subsystem --help options.

2016-06-21 Thread Amol Kahat

Hi,

Please review this patch.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1340718

Thanks
Amol  K.
>From ad4e565f54db5e38102f3cbceeb98b22090c0ef5 Mon Sep 17 00:00:00 2001
From: Amol Kahat <aka...@redhat.com>
Date: Tue, 21 Jun 2016 12:47:23 +0530
Subject: [PATCH] Fixes pki-server subsystem-* --help options.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1340718
---
 base/server/python/pki/server/cli/subsystem.py | 165 +
 1 file changed, 86 insertions(+), 79 deletions(-)

diff --git a/base/server/python/pki/server/cli/subsystem.py b/base/server/python/pki/server/cli/subsystem.py
index c92ed16be251af87aa20ddada17da48de2ea4511..a4d91610fd2fa9f575923f3361c5a544bacb1927 100644
--- a/base/server/python/pki/server/cli/subsystem.py
+++ b/base/server/python/pki/server/cli/subsystem.py
@@ -90,7 +90,7 @@ class SubsystemFindCLI(pki.cli.CLI):
 self.set_verbose(True)
 
 elif o == '--help':
-self.print_help()
+self.usage()
 sys.exit()
 
 else:
@@ -138,12 +138,6 @@ class SubsystemShowCLI(pki.cli.CLI):
 self.usage()
 sys.exit(1)
 
-if len(args) != 1:
-print('ERROR: missing subsystem ID')
-self.usage()
-sys.exit(1)
-
-subsystem_name = args[0]
 instance_name = 'pki-tomcat'
 
 for o, a in opts:
@@ -154,7 +148,7 @@ class SubsystemShowCLI(pki.cli.CLI):
 self.set_verbose(True)
 
 elif o == '--help':
-self.print_help()
+self.usage()
 sys.exit()
 
 else:
@@ -162,6 +156,13 @@ class SubsystemShowCLI(pki.cli.CLI):
 self.usage()
 sys.exit(1)
 
+if len(args) != 1:
+print('ERROR: missing subsystem ID')
+self.usage()
+sys.exit(1)
+
+subsystem_name = args[0]
+
 instance = pki.server.PKIInstance(instance_name)
 instance.load()
 
@@ -195,12 +196,6 @@ class SubsystemEnableCLI(pki.cli.CLI):
 self.usage()
 sys.exit(1)
 
-if len(args) != 1:
-print('ERROR: missing subsystem ID')
-self.usage()
-sys.exit(1)
-
-subsystem_name = args[0]
 instance_name = 'pki-tomcat'
 
 for o, a in opts:
@@ -211,7 +206,7 @@ class SubsystemEnableCLI(pki.cli.CLI):
 self.set_verbose(True)
 
 elif o == '--help':
-self.print_help()
+self.usage()
 sys.exit()
 
 else:
@@ -219,6 +214,13 @@ class SubsystemEnableCLI(pki.cli.CLI):
 self.usage()
 sys.exit(1)
 
+if len(args) != 1:
+print('ERROR: missing subsystem ID')
+self.usage()
+sys.exit(1)
+
+subsystem_name = args[0]
+
 instance = pki.server.PKIInstance(instance_name)
 instance.load()
 
@@ -257,12 +259,6 @@ class SubsystemDisableCLI(pki.cli.CLI):
 self.usage()
 sys.exit(1)
 
-if len(args) != 1:
-print('ERROR: missing subsystem ID')
-self.usage()
-sys.exit(1)
-
-subsystem_name = args[0]
 instance_name = 'pki-tomcat'
 
 for o, a in opts:
@@ -273,7 +269,7 @@ class SubsystemDisableCLI(pki.cli.CLI):
 self.set_verbose(True)
 
 elif o == '--help':
-self.print_help()
+self.usage()
 sys.exit()
 
 else:
@@ -281,6 +277,13 @@ class SubsystemDisableCLI(pki.cli.CLI):
 self.usage()
 sys.exit(1)
 
+if len(args) != 1:
+print('ERROR: missing subsystem ID')
+self.usage()
+sys.exit(1)
+
+subsystem_name = args[0]
+
 instance = pki.server.PKIInstance(instance_name)
 instance.load()
 
@@ -342,12 +345,6 @@ class SubsystemCertFindCLI(pki.cli.CLI):
 self.print_help()
 sys.exit(1)
 
-if len(args) != 1:
-print('ERROR: missing subsystem ID')
-self.print_help()
-sys.exit(1)
-
-subsystem_name = args[0]
 instance_name = 'pki-tomcat'
 show_all = False
 
@@ -370,6 +367,13 @@ class SubsystemCertFindCLI(pki.cli.CLI):
 self.print_help()
 sys.exit(1)
 
+if len(args) != 1:
+print('ERROR: missing subsystem ID')
+self.print_help()
+sys.exit(1)
+
+subsystem_name = args[0]
+
 instance = pki.server.PKIInstance(instance_name)
 instance.load()
 
@@ -414,18 +418,6 @@ class SubsystemCertShowCLI(pki.cli.CLI):
 self.usage()
 sys.exit(1)
 
-if len(args) < 1:
-print('ERROR: missing subsystem ID')
-self.usage()
-sys.exit(1)
-
-if len(args) < 2:
-