Skip to content

Commit

Permalink
Fix #107: Handle environment variable connection prop
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Sep 26, 2024
1 parent 0afbb97 commit bc3eeef
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 38 deletions.
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/includes/quarkus-temporal.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_TEMPORAL_CONNECTION_MTLS_CLIENT_CERT_PATH+++`
endif::add-copy-button-to-env-var[]
--|string
--|path
|


Expand All @@ -916,7 +916,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_TEMPORAL_CONNECTION_MTLS_CLIENT_KEY_PATH+++`
endif::add-copy-button-to-env-var[]
--|string
--|path
|


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,46 @@ public class TemporalConfigRelocateInterceptor implements ConfigSourceIntercepto
@Override
public ConfigValue getValue(ConfigSourceInterceptorContext context, String name) {

if (name.equals("quarkus.grpc.clients.temporal-client.host")) {

ConfigValue host = context.proceed("quarkus.grpc.clients.temporal-client.host");
ConfigValue target = context.proceed("quarkus.temporal.connection.target");
if (host == null && target != null) {
String[] split = target.getValue().split(":");
return target.from()
.withName("quarkus.grpc.clients.temporal-client.host")
.withValue(split[0])
.build();
}
return host;
ConfigValue target = context.proceed("quarkus.temporal.connection.target");
if (target == null) {
return context.proceed(name);
}
String[] connection = processConnectString(target.getValue());

if (name.equals("quarkus.grpc.clients.temporal-client.port")) {
switch (name) {
case "quarkus.grpc.clients.temporal-client.host": {

ConfigValue port = context.proceed("quarkus.grpc.clients.temporal-client.port");
ConfigValue target = context.proceed("quarkus.temporal.connection.target");
if (port == null && target != null) {
String[] split = target.getValue().split(":");
return target.from()
.withName("quarkus.grpc.clients.temporal-client.port")
.withValue(split[1])
.build();
ConfigValue host = context.proceed("quarkus.grpc.clients.temporal-client.host");
if (host == null && connection[0] != null) {
return target.from()
.withName("quarkus.grpc.clients.temporal-client.host")
.withValue(connection[0])
.build();
}
return host;
}
return port;
}
case "quarkus.grpc.clients.temporal-client.port": {

if (name.equals("quarkus.grpc.clients.temporal-client.test-port")) {
ConfigValue port = context.proceed("quarkus.grpc.clients.temporal-client.port");
if (port == null && connection[1] != null) {
return target.from()
.withName("quarkus.grpc.clients.temporal-client.port")
.withValue(connection[1])
.build();
}
return port;
}
case "quarkus.grpc.clients.temporal-client.test-port": {

ConfigValue port = context.proceed("quarkus.grpc.clients.temporal-client.test-port");
ConfigValue target = context.proceed("quarkus.temporal.connection.target");
if (port == null && target != null) {
String[] split = target.getValue().split(":");
return target.from()
.withName("quarkus.grpc.clients.temporal-client.test-port")
.withValue(split[1])
.build();
ConfigValue port = context.proceed("quarkus.grpc.clients.temporal-client.test-port");
if (port == null && connection[1] != null) {
return target.from()
.withName("quarkus.grpc.clients.temporal-client.test-port")
.withValue(connection[1])
.build();
}
return port;
}
return port;
}

return context.proceed(name);
Expand All @@ -71,4 +71,37 @@ public Iterator<String> iterateNames(ConfigSourceInterceptorContext context) {
return names.iterator();
}

}
/**
* Processes a connection string and extracts the host and port.
* The input can either be in the format "${PLACEHOLDER:host:port}" or "host:port".
* If the input contains a placeholder in the form of "${...}", the method removes it
* and returns the host and port. If the port is not provided, the port will be an empty string.
*
* @param input the connection string which may include a placeholder in the form "${...}" or just "host:port".
* @return a String array where the first element is the host and the second element is the port. If the port is
* not provided, the second element will be an empty string.
* @throws IllegalArgumentException if the input is null or empty.
*/
private static String[] processConnectString(String input) {
if (input == null || input.isEmpty()) {
throw new IllegalArgumentException("'quarkus.temporal.connection.target' cannot be null or empty");
}

// Check if the string starts with "${" and contains a "}"
input = input.replaceAll("^\\$\\{", "");
input = input.replaceAll("}", "");

// Split by colon
String[] parts = input.split(":");

// Validate that there are at least two parts (host and port)
if (parts.length >= 2) {
String host = parts[parts.length - 2];
String port = parts[parts.length - 1];
// Return the host and port as a string array
return new String[] { host, port };
} else {
throw new IllegalArgumentException("'quarkus.temporal.connection.target' is not in host:port format.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public WorkflowClientRecorder(TemporalRuntimeConfig runtimeConfig, TemporalBuild
/**
* Creates an instance of {@link WorkflowClientOptions} based on the provided propagators and telemetry settings.
*
* @param context
* @param context the workflow Synthetic Creation Context
* @return A configured {@link WorkflowClientOptions} instance.
*/
public WorkflowClientOptions createWorkflowClientOptions(
Expand Down Expand Up @@ -99,4 +99,4 @@ public Function<SyntheticCreationalContext<WorkflowClient>, WorkflowClient> crea
createWorkflowClientOptions(context));
}

}
}

0 comments on commit bc3eeef

Please sign in to comment.