Skip to content

Commit

Permalink
Merge pull request #61 from conductor-sdk/fix-readme
Browse files Browse the repository at this point in the history
Fixed README to be up to date
  • Loading branch information
gardusig authored Mar 22, 2023
2 parents 85a1f31 + 780b99d commit ce7050e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static IServiceCollection AddConductorWorker(this IServiceCollection serv
services.AddOptions();
if (configuration == null)
{
configuration = Configuration.Default;
configuration = new Configuration();
}
services.AddSingleton<Configuration>(configuration);
services.AddSingleton<IWorkflowTaskClient, WorkflowTaskHttpClient>();
Expand Down
23 changes: 23 additions & 0 deletions Conductor/Client/OrkesApiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Conductor.Client.Authentication;

namespace Conductor.Client
{
public class OrkesApiClient
{
private Configuration _configuration = null;

public OrkesApiClient(Configuration configuration, OrkesAuthenticationSettings orkesAuthenticationSettings)
{
_configuration = configuration;
if (orkesAuthenticationSettings != null)
{
configuration.AuthenticationSettings = orkesAuthenticationSettings;
}
}

public T GetClient<T>() where T : IApiAccessor, new()
{
return _configuration.GetClient<T>();
}
}
}
27 changes: 9 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,16 @@ See [Access Control](https://orkes.io/content/docs/getting-started/concepts/acce

### Configure API Client
```csharp
OrkesApiClient GetApiClient(string basePath, string keyId, string keySecret)
{
return new OrkesApiClient(
configuration: new Configuration()
{
BasePath = basePath
},
authenticationSettings: new OrkesAuthenticationSettings(
keyId, keySecret
)
);
}
using Conductor.Api;
using Conductor.Client;
using Conductor.Client.Authentication;

OrkesApiClient apiClient = GetApiClient(
basePath: "https://play.orkes.io/api",
keyId: "key",
keySecret: "secret"
);
WorkflowResourceApi workflowClient = apiClient.GetClient<WorkflowResourceApi>();
var configuration = new Configuration() {
BasePath = basePath,
AuthenticationSettings = new OrkesAuthenticationSettings(keyId, keySecret)
};

var workflowClient = configuration.GetClient<WorkflowResourceApi>();

workflowClient.StartWorkflow(
name: "test-sdk-csharp-workflow",
Expand Down
22 changes: 22 additions & 0 deletions Tests/Client/OrkesApiClientTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Conductor.Api;
using Conductor.Client;
using Tests.Util;
using Xunit;

namespace Tests.Client
{
public class OrkesApiClientTest
{
[Fact]
public void TestOrkesApiClient()
{
var configuration = ApiUtil.GetConfiguration();
var orkesApiClient = new OrkesApiClient(configuration, null);
var workflowClient = orkesApiClient.GetClient<WorkflowResourceApi>();
var expectedWorkflowClient = configuration.GetClient<WorkflowResourceApi>();
var token = workflowClient.Configuration.AccessToken;
var expectedToken = expectedWorkflowClient.Configuration.AccessToken;
Assert.Equal(expectedToken, token);
}
}
}
24 changes: 16 additions & 8 deletions Tests/Util/ApiUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ public class ApiUtil
private const string ENV_KEY_ID = "KEY";
private const string ENV_SECRET = "SECRET";

private static Configuration _configuration = null;

static ApiUtil()
{
var configuration = new Configuration();
configuration.BasePath = GetEnvironmentVariable(ENV_ROOT_URI);
configuration.Timeout = 5000;
configuration.AuthenticationSettings = new OrkesAuthenticationSettings(
GetEnvironmentVariable(ENV_KEY_ID),
GetEnvironmentVariable(ENV_SECRET));
Configuration.Default = configuration;
_configuration = new Configuration()
{
Timeout = 30000,
BasePath = GetEnvironmentVariable(ENV_ROOT_URI),
AuthenticationSettings = new OrkesAuthenticationSettings(
GetEnvironmentVariable(ENV_KEY_ID),
GetEnvironmentVariable(ENV_SECRET))
};
}

public static WorkflowExecutor GetWorkflowExecutor()
Expand All @@ -34,7 +37,12 @@ public static WorkflowExecutor GetWorkflowExecutor()

public static T GetClient<T>() where T : IApiAccessor, new()
{
return Configuration.Default.GetClient<T>();
return _configuration.GetClient<T>();
}

public static Configuration GetConfiguration()
{
return _configuration;
}

private static string GetEnvironmentVariable(string variable)
Expand Down
2 changes: 1 addition & 1 deletion Tests/Util/WorkerUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static IHost GetWorkerHost()
.ConfigureServices(
(ctx, services) =>
{
services.AddConductorWorker();
services.AddConductorWorker(ApiUtil.GetConfiguration());
services.AddConductorWorkflowTask<SimpleWorker>();
services.WithHostedService<WorkerService>();
}
Expand Down

0 comments on commit ce7050e

Please sign in to comment.