Skip to content

Commit

Permalink
Unify environment variable usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmigueprieto committed Jan 7, 2025
1 parent eba0c7f commit 312c26f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
30 changes: 21 additions & 9 deletions Conductor/Client/Extensions/ApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@ namespace Conductor.Client.Extensions
{
public class ApiExtensions
{
private const string ENV_ROOT_URI = "CONDUCTOR_SERVER_URL";
private const string ENV_KEY_ID = "KEY";
private const string ENV_SECRET = "SECRET";
private const int REST_CLIENT_REQUEST_TIME_OUT = 30 * 1000;

private static readonly Lazy<Configuration> _lazyConfiguration =
new Lazy<Configuration>(() => new Configuration(REST_CLIENT_REQUEST_TIME_OUT)
{
BasePath = GetEnvironmentVariable(ENV_ROOT_URI),
AuthenticationSettings = new OrkesAuthenticationSettings(
GetEnvironmentVariable(ENV_KEY_ID),
GetEnvironmentVariable(ENV_SECRET)
)
BasePath = GetBasePathFromEnv(),
AuthenticationSettings = GetAuthenticationSettingsFromEnv()
});

private static Configuration _customConfiguration;
Expand Down Expand Up @@ -68,9 +62,27 @@ public static string GetWorkflowExecutionURL(string workflowId)
return $"{prefix}/execution/{workflowId}";
}

private static string GetEnvironmentVariable(string variable)
private static string GetEnvVariableOrThrow(string variable)
{
return Environment.GetEnvironmentVariable(variable) ?? throw new InvalidOperationException($"Environment variable '{variable}' is not set.");
}

private static string GetBasePathFromEnv()
{
return GetEnvVariableOrThrow("CONDUCTOR_SERVER_URL");
}

private static OrkesAuthenticationSettings GetAuthenticationSettingsFromEnv()
{
// keeping KEY and SECRET for backwards compatibility
string keyId = Environment.GetEnvironmentVariable("CONDUCTOR_AUTH_KEY") ?? Environment.GetEnvironmentVariable("KEY");
string secret = Environment.GetEnvironmentVariable("CONDUCTOR_AUTH_SECRET") ?? Environment.GetEnvironmentVariable("SECRET");
if (!string.IsNullOrEmpty(keyId) && !string.IsNullOrEmpty(secret))
{
return new OrkesAuthenticationSettings(keyId, secret);
}

return null;
}
}
}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ FROM build as test
ARG KEY
ARG SECRET
ARG CONDUCTOR_SERVER_URL
ENV KEY=${KEY}
ENV SECRET=${SECRET}
ENV CONDUCTOR_SERVER_URL=${CONDUCTOR_SERVER_URL}
ENV CONDUCTOR_AUTH_KEY=${KEY}
ENV CONDUCTOR_AUTH_SECRET=${SECRET}
ENV CONDUCTOR_SERVER_URL=${URL}
COPY /csharp-examples /package/csharp-examples
COPY /Tests /package/Tests
WORKDIR /package/Tests
Expand Down

0 comments on commit 312c26f

Please sign in to comment.