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

Unify environment variable usage. #124

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
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;
jmigueprieto marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ FROM build as test
ARG KEY
ARG SECRET
ARG CONDUCTOR_SERVER_URL
ENV KEY=${KEY}
ENV SECRET=${SECRET}
ENV CONDUCTOR_AUTH_KEY=${KEY}
ENV CONDUCTOR_AUTH_SECRET=${SECRET}
ENV CONDUCTOR_SERVER_URL=${CONDUCTOR_SERVER_URL}
COPY /csharp-examples /package/csharp-examples
COPY /Tests /package/Tests
Expand Down
Loading