From ca61b00c103262137c9f2b827499a9fcf44731ed Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Tue, 21 Jan 2025 00:58:41 +0800 Subject: feat(manage): default to test in certbot. add update-blog command. --- tools/cru-py/cru/service/_external.py | 14 +++++++++++++- tools/cru-py/cru/service/_nginx.py | 15 +++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/tools/cru-py/cru/service/_external.py b/tools/cru-py/cru/service/_external.py index 418316a..2347e95 100644 --- a/tools/cru-py/cru/service/_external.py +++ b/tools/cru-py/cru/service/_external.py @@ -21,7 +21,10 @@ class CliToolCommandProvider(AppCommandFeatureProvider): "-t", "--test", action="store_true", help="run certbot in test mode" ) _install_docker_parser = subparsers.add_parser( - "install-docker", help="print docker commands" + "install-docker", help="print docker installation commands" + ) + _update_blog_parser = subparsers.add_parser( + "update-blog", help="print blog update command" ) def _print_install_docker_commands(self) -> None: @@ -59,6 +62,13 @@ sudo systemctl start docker sudo groupadd -f docker sudo usermod -aG docker $USER # Remember to log out and log back in for the group changes to take effect +""".strip() + print(output) + + def _print_update_blog_command(self): + output = """ +### COMMAND: update blog +docker exec -it blog /scripts/update.bash """.strip() print(output) @@ -67,3 +77,5 @@ sudo usermod -aG docker $USER self.app.get_feature(NginxManager).print_all_certbot_commands(args.test) elif args.gen_cli_command == "install-docker": self._print_install_docker_commands() + elif args.gen_cli_command == "update-blog": + self._print_update_blog_command() \ No newline at end of file diff --git a/tools/cru-py/cru/service/_nginx.py b/tools/cru-py/cru/service/_nginx.py index a9013e2..e0a9c60 100644 --- a/tools/cru-py/cru/service/_nginx.py +++ b/tools/cru-py/cru/service/_nginx.py @@ -91,10 +91,9 @@ class NginxManager(AppCommandFeatureProvider): def _certbot_command( self, action: CertbotAction | str, - /, - test=False, - no_docker=False, + test: bool, *, + docker=True, standalone=None, email=None, agree_tos=True, @@ -123,7 +122,7 @@ class NginxManager(AppCommandFeatureProvider): data_dir = self.app.data_dir.full_path.as_posix() - if no_docker: + if not docker: command_args.append("certbot") else: command_args.extend( @@ -142,6 +141,8 @@ class NginxManager(AppCommandFeatureProvider): command_args.append(command_action) + command_args.append(f"--cert-name {self.root_domain}") + if standalone: command_args.append("--standalone") else: @@ -208,14 +209,16 @@ class NginxManager(AppCommandFeatureProvider): _list_parser = subparsers.add_parser("list", help="list domains") certbot_parser = subparsers.add_parser("certbot", help="print certbot commands") certbot_parser.add_argument( - "-t", "--test", action="store_true", help="run certbot in test mode" + "--no-test", + action="store_true", + help="remove args making certbot run in test mode", ) def run_command(self, args: Namespace) -> None: if args.nginx_command == "list": self._print_domains() elif args.nginx_command == "certbot": - self.print_all_certbot_commands(args.test) + self.print_all_certbot_commands(not args.no_test) def _generate_dns_zone( self, -- cgit v1.2.3