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

115
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")
subparsers = parser.add_subparsers(
help="Object to inspect", dest="object", required=True help="Object to inspect", dest="object", required=True
) )
x509_parser = subparsers.add_parser("x509", help="x509 certificates") x509_parser = subparsers.add_parser("x509", help="x509 certificates")
x509_subparsers = x509_parser.add_subparsers( x509_subparsers = x509_parser.add_subparsers(
help="Action for perform", dest="action", required=True help="Action for perform", dest="action", required=True
) )
x509_list_parser = x509_subparsers.add_parser("list", help="List x509 certificates") x509_list_parser = x509_subparsers.add_parser("list", help="List x509 certificates")
x509_list_parser.add_argument( x509_list_parser.add_argument(
"--show-expired", "--show-expired",
"-e", "-e",
action="store_true", action="store_true",
default=False, default=False,
help="Show expired certificates", help="Show expired certificates",
) )
x509_list_parser.add_argument( x509_list_parser.add_argument(
"--show-revoked", "--show-revoked",
"-r", "-r",
action="store_true", action="store_true",
default=False, default=False,
help="Show revoked certificates", help="Show revoked certificates",
) )
x509_list_parser.add_argument( x509_list_parser.add_argument(
"--sort-by", "--sort-by",
"-s", "-s",
type=str, type=str,
choices=["not_after", "not_before"], choices=["not_after", "not_before"],
default="not_after", default="not_after",
help="Sort certificates", help="Sort certificates",
) )
x509_details_parser = x509_subparsers.add_parser( x509_details_parser = x509_subparsers.add_parser(
"details", help="Show an x509 certificate details" "details", help="Show an x509 certificate details"
) )
x509_details_parser.add_argument( x509_details_parser.add_argument(
"--serial", "-s", type=str, required=True, help="Certificate serial" "--serial", "-s", type=str, required=True, help="Certificate serial"
) )
x509_details_parser.add_argument( x509_details_parser.add_argument(
"--show-cert", "--show-cert",
"-c", "-c",
action="store_true", action="store_true",
default=False, default=False,
help="Show certificate (PEM)", help="Show certificate (PEM)",
) )
x509_details_parser.add_argument( x509_details_parser.add_argument(
"--show-pubkey", "--show-pubkey",
"-p", "-p",
action="store_true", action="store_true",
default=False, default=False,
help="Show public key (PEM)", help="Show public key (PEM)",
) )
x509_dump_parser = x509_subparsers.add_parser("dump", help="Dump an x509 certificate") x509_dump_parser = x509_subparsers.add_parser(
x509_dump_parser.add_argument( "dump", help="Dump an x509 certificate"
)
x509_dump_parser.add_argument(
"--serial", "-s", type=str, required=True, help="Certificate serial" "--serial", "-s", type=str, required=True, help="Certificate serial"
) )
x509_dump_parser.add_argument( x509_dump_parser.add_argument(
"--format", "--format",
"-f", "-f",
type=str, type=str,
choices=["pem"], choices=["pem"],
required=False, required=False,
help="Certificate format", help="Certificate format",
) )
ssh_parser = subparsers.add_parser("ssh", help="ssh certificates") ssh_parser = subparsers.add_parser("ssh", help="ssh certificates")
ssh_subparsers = ssh_parser.add_subparsers( ssh_subparsers = ssh_parser.add_subparsers(
help="Action for perform", dest="action", required=True help="Action for perform", dest="action", required=True
) )
ssh_list_parser = ssh_subparsers.add_parser("list", help="List ssh certificates") ssh_list_parser = ssh_subparsers.add_parser("list", help="List ssh certificates")
ssh_list_parser.add_argument( ssh_list_parser.add_argument(
"--show-expired", "--show-expired",
"-e", "-e",
action="store_true", action="store_true",
default=False, default=False,
help="Show expired certificates", help="Show expired certificates",
) )
ssh_list_parser.add_argument( ssh_list_parser.add_argument(
"--show-revoked", "--show-revoked",
"-r", "-r",
action="store_true", action="store_true",
default=False, default=False,
help="Show revoked certificates", help="Show revoked certificates",
) )
ssh_list_parser.add_argument( ssh_list_parser.add_argument(
"--sort-by", "--sort-by",
"-s", "-s",
type=str, type=str,
choices=["not_after", "not_before"], choices=["not_after", "not_before"],
default="not_after", default="not_after",
help="Sort certificates (default: not_after)", help="Sort certificates (default: not_after)",
) )
ssh_details_parser = ssh_subparsers.add_parser( ssh_details_parser = ssh_subparsers.add_parser(
"details", help="Show an ssh certificate details" "details", help="Show an ssh certificate details"
) )
ssh_details_parser.add_argument( ssh_details_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") ssh_dump_parser = ssh_subparsers.add_parser("dump", help="Dump an ssh certificate")
ssh_dump_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"
) )
args = parser.parse_args() 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,
sort_key=args.sort_by,
) )
elif args.action == "details": elif args.action == "details":
get_x509_cert( get_x509_cert(
serial=args.serial, show_cert=args.show_cert, show_pubkey=args.show_pubkey serial=args.serial,
show_cert=args.show_cert,
show_pubkey=args.show_pubkey,
) )
elif args.action == "dump": elif args.action == "dump":
dump_x509_cert(serial=args.serial) dump_x509_cert(serial=args.serial)
elif args.object == "ssh": elif args.object == "ssh":
if args.action == "list": if args.action == "list":
list_ssh_certs( list_ssh_certs(
revoked=args.show_revoked, expired=args.show_expired, sort_key=args.sort_by revoked=args.show_revoked,
expired=args.show_expired,
sort_key=args.sort_by,
) )
elif args.action == "details": elif args.action == "details":
get_ssh_cert(serial=args.serial) get_ssh_cert(serial=args.serial)
elif args.action == "dump": elif args.action == "dump":
dump_ssh_cert(serial=args.serial) dump_ssh_cert(serial=args.serial)
if __name__ == "__main__":
main()