Debian Codegraph @

src/harlequin_postgres/cli_options.py

raw symbols SCIP
1 from __future__ import annotations
2
3 from harlequin.options import (
4 FlagOption, # noqa
5 ListOption, # noqa
6 PathOption, # noqa
7 SelectOption, # noqa
8 TextOption,
9 )
10
11 host = TextOption(
12 name="host",
13 description=(
14 "Specifies the host name of the machine on which the server is running. "
15 "If the value begins with a slash, it is used as the directory for the "
16 "Unix-domain socket."
17 ),
18 short_decls=["-h"],
19 default="localhost",
20 )
21
22
23 port = TextOption(
24 name="port",
25 description=(
26 "Port number to connect to at the server host, or socket file name extension "
27 "for Unix-domain connections."
28 ),
29 short_decls=["-p"],
30 default="5432",
31 )
32
33
34 dbname = TextOption(
35 name="dbname",
36 description=("The database name to use when connecting with the Postgres server."),
37 short_decls=["-d"],
38 default="postgres",
39 )
40
41
42 user = TextOption(
43 name="user",
44 description=("PostgreSQL user name to connect as."),
45 short_decls=["-u", "--username", "-U"],
46 )
47
48
49 password = TextOption(
50 name="password",
51 description=("Password to be used if the server demands password authentication."),
52 )
53
54
55 passfile = PathOption(
56 name="passfile",
57 description=(
58 "Specifies the name of the file used to store passwords. Defaults to "
59 r"~/.pgpass, or %APPDATA%\postgresql\pgpass.conf on Windows. (No error is "
60 "reported if this file does not exist.)"
61 ),
62 resolve_path=True,
63 exists=False,
64 file_okay=True,
65 dir_okay=False,
66 )
67
68 require_auth = SelectOption(
69 name="require_auth",
70 description=(
71 "Specifies the authentication method that the client requires from the server. "
72 "If the server does not use the required method to authenticate the client, or "
73 "if the authentication handshake is not fully completed by the server, the "
74 "connection will fail."
75 ),
76 choices=["password", "md5", "gss", "sspi", "scram-sha-256", "none"],
77 )
78
79 channel_binding = SelectOption(
80 name="channel_binding",
81 description=(
82 "This option controls the client's use of channel binding. A setting of "
83 "require means that the connection must employ channel binding, prefer "
84 "means that the client will choose channel binding if available, and "
85 "disable prevents the use of channel binding. The default is prefer if "
86 "PostgreSQL is compiled with SSL support; otherwise the default is disable."
87 ),
88 choices=["require", "prefer", "disable"],
89 )
90
91
92 def _int_validator(s: str | None) -> tuple[bool, str]:
93 if s is None:
94 return True, ""
95 try:
96 _ = int(s)
97 except ValueError:
98 return False, f"Cannot convert {s} to an int!"
99 else:
100 return True, ""
101
102
103 connect_timeout = TextOption(
104 name="connect_timeout",
105 description=(
106 "Maximum time to wait while connecting, in seconds (write as an integer, "
107 "e.g., 10)."
108 ),
109 validator=_int_validator,
110 )
111
112 sslmode = SelectOption(
113 name="sslmode",
114 description=(
115 "Determines whether or with what priority a secure SSL TCP/IP connection will "
116 "be negotiated with the server."
117 ),
118 choices=["disable", "allow", "prefer", "require", "verify-ca", "verify-full"],
119 default="prefer",
120 )
121
122 sslcert = PathOption(
123 name="sslcert",
124 description=(
125 "Specifies the file name of the client SSL certificate. "
126 "Ignored if an SSL connection is not made."
127 ),
128 default="~/.postgresql/postgresql.crt",
129 )
130
131 sslkey = TextOption(
132 name="sslkey",
133 description=(
134 "Specifies the location for the secret key used for the client certificate. "
135 "It can either specify a file name that will be used instead of the default "
136 "~/.postgresql/postgresql.key, or it can specify a key obtained from an "
137 "external engine. An external engine specification should consist of a "
138 "colon-separated engine name and an engine-specific key identifier. This "
139 "parameter is ignored if an SSL connection is not made."
140 ),
141 )
142
143
144 POSTGRES_OPTIONS = [
145 host,
146 port,
147 dbname,
148 user,
149 password,
150 passfile,
151 require_auth,
152 channel_binding,
153 connect_timeout,
154 sslmode,
155 sslcert,
156 sslkey,
157 ]