44
55import requests
66
7+ DEFAULT_PORT = 8000
8+ DEFAULT_TIMEOUT_SECONDS = 1
79
8- def get_args (argv : list [str ]) -> argparse .Namespace :
10+
11+ def get_args (
12+ argv : list [str ],
13+ * ,
14+ prog : str ,
15+ ) -> argparse .Namespace :
916 parser = argparse .ArgumentParser (
1017 description = "Health checks" ,
18+ prog = prog ,
1119 )
12- subcommands = parser .add_subparsers (dest = "subcommand" , required = True )
20+ subcommands = parser .add_subparsers (dest = "subcommand" )
1321 tcp_parser = subcommands .add_parser (
14- "tcp" , help = "Check if the API is able to accept local TCP connections"
22+ "tcp" ,
23+ help = "Check if the API is able to accept local TCP connections" ,
1524 )
1625 tcp_parser .add_argument (
1726 "--port" ,
1827 "-p" ,
1928 type = int ,
20- default = 8000 ,
21- help = "Port to check the API on (default: 8000 )" ,
29+ default = DEFAULT_PORT ,
30+ help = f "Port to check the API on (default: { DEFAULT_PORT } )" ,
2231 )
2332 tcp_parser .add_argument (
2433 "--timeout" ,
2534 "-t" ,
2635 type = int ,
27- default = 1 ,
28- help = "Socket timeout for the connection attempt in seconds (default: 1 )" ,
36+ default = DEFAULT_TIMEOUT_SECONDS ,
37+ help = f "Socket timeout for the connection attempt in seconds (default: { DEFAULT_TIMEOUT_SECONDS } )" ,
2938 )
3039 http_parser = subcommands .add_parser (
3140 "http" , help = "Check if the API is able to serve HTTP requests"
@@ -34,15 +43,15 @@ def get_args(argv: list[str]) -> argparse.Namespace:
3443 "--port" ,
3544 "-p" ,
3645 type = int ,
37- default = 8000 ,
38- help = "Port to check the API on (default: 8000 )" ,
46+ default = DEFAULT_PORT ,
47+ help = f "Port to check the API on (default: { DEFAULT_PORT } )" ,
3948 )
4049 http_parser .add_argument (
4150 "--timeout" ,
4251 "-t" ,
4352 type = int ,
44- default = 1 ,
45- help = "Request timeout in seconds (default: 1 )" ,
53+ default = DEFAULT_TIMEOUT_SECONDS ,
54+ help = f "Request timeout in seconds (default: { DEFAULT_TIMEOUT_SECONDS } )" ,
4655 )
4756 http_parser .add_argument (
4857 "path" ,
@@ -83,9 +92,18 @@ def check_http_response(
8392 ).raise_for_status ()
8493
8594
86- def main (argv : list [str ]) -> None :
87- args = get_args (argv )
95+ def main (
96+ argv : list [str ],
97+ * ,
98+ prog : str ,
99+ ) -> None :
100+ args = get_args (argv , prog = prog )
88101 match args .subcommand :
102+ case None :
103+ check_tcp_connection (
104+ port = DEFAULT_PORT ,
105+ timeout_seconds = DEFAULT_TIMEOUT_SECONDS ,
106+ )
89107 case "tcp" :
90108 check_tcp_connection (
91109 port = args .port ,
0 commit comments