]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common/cryptotools: use a main function
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 21 Apr 2025 19:50:22 +0000 (15:50 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Mon, 7 Jul 2025 13:32:24 +0000 (09:32 -0400)
Use a main function to encapsulate the cli parsing rather than a block
of code in module scope.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/python-common/ceph/cryptotools/cryptotools.py

index 52c28d3f6ec92a8954a48a67037bc24ac9ffc0b0..979e664c1d3fe3db0406fe7425668921ae9fbbda 100644 (file)
@@ -209,7 +209,7 @@ def verify_tls(args: Namespace) -> None:
     json.dump({'ok': True}, sys.stdout)  # need to emit something on success
 
 
-if __name__ == "__main__":
+def main():
     # create the top-level parser
     parser = argparse.ArgumentParser(prog='cryptotools.py')
     subparsers = parser.add_subparsers(required=True)
@@ -220,8 +220,12 @@ if __name__ == "__main__":
 
     # create the parser for the "create_self_signed_cert" command
     parser_cssc = subparsers.add_parser('create_self_signed_cert')
-    parser_cssc.add_argument('--private_key', required=False, action='store_true')
-    parser_cssc.add_argument('--certificate', required=False, action='store_true')
+    parser_cssc.add_argument(
+        '--private_key', required=False, action='store_true'
+    )
+    parser_cssc.add_argument(
+        '--certificate', required=False, action='store_true'
+    )
     parser_cssc.set_defaults(func=create_self_signed_cert)
 
     # create the parser for the "certificate_days_to_expire" command
@@ -243,3 +247,7 @@ if __name__ == "__main__":
     # parse the args and call whatever function was selected
     args = parser.parse_args()
     args.func(args)
+
+
+if __name__ == "__main__":
+    main()