| 1 | from __future__ import annotations |
| 2 | |
| 3 | from harlequin.options import ( |
| 4 | FlagOption, |
| 5 | PathOption, |
| 6 | TextOption, |
| 7 | ) |
| 8 | |
| 9 | |
| 10 | def _int_validator(s: str | None) -> tuple[bool, str]: |
| 11 | if s is None: |
| 12 | return True, "" |
| 13 | try: |
| 14 | _ = int(s) |
| 15 | except ValueError: |
| 16 | return False, f"Cannot convert {s} to an int!" |
| 17 | else: |
| 18 | return True, "" |
| 19 | |
| 20 | |
| 21 | host = TextOption( |
| 22 | name="host", |
| 23 | description=("The host name or IP address of the MySQL server."), |
| 24 | short_decls=["-h"], |
| 25 | default="localhost", |
| 26 | ) |
| 27 | |
| 28 | |
| 29 | port = TextOption( |
| 30 | name="port", |
| 31 | description=("The TCP/IP port of the MySQL server. Must be an integer."), |
| 32 | short_decls=["-p"], |
| 33 | default="3306", |
| 34 | validator=_int_validator, |
| 35 | ) |
| 36 | |
| 37 | |
| 38 | unix_socket = TextOption( |
| 39 | name="unix_socket", |
| 40 | description=("The location of the Unix socket file."), |
| 41 | ) |
| 42 | |
| 43 | |
| 44 | database = TextOption( |
| 45 | name="database", |
| 46 | description=("The database name to use when connecting with the MySQL server."), |
| 47 | short_decls=["-d", "-db"], |
| 48 | default="postgres", |
| 49 | ) |
| 50 | |
| 51 | |
| 52 | user = TextOption( |
| 53 | name="user", |
| 54 | description=("The user name used to authenticate with the MySQL server."), |
| 55 | short_decls=["-u", "--username", "-U"], |
| 56 | ) |
| 57 | |
| 58 | |
| 59 | password = TextOption( |
| 60 | name="password", |
| 61 | description=("The password to authenticate the user with the MySQL server."), |
| 62 | short_decls=["--password1"], |
| 63 | ) |
| 64 | |
| 65 | |
| 66 | password2 = TextOption( |
| 67 | name="password2", |
| 68 | description=("For Multi-Factor Authentication (MFA); Added in 8.0.28."), |
| 69 | ) |
| 70 | |
| 71 | |
| 72 | password3 = TextOption( |
| 73 | name="password3", |
| 74 | description=("For Multi-Factor Authentication (MFA); Added in 8.0.28."), |
| 75 | ) |
| 76 | |
| 77 | |
| 78 | connect_timeout = TextOption( |
| 79 | name="connection_timeout", |
| 80 | description="Timeout for the TCP and Unix socket connections. Must be an integer.", |
| 81 | short_decls=["--connect_timeout"], |
| 82 | validator=_int_validator, |
| 83 | ) |
| 84 | |
| 85 | |
| 86 | ssl_ca = PathOption( |
| 87 | name="ssl-ca", |
| 88 | description="File containing the SSL certificate authority.", |
| 89 | exists=True, |
| 90 | dir_okay=False, |
| 91 | ) |
| 92 | |
| 93 | ssl_cert = PathOption( |
| 94 | name="ssl-cert", |
| 95 | description="File containing the SSL certificate file.", |
| 96 | exists=True, |
| 97 | dir_okay=False, |
| 98 | short_decls=["--sslcert"], |
| 99 | ) |
| 100 | |
| 101 | ssl_disabled = FlagOption( |
| 102 | name="ssl-disabled", |
| 103 | description="True disables SSL/TLS usage.", |
| 104 | ) |
| 105 | |
| 106 | ssl_key = PathOption( |
| 107 | name="ssl-key", |
| 108 | description="File containing the SSL key.", |
| 109 | exists=True, |
| 110 | dir_okay=False, |
| 111 | short_decls=["--sslkey"], |
| 112 | ) |
| 113 | |
| 114 | openid_token_file = PathOption( |
| 115 | name="openid-token-file", |
| 116 | description="File containing the OpenID Token.", |
| 117 | exists=True, |
| 118 | dir_okay=False, |
| 119 | short_decls=["--oid"], |
| 120 | ) |
| 121 | |
| 122 | pool_size = TextOption( |
| 123 | name="pool-size", |
| 124 | description=( |
| 125 | "The number of concurrent connections maintained by Harlequin. MySQL " |
| 126 | "only allows one cursor per connection, so this sets the number of queries " |
| 127 | "that can be executed at once in Harlequin." |
| 128 | ), |
| 129 | short_decls=["-n"], |
| 130 | default="5", |
| 131 | validator=_int_validator, |
| 132 | ) |
| 133 | |
| 134 | |
| 135 | enable_cleartext_plugin = FlagOption( |
| 136 | name="enable-cleartext-plugin", |
| 137 | description="Enable the cleartext authentication plugin for MySQL connections.", |
| 138 | ) |
| 139 | |
| 140 | |
| 141 | MYSQLADAPTER_OPTIONS = [ |
| 142 | host, |
| 143 | port, |
| 144 | unix_socket, |
| 145 | database, |
| 146 | user, |
| 147 | password, |
| 148 | password2, |
| 149 | password3, |
| 150 | connect_timeout, |
| 151 | ssl_ca, |
| 152 | ssl_cert, |
| 153 | ssl_disabled, |
| 154 | ssl_key, |
| 155 | openid_token_file, |
| 156 | pool_size, |
| 157 | enable_cleartext_plugin, |
| 158 | ] |