Enhance argument parsing in CA commands with detailed help messages and default values
/ test-bash (push) Successful in 12s
/ test-python (push) Failing after 8s
/ test-go (push) Failing after 13m44s

This commit is contained in:
2026-05-10 18:02:00 +02:00
parent 2fb1e96c68
commit 1cae1a87da
Regular → Executable
+20 -18
View File
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# MIT License # MIT License
# #
# Copyright (c) 2026 Sławomir Koszewski # Copyright (c) 2026 Sławomir Koszewski
@@ -367,25 +368,25 @@ def _build_parser():
sub = parser.add_subparsers(dest="command", required=True) sub = parser.add_subparsers(dest="command", required=True)
p_ca = sub.add_parser("make-ca", help="Create a root or issuing CA.") p_ca = sub.add_parser("make-ca", help="Create a root or issuing CA.")
p_ca.add_argument("--days", type=int, default=3650) p_ca.add_argument("--days", type=int, default=3650, help="Validity period in days (default: 3650)")
p_ca.add_argument("--issuing-ca") p_ca.add_argument("--issuing-ca", help="Specify the issuing CA")
p_ca.add_argument("--aia-base-url") p_ca.add_argument("--aia-base-url", help="Specify the AIA base URL")
p_ca.add_argument("ca_dir") p_ca.add_argument("--ca-dir", help="Directory to store the CA files")
p_ca.add_argument("ca_name") p_ca.add_argument("ca_name", help="Name of the CA")
p_cert = sub.add_parser("make-cert", help="Create a server/client certificate.") p_cert = sub.add_parser("make-cert", help="Create a server/client certificate.")
p_cert.add_argument("--ca-dir") p_cert.add_argument("--ca-dir", help="Directory of the CA")
p_cert.add_argument("--issuing-ca") p_cert.add_argument("--issuing-ca", help="Specify the issuing CA")
p_cert.add_argument("--days", type=int, default=365) p_cert.add_argument("--days", type=int, default=365, help="Validity period in days (default: 365)")
p_cert.add_argument("cert_dir") p_cert.add_argument("--cert-dir", help="Directory to store the certificate files")
p_cert.add_argument("subject_name") p_cert.add_argument("subject_name", help="Subject name for the certificate")
p_cert.add_argument("sans", nargs="*") p_cert.add_argument("sans", nargs="*", help="Subject Alternative Names (SANs) for the certificate")
p_pfx = sub.add_parser("make-pfx", help="Create a PKCS#12 (PFX) bundle.") p_pfx = sub.add_parser("make-pfx", help="Create a PKCS#12 (PFX) bundle.")
p_pfx.add_argument("--ca-dir", required=True) p_pfx.add_argument("--issuing-ca", help="Specify the issuing CA")
p_pfx.add_argument("--issuing-ca") p_pfx.add_argument("--ca-dir", help="Directory of the CA")
p_pfx.add_argument("--path", required=True, dest="cert_path") p_pfx.add_argument("--password", help="Password for the PFX file")
p_pfx.add_argument("--password") p_pfx.add_argument("path", help="Path to the certificate file")
return parser return parser
@@ -393,10 +394,11 @@ def _build_parser():
def main(argv=None): def main(argv=None):
parser = _build_parser() parser = _build_parser()
args = parser.parse_args(argv) args = parser.parse_args(argv)
ca_dir = args.ca_dir or os.environ.get("SIMPLE_CA_DIR") or os.getcwd()
if args.command == "make-ca": if args.command == "make-ca":
ok = make_ca( ok = make_ca(
args.ca_dir, args.ca_name, ca_dir, args.ca_name,
days=args.days, days=args.days,
issuing_ca=args.issuing_ca, issuing_ca=args.issuing_ca,
aia_base_url=args.aia_base_url, aia_base_url=args.aia_base_url,
@@ -405,13 +407,13 @@ def main(argv=None):
ok = make_cert( ok = make_cert(
args.cert_dir, args.subject_name, args.cert_dir, args.subject_name,
sans=args.sans, sans=args.sans,
ca_dir=args.ca_dir, ca_dir=ca_dir,
issuing_ca=args.issuing_ca, issuing_ca=args.issuing_ca,
days=args.days, days=args.days,
) )
elif args.command == "make-pfx": elif args.command == "make-pfx":
ok = make_pfx( ok = make_pfx(
args.cert_path, args.ca_dir, args.path, ca_dir,
issuing_ca=args.issuing_ca, issuing_ca=args.issuing_ca,
password=args.password, password=args.password,
) )