Skip to content

Commit

Permalink
fix certgrinderd 'show configuration' subcommand and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
tykling committed Oct 22, 2023
1 parent 63d420d commit d18545f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
1 change: 1 addition & 0 deletions docs/certgrinderd-changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Fixed

- Add missing development dependency `build` to dev extras in `pyproject.toml`
- Stop including unit tests in built packages. Tests are still included in the source `.tar.gz` distribution.
- Fixed broken `show configuration` subcommand and remove some unused code.


v0.18.0 (02-oct-2023)
Expand Down
31 changes: 15 additions & 16 deletions server/certgrinderd/certgrinderd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import tempfile
import typing
from datetime import datetime, timedelta
from pprint import pprint

import cryptography.x509
import requests
Expand Down Expand Up @@ -1040,32 +1041,24 @@ def get_parser() -> argparse.ArgumentParser:
# "show" command
show_parser = subparsers.add_parser(
"show",
help='Use the "show" command to show configuration, CSR info, or certificate info.',
help='Use the "show" command to show configuration and ACME account info.',
)
show_subparsers = show_parser.add_subparsers(
help="Specify what to show using one of the available show sub-commands",
dest="subcommand",
required=True,
)

# "show certificate" subcommand
show_certificate_parser = show_subparsers.add_parser(
"certificate",
help="Tell certgrinder to output information about the provided certificate.",
)
show_certificate_parser.set_defaults(method="show_certificate_command")

# "show csr" subcommand
show_csr_parser = show_subparsers.add_parser(
"csr", help="Tell certgrinder to output information about the provided CSR."
# "show configuration" subcommand
show_subparsers.add_parser(
"configuration", help="Tell certgrinderd to output the current configuration"
)
show_csr_parser.set_defaults(method="show_csr_command")

# "show configuration" subcommand
show_configuration_parser = show_subparsers.add_parser(
"configuration", help="Tell certgrinder to output the current configuration"
# "show acmeaccount" subcommand
show_acmeaccount_parser = show_subparsers.add_parser(
"acmeaccount", help="Tell certgrinderd to output the ACME account URI (for example for use in CAA records)"
)
show_configuration_parser.set_defaults(method="show_configuration_command")
show_acmeaccount_parser.set_defaults(method="show_acmeaccount_command")

# "help" command
subparsers.add_parser("help", help='The "help" command just outputs the usage help')
Expand Down Expand Up @@ -1292,6 +1285,12 @@ def main(mockargs: typing.Optional[typing.List[str]] = None) -> None:
# instantiate Certgrinderd class
certgrinderd = Certgrinderd(userconfig=config)

# if the command is "show configuration" just output certgrinder.conf and exit now
if args.command == "show" and args.subcommand == "configuration":
logger.info("Current certgrinderd configuration:")
pprint(certgrinderd.conf)
sys.exit(0)

# all good
try:
logger.debug(f"Calling method {args.method}")
Expand Down
13 changes: 8 additions & 5 deletions server/certgrinderd/tests/test_certgrinderd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
import requests
from certgrinderd.certgrinderd import Certgrinderd, main

# from cryptography.hazmat import primitives
# from cryptography.hazmat.backends import cryptography.hazmat.backends.default_backend
# from cryptography.hazmat.backends.openssl import x509


def test_parse_csr(known_csr):
"""Test the parse_csr() method with a valid CSR."""
certgrinderd = Certgrinderd()
Expand Down Expand Up @@ -927,3 +922,11 @@ def test_help(capsys):
assert E.type == SystemExit
captured = capsys.readouterr()
assert "See the manpage certgrinderd(8)" in captured.out

def test_show_configuration(capsys):
"""Test the 'show configuration' sub-command."""
with pytest.raises(SystemExit) as E:
main(["show", "configuration"])
assert E.type == SystemExit
captured = capsys.readouterr()
assert "Current certgrinderd configuration:"

0 comments on commit d18545f

Please sign in to comment.