Skip to content

Commit

Permalink
- Allow a custom configuration in ApiExtensions
Browse files Browse the repository at this point in the history
- Lazily initialize from Environment variables if no custom config
- Improve unset env variable error message
  • Loading branch information
jmigueprieto committed Dec 4, 2024
1 parent 7797293 commit 27201d3
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions Conductor/Client/Extensions/ApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using Conductor.Executor;
using Conductor.Client.Authentication;
using System;
using System.Diagnostics;

namespace Conductor.Client.Extensions
{
Expand All @@ -25,20 +24,25 @@ public class ApiExtensions
private const string ENV_SECRET = "SECRET";
private const int REST_CLIENT_REQUEST_TIME_OUT = 30 * 1000;

public static Configuration Configuration { get; set; }

static ApiExtensions()
{
Configuration = new Configuration(REST_CLIENT_REQUEST_TIME_OUT)
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)
)
};
GetEnvironmentVariable(ENV_KEY_ID),
GetEnvironmentVariable(ENV_SECRET)
)
});

private static Configuration _customConfiguration;

public static Configuration Configuration
{
get => _customConfiguration ?? _lazyConfiguration.Value;
set => _customConfiguration = value;
}


public static WorkflowExecutor GetWorkflowExecutor()
{
return new WorkflowExecutor(
Expand Down Expand Up @@ -66,9 +70,7 @@ public static string GetWorkflowExecutionURL(string workflowId)

private static string GetEnvironmentVariable(string variable)
{
string value = Environment.GetEnvironmentVariable(variable);
Debug.Assert(value != null);
return value;
return Environment.GetEnvironmentVariable(variable) ?? throw new InvalidOperationException($"Environment variable '{variable}' is not set.");
}
}
}

0 comments on commit 27201d3

Please sign in to comment.