imbajin commented on code in PR #2944:
URL:
https://github.com/apache/incubator-hugegraph/pull/2944#discussion_r2724267776
##########
hugegraph-commons/hugegraph-common/src/main/java/org/apache/hugegraph/config/HugeConfig.java:
##########
@@ -213,4 +217,55 @@ private static Configuration loadConfigFile(File
configFile) {
e, configFile);
}
}
+
+ private static Object normalizeUrlOptionIfNeeded(String key, Object value)
{
+ if (value == null) {
+ return null;
+ }
+
+ String scheme = defaultSchemeFor(key);
+ if (scheme == null) {
+ return value;
+ }
+
+ // URL options are defined as ConfigOption<String> and normalized here.
+ if (value instanceof String) {
+ return prefixSchemeIfMissing((String) value, scheme);
+ }
+
+ // If it ever hits here, it means config storage returned a non-string
type;
+ // leave it unchanged (safer than forcing toString()).
+ return value;
+ }
+
+ private static String defaultSchemeFor(String key) {
Review Comment:
**‼️ Critical: Hardcoded Config Keys Break Maintainability**
The switch statement hardcodes config key strings:
```java
case "restserver.url":
case "gremlinserver.url":
case "server.urls_to_pd":
case "server.k8s_url":
```
This creates tight coupling between `HugeConfig` (commons module) and
specific config keys from various modules. If a key is renamed or a new URL
option is added elsewhere, developers must remember to update this switch
statement.
**Better approach:** Let `ConfigOption` declare whether it needs URL
normalization via metadata:
```java
public class ConfigOption<T> {
private boolean urlNormalize = false;
private String defaultScheme = "http://";
public ConfigOption<T> withUrlNormalization(String scheme) {
this.urlNormalize = true;
this.defaultScheme = scheme;
return this;
}
}
```
Then in `HugeConfig.get()`:
```java
if (option.needsUrlNormalization()) {
value = prefixSchemeIfMissing((String) value, option.getDefaultScheme());
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]