Skip to content

Commit 1facd39

Browse files
committed
fix(Sdk): Changed the way authorization is used and generated
feat(Sdk): Added a new `secrets` runtime expression argument Signed-off-by: Charles d'Avernas <charles.davernas@neuroglia.io>
1 parent 3bc18f7 commit 1facd39

17 files changed

+97
-23
lines changed

src/ServerlessWorkflow.Sdk.Builders/AuthenticationPolicyDefinitionBuilder.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,23 @@ public class AuthenticationPolicyDefinitionBuilder
2020
: IAuthenticationPolicyDefinitionBuilder
2121
{
2222

23+
/// <summary>
24+
/// Gets/sets the name of the <see cref="AuthenticationPolicyDefinition"/> to use, if any
25+
/// </summary>
26+
protected string? Policy { get; set; }
27+
2328
/// <summary>
2429
/// Gets/sets the <see cref="AuthenticationSchemeDefinition"/> to use
2530
/// </summary>
2631
protected IAuthenticationSchemeDefinitionBuilder? SchemeBuilder { get; set; }
2732

33+
/// <inheritdoc/>
34+
public virtual void Use(string policy)
35+
{
36+
ArgumentException.ThrowIfNullOrWhiteSpace(policy);
37+
this.Policy = policy;
38+
}
39+
2840
/// <inheritdoc/>
2941
public virtual IBasicAuthenticationSchemeDefinitionBuilder Basic()
3042
{
@@ -56,6 +68,7 @@ public virtual AuthenticationPolicyDefinition Build()
5668
var scheme = this.SchemeBuilder.Build();
5769
return new()
5870
{
71+
Use = this.Policy,
5972
Basic = scheme is BasicAuthenticationSchemeDefinition basic ? basic : null,
6073
Bearer = scheme is BearerAuthenticationSchemeDefinition bearer ? bearer : null,
6174
OAuth2 = scheme is OAuth2AuthenticationSchemeDefinition oauth2 ? oauth2 : null,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Represents the base class for all <see cref="IAuthenticationSchemeDefinitionBuilder"/> implementations
18+
/// </summary>
19+
/// <typeparam name="TDefinition">The type of the <see cref="AuthenticationSchemeDefinition"/> to build</typeparam>
20+
public abstract class AuthenticationSchemeDefinitionBuilder<TDefinition>
21+
: IAuthenticationSchemeDefinitionBuilder<TDefinition>
22+
where TDefinition : AuthenticationSchemeDefinition
23+
{
24+
25+
/// <summary>
26+
/// Gets the name of the secret to load the authentication scheme definition from
27+
/// </summary>
28+
protected string? Secret { get; private set; }
29+
30+
/// <inheritdoc/>
31+
public virtual void Use(string secret)
32+
{
33+
ArgumentException.ThrowIfNullOrWhiteSpace(secret);
34+
this.Secret = secret;
35+
}
36+
37+
/// <inheritdoc/>
38+
public abstract TDefinition Build();
39+
40+
AuthenticationSchemeDefinition IAuthenticationSchemeDefinitionBuilder.Build() => this.Build();
41+
42+
}

src/ServerlessWorkflow.Sdk.Builders/BasicAuthenticationSchemeDefinitionBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace ServerlessWorkflow.Sdk.Builders;
1717
/// Represents the default implementation of the <see cref="IBasicAuthenticationSchemeDefinitionBuilder"/> interface
1818
/// </summary>
1919
public class BasicAuthenticationSchemeDefinitionBuilder
20-
: IBasicAuthenticationSchemeDefinitionBuilder
20+
: AuthenticationSchemeDefinitionBuilder<BasicAuthenticationSchemeDefinition>, IBasicAuthenticationSchemeDefinitionBuilder
2121
{
2222

2323
/// <summary>
@@ -47,12 +47,13 @@ public virtual IBasicAuthenticationSchemeDefinitionBuilder WithPassword(string p
4747
}
4848

4949
/// <inheritdoc/>
50-
public virtual BasicAuthenticationSchemeDefinition Build()
50+
public override BasicAuthenticationSchemeDefinition Build()
5151
{
5252
if (string.IsNullOrWhiteSpace(this.Username)) throw new NullReferenceException("The username must be set");
5353
if (string.IsNullOrWhiteSpace(this.Password)) throw new NullReferenceException("The password must be set");
5454
return new()
5555
{
56+
Use = this.Secret,
5657
Username = this.Username,
5758
Password = this.Password
5859
};

src/ServerlessWorkflow.Sdk.Builders/BearerAuthenticationSchemeDefinitionBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace ServerlessWorkflow.Sdk.Builders;
1717
/// Represents the default implementation of the <see cref="IBearerAuthenticationSchemeDefinitionBuilder"/> interface
1818
/// </summary>
1919
public class BearerAuthenticationSchemeDefinitionBuilder
20-
: IBearerAuthenticationSchemeDefinitionBuilder
20+
: AuthenticationSchemeDefinitionBuilder<BearerAuthenticationSchemeDefinition>, IBearerAuthenticationSchemeDefinitionBuilder
2121
{
2222

2323
/// <summary>
@@ -34,11 +34,12 @@ public virtual IBearerAuthenticationSchemeDefinitionBuilder WithToken(string tok
3434
}
3535

3636
/// <inheritdoc/>
37-
public virtual BearerAuthenticationSchemeDefinition Build()
37+
public override BearerAuthenticationSchemeDefinition Build()
3838
{
3939
if (string.IsNullOrWhiteSpace(this.Token)) throw new NullReferenceException("The token must be set");
4040
return new()
4141
{
42+
Use = this.Secret,
4243
Token = this.Token
4344
};
4445
}

src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationPolicyDefinitionBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ namespace ServerlessWorkflow.Sdk.Builders;
1919
public interface IAuthenticationPolicyDefinitionBuilder
2020
{
2121

22+
/// <summary>
23+
/// Gets the name of the top-level authentication policy to use
24+
/// </summary>
25+
/// <param name="policy">The name of the top-level authentication to use</param>
26+
void Use(string policy);
27+
2228
/// <summary>
2329
/// Configures the policy to use 'Basic' authentication
2430
/// </summary>

src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationSchemeDefinitionBuilder.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ namespace ServerlessWorkflow.Sdk.Builders;
1919
public interface IAuthenticationSchemeDefinitionBuilder
2020
{
2121

22+
/// <summary>
23+
/// Configures the authentication scheme to load from the specified secret
24+
/// </summary>
25+
/// <param name="secret">The name of the secret that defines the authentication scheme's definition</param>
26+
void Use(string secret);
27+
2228
/// <summary>
2329
/// Builds the configured <see cref="AuthenticationSchemeDefinition"/>
2430
/// </summary>
@@ -30,10 +36,10 @@ public interface IAuthenticationSchemeDefinitionBuilder
3036
/// <summary>
3137
/// Defines the fundamentals of a service used to builder <see cref="AuthenticationSchemeDefinition"/>s
3238
/// </summary>
39+
/// <typeparam name="TDefinition">The type of the <see cref="AuthenticationSchemeDefinition"/> to build</typeparam>
3340
public interface IAuthenticationSchemeDefinitionBuilder<TDefinition>
3441
: IAuthenticationSchemeDefinitionBuilder
3542
where TDefinition : AuthenticationSchemeDefinition
36-
3743
{
3844

3945
/// <summary>

src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowDefinitionBuilder.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,6 @@ public interface IWorkflowDefinitionBuilder
141141
/// <returns>The configured <see cref="IWorkflowDefinitionBuilder"/></returns>
142142
IWorkflowDefinitionBuilder UseSecret(string secret);
143143

144-
/// <summary>
145-
/// Uses the specified secrets
146-
/// </summary>
147-
/// <param name="secrets">A list containing the secrets to use</param>
148-
/// <returns>The configured <see cref="IWorkflowDefinitionBuilder"/></returns>
149-
IWorkflowDefinitionBuilder UseSecrets(params string[] secrets);
150-
151144
/// <summary>
152145
/// Builds the configured <see cref="WorkflowDefinition"/>
153146
/// </summary>

src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationSchemeDefinitionBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace ServerlessWorkflow.Sdk.Builders;
1919
/// Represents the default implementation of the <see cref="IOAuth2AuthenticationSchemeDefinitionBuilder"/> interface
2020
/// </summary>
2121
public class OAuth2AuthenticationSchemeDefinitionBuilder
22-
: IOAuth2AuthenticationSchemeDefinitionBuilder
22+
: AuthenticationSchemeDefinitionBuilder<OAuth2AuthenticationSchemeDefinition>, IOAuth2AuthenticationSchemeDefinitionBuilder
2323
{
2424

2525
/// <summary>
@@ -147,13 +147,14 @@ public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithSubject(OAuth2To
147147
}
148148

149149
/// <inheritdoc/>
150-
public virtual OAuth2AuthenticationSchemeDefinition Build()
150+
public override OAuth2AuthenticationSchemeDefinition Build()
151151
{
152152
if (this.Authority == null) throw new NullReferenceException("The authority must be set");
153153
if (string.IsNullOrWhiteSpace(this.GrantType)) throw new NullReferenceException("The grant type must be set");
154154
if (this.Client == null) throw new NullReferenceException("The client must be set");
155155
return new()
156156
{
157+
Use = this.Secret,
157158
Authority = this.Authority,
158159
Grant = this.GrantType,
159160
Client = this.Client,

src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<VersionPrefix>1.0.0</VersionPrefix>
8-
<VersionSuffix>alpha2.5</VersionSuffix>
8+
<VersionSuffix>alpha2.6</VersionSuffix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<VersionPrefix>1.0.0</VersionPrefix>
8-
<VersionSuffix>alpha2.5</VersionSuffix>
8+
<VersionSuffix>alpha2.6</VersionSuffix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

0 commit comments

Comments
 (0)