Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/mcl/net/Parameter.java @ 939:fd938d0a2b3a
Include all Parameters in GetPropertyInfo
Not just user, password, tls and cert.
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Wed, 08 Jan 2025 15:41:48 +0100 (3 months ago) |
parents | 64ea9d5fbf87 |
children | c5e47b8a509c |
comparison
equal
deleted
inserted
replaced
938:64ea9d5fbf87 | 939:fd938d0a2b3a |
---|---|
11 */ | 11 */ |
12 | 12 |
13 package org.monetdb.mcl.net; | 13 package org.monetdb.mcl.net; |
14 | 14 |
15 import java.sql.DriverPropertyInfo; | 15 import java.sql.DriverPropertyInfo; |
16 import java.util.ArrayList; | |
16 import java.util.Calendar; | 17 import java.util.Calendar; |
17 import java.util.Properties; | 18 import java.util.Properties; |
18 | 19 |
19 /** | 20 /** |
20 * Enumerates things that can be configured on a connection to MonetDB. | 21 * Enumerates things that can be configured on a connection to MonetDB. |
21 */ | 22 */ |
22 public enum Parameter { | 23 public enum Parameter { |
23 // String name, ParameterType type, Object defaultValue, String description, boolean isCore | 24 // String name, ParameterType type, Object defaultValue, String description, boolean isCore |
24 TLS("tls", ParameterType.Bool, false, "secure the connection using TLS", true), | 25 TLS("tls", ParameterType.Bool, false, "secure the connection using TLS", true, true), |
25 HOST("host", ParameterType.Str, "", "IP number, domain name or one of the special values `localhost` and `localhost.`", true), | 26 HOST("host", ParameterType.Str, "", "IP number, domain name or one of the special values `localhost` and `localhost.`", true), |
26 PORT("port", ParameterType.Int, -1, "Port to connect to, 1..65535 or -1 for 'not set'", true), | 27 PORT("port", ParameterType.Int, -1, "Port to connect to, 1..65535 or -1 for 'not set'", true), |
27 DATABASE("database", ParameterType.Str, "", "name of database to connect to", true), | 28 DATABASE("database", ParameterType.Str, "", "name of database to connect to", true), |
28 TABLESCHEMA("tableschema", ParameterType.Str, "", "only used for REMOTE TABLE, otherwise unused", true), | 29 TABLESCHEMA("tableschema", ParameterType.Str, "", "only used for REMOTE TABLE, otherwise unused", true), |
29 TABLE("table", ParameterType.Str, "", "only used for REMOTE TABLE, otherwise unused", true), | 30 TABLE("table", ParameterType.Str, "", "only used for REMOTE TABLE, otherwise unused", true), |
30 SOCK("sock", ParameterType.Path, "", "path to Unix domain socket to connect to", false), | 31 SOCK("sock", ParameterType.Path, "", "path to Unix domain socket to connect to", false), |
31 SOCKDIR("sockdir", ParameterType.Path, "/tmp", "Directory for implicit Unix domain sockets (.s.monetdb.PORT)", false), | 32 SOCKDIR("sockdir", ParameterType.Path, "/tmp", "Directory for implicit Unix domain sockets (.s.monetdb.PORT)", false), |
32 CERT("cert", ParameterType.Path, "", "path to TLS certificate to authenticate server with", false), | 33 CERT("cert", ParameterType.Path, "", "path to TLS certificate to authenticate server with", false, true), |
33 CERTHASH("certhash", ParameterType.Str, "", "hash of server TLS certificate must start with these hex digits; overrides cert", false), | 34 CERTHASH("certhash", ParameterType.Str, "", "hash of server TLS certificate must start with these hex digits; overrides cert", false, true), |
34 CLIENTKEY("clientkey", ParameterType.Path, "", "path to TLS key (+certs) to authenticate with as client", false), | 35 CLIENTKEY("clientkey", ParameterType.Path, "", "path to TLS key (+certs) to authenticate with as client", false, true), |
35 CLIENTCERT("clientcert", ParameterType.Path, "", "path to TLS certs for 'clientkey', if not included there", false), | 36 CLIENTCERT("clientcert", ParameterType.Path, "", "path to TLS certs for 'clientkey', if not included there", false, true), |
36 USER("user", ParameterType.Str, "", "user name to authenticate as", false), | 37 USER("user", ParameterType.Str, "", "user name to authenticate as", false), |
37 PASSWORD("password", ParameterType.Str, "", "password to authenticate with", false), | 38 PASSWORD("password", ParameterType.Str, "", "password to authenticate with", false), |
38 LANGUAGE("language", ParameterType.Str, "sql", "for example, \"sql\", \"mal\", \"msql\", \"profiler\"", false), | 39 LANGUAGE("language", ParameterType.Str, "sql", "for example, \"sql\", \"mal\", \"msql\", \"profiler\"", false), |
39 AUTOCOMMIT("autocommit", ParameterType.Bool, true, "initial value of autocommit", false), | 40 AUTOCOMMIT("autocommit", ParameterType.Bool, true, "initial value of autocommit", false), |
40 SCHEMA("schema", ParameterType.Str, "", "initial schema", false), | 41 SCHEMA("schema", ParameterType.Str, "", "initial schema", false), |
57 public final String name; | 58 public final String name; |
58 public final ParameterType type; | 59 public final ParameterType type; |
59 private final Object defaultValue; | 60 private final Object defaultValue; |
60 public final String description; | 61 public final String description; |
61 public final boolean isCore; | 62 public final boolean isCore; |
62 | 63 public final boolean isTlsRelated; |
63 Parameter(String name, ParameterType type, Object defaultValue, String description, boolean isCore) { | 64 |
65 Parameter(String name, ParameterType type, Object defaultValue, String description, boolean isCore, boolean isTlsRelated) { | |
64 this.name = name; | 66 this.name = name; |
65 this.type = type; | 67 this.type = type; |
66 this.defaultValue = defaultValue; | 68 this.defaultValue = defaultValue; |
67 this.description = description; | 69 this.description = description; |
68 this.isCore = isCore; | 70 this.isCore = isCore; |
71 this.isTlsRelated = isTlsRelated; | |
72 } | |
73 | |
74 Parameter(String name, ParameterType type, Object defaultValue, String description, boolean isCore) { | |
75 this(name, type, defaultValue, description, isCore, false); | |
69 } | 76 } |
70 | 77 |
71 public static Parameter forName(String name) { | 78 public static Parameter forName(String name) { |
72 switch (name) { | 79 switch (name) { |
73 case "tls": | 80 case "tls": |
200 * | 207 * |
201 * Note: This method is called from jdbc.MonetDriver.getPropertyInfo() | 208 * Note: This method is called from jdbc.MonetDriver.getPropertyInfo() |
202 * | 209 * |
203 * @param info a proposed list of tag/value pairs that will be sent on | 210 * @param info a proposed list of tag/value pairs that will be sent on |
204 * connect open | 211 * connect open |
205 * @param requires_tls flag to inform is tls required | 212 * @param includeTls include TLS related properties. |
206 * @return an array of DriverPropertyInfo objects describing possible | 213 * @return an array of DriverPropertyInfo objects describing possible |
207 * properties. This array may be an empty array if no properties | 214 * properties. This array may be an empty array if no properties |
208 * are required. | 215 * are required. |
209 */ | 216 */ |
210 public static DriverPropertyInfo[] getPropertyInfo(final Properties info, boolean requires_tls) { | 217 public static DriverPropertyInfo[] getPropertyInfo(final Properties info, boolean includeTls) { |
211 final String tls = info != null ? info.getProperty("tls") : null; | 218 final String[] booleanChoices = new String[] { "true", "false" }; |
212 final boolean tls_enabled = requires_tls || (tls != null && tls.equals("true")); | 219 final ArrayList<DriverPropertyInfo> mandatory = new ArrayList<>(Parameter.values().length); |
213 final int dpi_size = (tls_enabled ? 4 : 2); | 220 final ArrayList<DriverPropertyInfo> optional = new ArrayList<>(Parameter.values().length); |
214 final DriverPropertyInfo[] dpi = new DriverPropertyInfo[dpi_size]; | 221 |
215 DriverPropertyInfo prop = null; | 222 for (Parameter parm: Parameter.values()) { |
216 | 223 if (!includeTls && parm.isTlsRelated) |
217 // minimal required connection settings are "user" and "password" | 224 continue; |
218 prop = new DriverPropertyInfo("user", info != null ? info.getProperty("user") : null); | 225 if (parm == Parameter.FETCHSIZE) // alias of REPLYSIZE |
219 prop.required = true; | 226 continue; |
220 prop.description = "User loginname to use when authenticating on the database server"; | 227 String value = info == null ? null : info.getProperty(parm.name); |
221 dpi[0] = prop; | 228 if (value == null) { |
222 | 229 Object defaultValue = parm.getDefault(); |
223 prop = new DriverPropertyInfo("password", info != null ? info.getProperty("password") : null); | 230 if (defaultValue != null) |
224 prop.required = true; | 231 value = defaultValue.toString(); |
225 prop.description = "Password to use when authenticating on the database server"; | 232 } |
226 dpi[1] = prop; | 233 DriverPropertyInfo propInfo = new DriverPropertyInfo(parm.name, value); |
227 | 234 propInfo.description = parm.description; |
228 if (tls_enabled && dpi_size > 2) { | 235 if (parm.type == ParameterType.Bool) |
229 // when tls is enabled or required also "tls" and "cert" become required | 236 propInfo.choices = booleanChoices; |
230 final String[] boolean_choices = new String[] { "true", "false" }; | 237 propInfo.required = (parm == Parameter.USER || parm == Parameter.PASSWORD); |
231 | 238 if (propInfo.required) |
232 prop = new DriverPropertyInfo("tls", tls); | 239 mandatory.add(propInfo); |
233 prop.required = true; | 240 else |
234 prop.description = "secure the connection using TLS"; | 241 optional.add(propInfo); |
235 prop.choices = boolean_choices; | 242 } |
236 dpi[2] = prop; | 243 |
237 | 244 final DriverPropertyInfo[] result = new DriverPropertyInfo[mandatory.size() + optional.size()]; |
238 prop = new DriverPropertyInfo("cert", info != null ? info.getProperty("cert") : null); | 245 int i = 0; |
239 prop.required = true; | 246 for (DriverPropertyInfo propInfo: mandatory) |
240 prop.description = "path to TLS certificate to authenticate server with"; | 247 result[i++] = propInfo; |
241 dpi[3] = prop; | 248 for (DriverPropertyInfo propInfo: optional) |
242 } | 249 result[i++] = propInfo; |
243 | 250 |
244 return dpi; | 251 return result; |
245 } | 252 } |
246 } | 253 } |