Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ANCHOR-936] Fix ktReferenceServerConfig is not populated correctly #1607

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kotlin-reference-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
implementation(variantOf(libs.java.stellar.sdk) { classifier("uber") })

implementation(project(mapOf("path" to ":api-schema")))
implementation(project(":lib-util"))
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.stellar.reference.di

import com.sksamuel.hoplite.*
import org.stellar.anchor.util.StringHelper.dotToCamelCase
import org.stellar.reference.data.Config
import org.stellar.reference.data.LocationConfig

Expand All @@ -25,15 +26,14 @@ class ConfigContainer(envMap: Map<String, String>?) {
val locationCfgBuilder =
ConfigLoaderBuilder.default().addPropertySource(PropertySource.environment())

val cfgBuilder = ConfigLoaderBuilder.default()

// Add environment variables as a property source for the config object
cfgBuilder.addPropertySource(PropertySource.environment())
val cfgBuilder = ConfigLoaderBuilder.default().addPropertySource(PropertySource.environment())

// Add any environment variable overrides from the envMap
envMap?.run {
locationCfgBuilder.addMapSource(this)
cfgBuilder.addMapSource(this)
val camelEnvMap = this.mapKeys { (key, _) -> dotToCamelCase(key) }
locationCfgBuilder.addMapSource(camelEnvMap)
cfgBuilder.addMapSource(camelEnvMap)
}

val locationConfig = locationCfgBuilder.build().loadConfigOrThrow<LocationConfig>()
Expand Down
28 changes: 28 additions & 0 deletions lib-util/src/main/java/org/stellar/anchor/util/StringHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ public static String toPosixForm(String camel) {
.toUpperCase();
}

/**
* Converts a dot-separated string to camelCase. For example: - "kt.reference.server.config"
* becomes "ktReferenceServerConfig"
*
* @param s The dot-separated string to be converted.
* @return A string in camelCase format.
* @throws NullPointerException If the input string is null.
*/
public static String dotToCamelCase(String s) {
String[] parts = s.split("\\."); // Split by dot
StringBuilder result = new StringBuilder();

for (int i = 0; i < parts.length; i++) {
String part = parts[i];
if (part.isEmpty()) {
continue;
}
if (i == 0) {
// If it's the first part, leave it as is (in lowercase)
result.append(part);
} else {
// Capitalize the first letter of other parts
result.append(part.substring(0, 1).toUpperCase()).append(part.substring(1));
}
}
return result.toString();
}

static Gson gson = GsonUtils.getInstance();

/**
Expand Down
Loading