From ebb72a70c6140a2d9b035609694fa065811606ec Mon Sep 17 00:00:00 2001 From: ShawnAbshire Date: Thu, 2 Nov 2023 21:12:17 -0500 Subject: [PATCH 1/2] feat(multitenancy): Updated DeployResourceCommand to support TenantId. --- Client.UnitTests/DeploymentTest.cs | 26 +++++++++++++++++++ .../Commands/IDeployResourceCommandStep1.cs | 2 +- Client/Api/Commands/ITenantIdCommandStep.cs | 13 ++++++++++ Client/Impl/Commands/DeployResourceCommand.cs | 6 +++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Client/Api/Commands/ITenantIdCommandStep.cs diff --git a/Client.UnitTests/DeploymentTest.cs b/Client.UnitTests/DeploymentTest.cs index 02a09351..07f0ee88 100644 --- a/Client.UnitTests/DeploymentTest.cs +++ b/Client.UnitTests/DeploymentTest.cs @@ -339,5 +339,31 @@ public async Task ShouldSendMultipleDeployResourceAndGetResponseAsExpected() Assert.AreEqual("nameRequirement", decisionRequirementsMetadata.DmnDecisionRequirementsName); Assert.AreEqual("id", decisionRequirementsMetadata.DmnDecisionRequirementsId); } + + [Test] + public async Task ShouldSetTenantIdAsExpected() + { + // given + var expectedRequest = new DeployResourceRequest + { + TenantId = "1234", + Resources = + { + new Resource + { + Content = ByteString.FromStream(File.OpenRead(_demoProcessPath)), + Name = _demoProcessPath + } + } + }; + + // when + await ZeebeClient.NewDeployCommand().AddTenantId("1234").AddResourceFile(_demoProcessPath).Send(); + + // then + var actualRequest = TestService.Requests[typeof(DeployResourceRequest)][0]; + + Assert.AreEqual(expectedRequest, actualRequest); + } } } diff --git a/Client/Api/Commands/IDeployResourceCommandStep1.cs b/Client/Api/Commands/IDeployResourceCommandStep1.cs index 4e106904..ab92171b 100644 --- a/Client/Api/Commands/IDeployResourceCommandStep1.cs +++ b/Client/Api/Commands/IDeployResourceCommandStep1.cs @@ -18,7 +18,7 @@ namespace Zeebe.Client.Api.Commands { - public interface IDeployResourceCommandStep1 + public interface IDeployResourceCommandStep1 : ITenantIdCommandStep { /// /// Add the given resource to the deployment. diff --git a/Client/Api/Commands/ITenantIdCommandStep.cs b/Client/Api/Commands/ITenantIdCommandStep.cs new file mode 100644 index 00000000..b4802150 --- /dev/null +++ b/Client/Api/Commands/ITenantIdCommandStep.cs @@ -0,0 +1,13 @@ +namespace Zeebe.Client.Api.Commands +{ + public interface ITenantIdCommandStep + { + /// + /// Set the tenantId for the resource. + /// + /// the tenantId to associate to this resource + /// The builder for this command. Call to complete the command and send it + /// to the broker. + T AddTenantId(string tenantId); + } +} \ No newline at end of file diff --git a/Client/Impl/Commands/DeployResourceCommand.cs b/Client/Impl/Commands/DeployResourceCommand.cs index 5650e859..d947efdb 100644 --- a/Client/Impl/Commands/DeployResourceCommand.cs +++ b/Client/Impl/Commands/DeployResourceCommand.cs @@ -73,6 +73,12 @@ public IDeployResourceCommandBuilderStep2 AddResourceStringUtf8(string resourceS return this; } + public IDeployResourceCommandBuilderStep2 AddTenantId(string tenantId) + { + request.TenantId = tenantId; + return this; + } + public async Task Send(TimeSpan? timeout = null, CancellationToken token = default) { var asyncReply = gatewayClient.DeployResourceAsync(request, deadline: timeout?.FromUtcNow(), cancellationToken: token); From 77f503dd7b116e3782c2bbc0b9f34369d6ab2c15 Mon Sep 17 00:00:00 2001 From: ShawnAbshire Date: Sun, 12 Nov 2023 23:54:38 -0600 Subject: [PATCH 2/2] refactor(mutitenancy): Move ITenantIdCommandStep to before the final step. --- Client.UnitTests/DeploymentTest.cs | 2 +- Client/Api/Commands/IDeployResourceCommandStep1.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Client.UnitTests/DeploymentTest.cs b/Client.UnitTests/DeploymentTest.cs index 07f0ee88..06df67d7 100644 --- a/Client.UnitTests/DeploymentTest.cs +++ b/Client.UnitTests/DeploymentTest.cs @@ -358,7 +358,7 @@ public async Task ShouldSetTenantIdAsExpected() }; // when - await ZeebeClient.NewDeployCommand().AddTenantId("1234").AddResourceFile(_demoProcessPath).Send(); + await ZeebeClient.NewDeployCommand().AddResourceFile(_demoProcessPath).AddTenantId("1234").Send(); // then var actualRequest = TestService.Requests[typeof(DeployResourceRequest)][0]; diff --git a/Client/Api/Commands/IDeployResourceCommandStep1.cs b/Client/Api/Commands/IDeployResourceCommandStep1.cs index ab92171b..8e09cb97 100644 --- a/Client/Api/Commands/IDeployResourceCommandStep1.cs +++ b/Client/Api/Commands/IDeployResourceCommandStep1.cs @@ -18,7 +18,7 @@ namespace Zeebe.Client.Api.Commands { - public interface IDeployResourceCommandStep1 : ITenantIdCommandStep + public interface IDeployResourceCommandStep1 { /// /// Add the given resource to the deployment. @@ -70,7 +70,7 @@ IDeployResourceCommandBuilderStep2 AddResourceStream( IDeployResourceCommandBuilderStep2 AddResourceFile(string filename); } - public interface IDeployResourceCommandBuilderStep2 : IDeployResourceCommandStep1, IFinalCommandWithRetryStep + public interface IDeployResourceCommandBuilderStep2 : IDeployResourceCommandStep1, ITenantIdCommandStep, IFinalCommandWithRetryStep { // the place for new optional parameters }