Basic packaging

This commit is contained in:
Benjamin Collet 2025-04-23 13:10:44 +02:00
parent 1583cda39b
commit 9494eee98c
Signed by: bcollet
SSH key fingerprint: SHA256:8UJspOIcCOS+MtSOcnuq2HjKFube4ox1s/+A62ixov4
5 changed files with 162 additions and 123 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
.python-version .python-version
__pycache__/ __pycache__/
build/
*.egg-info/

24
setup.py Normal file
View file

@ -0,0 +1,24 @@
from setuptools import find_packages, setup
setup(
name="step-ca-inspector-client",
description="Step CA Inspector Client",
author="Benjamin Collet",
author_email="benjamin@collet.eu",
packages=find_packages(),
#long_description=open("README.md").read(),
#long_description_content_type="text/markdown",
install_requires=["requests>=2.20.0,<3.0", "PyYAML", "tabulate"],
keywords=["step-ca-inspector"],
version="0.0.1",
classifiers=[
"Intended Audience :: Developers",
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
],
entry_points={
"console_scripts": [
"step-ca-inspector = step_ca_inspector_client.cli:main",
],
},
)

View file

259
step-ca-inspector.py → step_ca_inspector_client/cli.py Executable file → Normal file
View file

@ -5,7 +5,7 @@ import requests
from urllib.parse import urljoin from urllib.parse import urljoin
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from tabulate import tabulate from tabulate import tabulate
from config import config from step_ca_inspector_client.config import config
config() config()
@ -126,7 +126,7 @@ def get_ssh_cert(serial):
) )
cert_tbl.append(["Extensions", "\n".join(cert["extensions"])]) cert_tbl.append(["Extensions", "\n".join(cert["extensions"])])
#cert_tbl.append(["Signing key", cert["signing_key"]]) # cert_tbl.append(["Signing key", cert["signing_key"]])
cert_tbl.append(["Status", cert["status"]]) cert_tbl.append(["Status", cert["status"]])
print(tabulate(cert_tbl, tablefmt="fancy_grid")) print(tabulate(cert_tbl, tablefmt="fancy_grid"))
@ -265,125 +265,138 @@ def dump_x509_cert(serial, cert_format="pem"):
print(cert["pem"].rstrip()) print(cert["pem"].rstrip())
parser = argparse.ArgumentParser(description="Step CA Inspector") def main():
subparsers = parser.add_subparsers( parser = argparse.ArgumentParser(description="Step CA Inspector")
help="Object to inspect", dest="object", required=True subparsers = parser.add_subparsers(
) help="Object to inspect", dest="object", required=True
x509_parser = subparsers.add_parser("x509", help="x509 certificates") )
x509_subparsers = x509_parser.add_subparsers( x509_parser = subparsers.add_parser("x509", help="x509 certificates")
help="Action for perform", dest="action", required=True x509_subparsers = x509_parser.add_subparsers(
) help="Action for perform", dest="action", required=True
x509_list_parser = x509_subparsers.add_parser("list", help="List x509 certificates") )
x509_list_parser.add_argument( x509_list_parser = x509_subparsers.add_parser("list", help="List x509 certificates")
"--show-expired", x509_list_parser.add_argument(
"-e", "--show-expired",
action="store_true", "-e",
default=False, action="store_true",
help="Show expired certificates", default=False,
) help="Show expired certificates",
x509_list_parser.add_argument( )
"--show-revoked", x509_list_parser.add_argument(
"-r", "--show-revoked",
action="store_true", "-r",
default=False, action="store_true",
help="Show revoked certificates", default=False,
) help="Show revoked certificates",
x509_list_parser.add_argument( )
"--sort-by", x509_list_parser.add_argument(
"-s", "--sort-by",
type=str, "-s",
choices=["not_after", "not_before"], type=str,
default="not_after", choices=["not_after", "not_before"],
help="Sort certificates", default="not_after",
) help="Sort certificates",
x509_details_parser = x509_subparsers.add_parser( )
"details", help="Show an x509 certificate details" x509_details_parser = x509_subparsers.add_parser(
) "details", help="Show an x509 certificate details"
x509_details_parser.add_argument( )
"--serial", "-s", type=str, required=True, help="Certificate serial" x509_details_parser.add_argument(
) "--serial", "-s", type=str, required=True, help="Certificate serial"
x509_details_parser.add_argument( )
"--show-cert", x509_details_parser.add_argument(
"-c", "--show-cert",
action="store_true", "-c",
default=False, action="store_true",
help="Show certificate (PEM)", default=False,
) help="Show certificate (PEM)",
x509_details_parser.add_argument( )
"--show-pubkey", x509_details_parser.add_argument(
"-p", "--show-pubkey",
action="store_true", "-p",
default=False, action="store_true",
help="Show public key (PEM)", default=False,
) help="Show public key (PEM)",
x509_dump_parser = x509_subparsers.add_parser("dump", help="Dump an x509 certificate") )
x509_dump_parser.add_argument( x509_dump_parser = x509_subparsers.add_parser(
"--serial", "-s", type=str, required=True, help="Certificate serial" "dump", help="Dump an x509 certificate"
) )
x509_dump_parser.add_argument( x509_dump_parser.add_argument(
"--format", "--serial", "-s", type=str, required=True, help="Certificate serial"
"-f", )
type=str, x509_dump_parser.add_argument(
choices=["pem"], "--format",
required=False, "-f",
help="Certificate format", type=str,
) choices=["pem"],
ssh_parser = subparsers.add_parser("ssh", help="ssh certificates") required=False,
ssh_subparsers = ssh_parser.add_subparsers( help="Certificate format",
help="Action for perform", dest="action", required=True )
) ssh_parser = subparsers.add_parser("ssh", help="ssh certificates")
ssh_list_parser = ssh_subparsers.add_parser("list", help="List ssh certificates") ssh_subparsers = ssh_parser.add_subparsers(
ssh_list_parser.add_argument( help="Action for perform", dest="action", required=True
"--show-expired", )
"-e", ssh_list_parser = ssh_subparsers.add_parser("list", help="List ssh certificates")
action="store_true", ssh_list_parser.add_argument(
default=False, "--show-expired",
help="Show expired certificates", "-e",
) action="store_true",
ssh_list_parser.add_argument( default=False,
"--show-revoked", help="Show expired certificates",
"-r", )
action="store_true", ssh_list_parser.add_argument(
default=False, "--show-revoked",
help="Show revoked certificates", "-r",
) action="store_true",
ssh_list_parser.add_argument( default=False,
"--sort-by", help="Show revoked certificates",
"-s", )
type=str, ssh_list_parser.add_argument(
choices=["not_after", "not_before"], "--sort-by",
default="not_after", "-s",
help="Sort certificates (default: not_after)", type=str,
) choices=["not_after", "not_before"],
ssh_details_parser = ssh_subparsers.add_parser( default="not_after",
"details", help="Show an ssh certificate details" help="Sort certificates (default: not_after)",
) )
ssh_details_parser.add_argument( ssh_details_parser = ssh_subparsers.add_parser(
"--serial", "-s", type=str, required=True, help="Certificate serial" "details", help="Show an ssh certificate details"
) )
ssh_dump_parser = ssh_subparsers.add_parser("dump", help="Dump an ssh certificate") ssh_details_parser.add_argument(
ssh_dump_parser.add_argument( "--serial", "-s", type=str, required=True, help="Certificate serial"
"--serial", "-s", type=str, required=True, help="Certificate serial" )
) ssh_dump_parser = ssh_subparsers.add_parser("dump", help="Dump an ssh certificate")
args = parser.parse_args() ssh_dump_parser.add_argument(
"--serial", "-s", type=str, required=True, help="Certificate serial"
)
args = parser.parse_args()
if args.object == "x509": if args.object == "x509":
if args.action == "list": if args.action == "list":
list_x509_certs( list_x509_certs(
revoked=args.show_revoked, expired=args.show_expired, sort_key=args.sort_by revoked=args.show_revoked,
) expired=args.show_expired,
elif args.action == "details": sort_key=args.sort_by,
get_x509_cert( )
serial=args.serial, show_cert=args.show_cert, show_pubkey=args.show_pubkey elif args.action == "details":
) get_x509_cert(
elif args.action == "dump": serial=args.serial,
dump_x509_cert(serial=args.serial) show_cert=args.show_cert,
elif args.object == "ssh": show_pubkey=args.show_pubkey,
if args.action == "list": )
list_ssh_certs( elif args.action == "dump":
revoked=args.show_revoked, expired=args.show_expired, sort_key=args.sort_by dump_x509_cert(serial=args.serial)
) elif args.object == "ssh":
elif args.action == "details": if args.action == "list":
get_ssh_cert(serial=args.serial) list_ssh_certs(
elif args.action == "dump": revoked=args.show_revoked,
dump_ssh_cert(serial=args.serial) expired=args.show_expired,
sort_key=args.sort_by,
)
elif args.action == "details":
get_ssh_cert(serial=args.serial)
elif args.action == "dump":
dump_ssh_cert(serial=args.serial)
if __name__ == "__main__":
main()