Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update .NET SDK to 1.3.1 and add proxy tests #536

Merged
merged 4 commits into from
Sep 12, 2024
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
3 changes: 3 additions & 0 deletions cmd/run_dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (r *Runner) RunDotNetExternal(ctx context.Context, run *cmd.Run) error {
if r.config.ClientCertPath != "" {
args = append(args, "--client-cert-path", r.config.ClientCertPath, "--client-key-path", r.config.ClientKeyPath)
}
if r.config.HTTPProxyURL != "" {
args = append(args, "--http-proxy-url", r.config.HTTPProxyURL)
}
args = append(args, run.ToArgs()...)
cmd, err := r.program.NewCommand(ctx, args...)
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Temporalio" Version="1.3.0">
<PackageReference Include="Temporalio" Version="1.3.1">
<!--
We have to make sure this isn't included transitively so it can be
overridden.
Expand Down
33 changes: 33 additions & 0 deletions features/client/http_proxy/feature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace client.http_proxy;

using Temporalio.Client;
using Temporalio.Features.Harness;
using Temporalio.Worker;
using Temporalio.Workflows;

class Feature : IFeature
{
public static void ConfigureClient(
Runner runner, TemporalClientConnectOptions options, bool useAuth)
{
var uri = new Uri(runner.HttpProxyUrl ?? throw new InvalidOperationException("Missing proxy URL"));
options.HttpConnectProxy = new() { TargetHost = $"{uri.Host}:{uri.Port}" };
if (useAuth)
{
options.HttpConnectProxy!.BasicAuth = ("proxy-user", "proxy-pass");
}
}

public void ConfigureClient(Runner runner, TemporalClientConnectOptions options) =>
ConfigureClient(runner, options, useAuth: false);

public void ConfigureWorker(Runner runner, TemporalWorkerOptions options) =>
options.AddWorkflow<MyWorkflow>();

[Workflow]
class MyWorkflow
{
[WorkflowRun]
public async Task<string> RunAsync() => "done";
}
}
22 changes: 22 additions & 0 deletions features/client/http_proxy_auth/feature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace client.http_proxy_auth;

using Temporalio.Client;
using Temporalio.Features.Harness;
using Temporalio.Worker;
using Temporalio.Workflows;

class Feature : IFeature
{
public void ConfigureClient(Runner runner, TemporalClientConnectOptions options) =>
http_proxy.Feature.ConfigureClient(runner, options, useAuth: true);

public void ConfigureWorker(Runner runner, TemporalWorkerOptions options) =>
options.AddWorkflow<MyWorkflow>();

[Workflow]
class MyWorkflow
{
[WorkflowRun]
public async Task<string> RunAsync() => "done";
}
}
14 changes: 12 additions & 2 deletions harness/dotnet/Temporalio.Features.Harness/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public static class App
name: "--client-key-path",
description: "Path to a client key for TLS");

private static readonly Option<string?> httpProxyUrlOption = new(
name: "--http-proxy-url",
description: "HTTP proxy URL");

private static readonly Argument<List<(string, string)>> featuresArgument = new(
name: "features",
parse: result => result.Tokens.Select(token =>
Expand Down Expand Up @@ -56,6 +60,7 @@ private static Command CreateCommand()
cmd.AddOption(namespaceOption);
cmd.AddOption(clientCertPathOption);
cmd.AddOption(clientKeyPathOption);
cmd.AddOption(httpProxyUrlOption);
cmd.AddArgument(featuresArgument);
cmd.SetHandler(RunCommandAsync);
return cmd;
Expand Down Expand Up @@ -98,8 +103,13 @@ private static async Task RunCommandAsync(InvocationContext ctx)
throw new InvalidOperationException($"Unable to find feature for dir {dir}");
try
{
await new Runner(clientOptions, taskQueue, feature, loggerFactory).RunAsync(
ctx.GetCancellationToken());
await new Runner(
clientOptions,
taskQueue,
feature,
loggerFactory,
ctx.ParseResult.GetValueForOption(httpProxyUrlOption)
).RunAsync(ctx.GetCancellationToken());
}
catch (TestSkippedException e)
{
Expand Down
6 changes: 5 additions & 1 deletion harness/dotnet/Temporalio.Features.Harness/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ internal Runner(
TemporalClientConnectOptions clientConnectOptions,
string taskQueue,
PreparedFeature feature,
ILoggerFactory loggerFactory)
ILoggerFactory loggerFactory,
string? httpProxyUrl)
{
PreparedFeature = feature;
Logger = loggerFactory.CreateLogger(PreparedFeature.FeatureType);
Feature = (IFeature)Activator.CreateInstance(PreparedFeature.FeatureType, true)!;
HttpProxyUrl = httpProxyUrl;

ClientOptions = (TemporalClientConnectOptions)clientConnectOptions.Clone();
Feature.ConfigureClient(this, ClientOptions);
Expand All @@ -71,6 +73,8 @@ internal Runner(

public TemporalWorkerOptions WorkerOptions { get; private init; }

public string? HttpProxyUrl { get; private init; }

/// <summary>
/// Run the feature with the given cancellation token.
/// </summary>
Expand Down
Loading