Skip to content

Commit 6eab8a1

Browse files
committed
fix(Sdk): Fixed the ExternalResourceDefinition to implement changes introduced by serverlessworkflow/specification#975
Signed-off-by: Charles d'Avernas <charles.davernas@neuroglia.io>
1 parent 73a219f commit 6eab8a1

File tree

8 files changed

+123
-50
lines changed

8 files changed

+123
-50
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 default implementation of the <see cref="IEndpointDefinitionBuilder"/> interface
18+
/// </summary>
19+
public class EndpointDefinitionBuilder
20+
: IEndpointDefinitionBuilder
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the uri that references the external resource
25+
/// </summary>
26+
protected virtual Uri? Uri { get; set; }
27+
28+
/// <summary>
29+
/// Gets/sets a reference to the authentication policy to use
30+
/// </summary>
31+
protected virtual Uri? AuthenticationReference { get; set; }
32+
33+
/// <summary>
34+
/// Gets/sets the authentication policy to use
35+
/// </summary>
36+
protected virtual AuthenticationPolicyDefinition? Authentication { get; set; }
37+
38+
/// <inheritdoc/>
39+
public virtual IEndpointDefinitionBuilder WithUri(Uri uri)
40+
{
41+
ArgumentNullException.ThrowIfNull(uri);
42+
this.Uri = uri;
43+
return this;
44+
}
45+
46+
/// <inheritdoc/>
47+
public virtual IEndpointDefinitionBuilder UseAuthentication(Uri reference)
48+
{
49+
ArgumentNullException.ThrowIfNull(reference);
50+
this.AuthenticationReference = reference;
51+
return this;
52+
}
53+
54+
/// <inheritdoc/>
55+
public virtual IEndpointDefinitionBuilder UseAuthentication(AuthenticationPolicyDefinition authentication)
56+
{
57+
ArgumentNullException.ThrowIfNull(authentication);
58+
this.Authentication = authentication;
59+
return this;
60+
}
61+
62+
/// <inheritdoc/>
63+
public virtual IEndpointDefinitionBuilder UseAuthentication(Action<IAuthenticationPolicyDefinitionBuilder> setup)
64+
{
65+
ArgumentNullException.ThrowIfNull(setup);
66+
var builder = new AuthenticationPolicyDefinitionBuilder();
67+
setup(builder);
68+
this.Authentication = builder.Build();
69+
return this;
70+
}
71+
72+
/// <inheritdoc/>
73+
public virtual EndpointDefinition Build()
74+
{
75+
if (this.Uri == null) throw new NullReferenceException("The uri that references the external resource must be set");
76+
var endpoint = new EndpointDefinition()
77+
{
78+
Uri = this.Uri
79+
};
80+
if (this.AuthenticationReference == null) endpoint.Authentication = new() { Ref = this.AuthenticationReference };
81+
else if (this.Authentication != null) endpoint.Authentication = this.Authentication;
82+
return endpoint;
83+
}
84+
85+
}

src/ServerlessWorkflow.Sdk.Builders/ExternalResourceDefinitionBuilder.cs

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,9 @@ public class ExternalResourceDefinitionBuilder
2626
protected virtual string? Name { get; set; }
2727

2828
/// <summary>
29-
/// Gets/sets the uri that references the external resource
29+
/// Gets/sets the endpoint at which to get the defined resource
3030
/// </summary>
31-
protected virtual Uri? Uri { get; set; }
32-
33-
/// <summary>
34-
/// Gets/sets a reference to the authentication policy to use
35-
/// </summary>
36-
protected virtual Uri? AuthenticationReference { get; set; }
37-
38-
/// <summary>
39-
/// Gets/sets the authentication policy to use
40-
/// </summary>
41-
protected virtual AuthenticationPolicyDefinition? Authentication { get; set; }
31+
protected virtual OneOf<EndpointDefinition, Uri>? Endpoint { get; set; }
4232

4333
/// <inheritdoc/>
4434
public virtual IExternalResourceDefinitionBuilder WithName(string name)
@@ -48,53 +38,33 @@ public virtual IExternalResourceDefinitionBuilder WithName(string name)
4838
}
4939

5040
/// <inheritdoc/>
51-
public virtual IExternalResourceDefinitionBuilder WithUri(Uri uri)
41+
public virtual IExternalResourceDefinitionBuilder WithEndpoint(OneOf<EndpointDefinition, Uri> endpoint)
5242
{
53-
ArgumentNullException.ThrowIfNull(uri);
54-
this.Uri = uri;
43+
ArgumentNullException.ThrowIfNull(endpoint);
44+
this.Endpoint = endpoint;
5545
return this;
5646
}
5747

5848
/// <inheritdoc/>
59-
public virtual IExternalResourceDefinitionBuilder UseAuthentication(Uri reference)
60-
{
61-
ArgumentNullException.ThrowIfNull(reference);
62-
this.AuthenticationReference = reference;
63-
return this;
64-
}
65-
66-
/// <inheritdoc/>
67-
public virtual IExternalResourceDefinitionBuilder UseAuthentication(AuthenticationPolicyDefinition authentication)
68-
{
69-
ArgumentNullException.ThrowIfNull(authentication);
70-
this.Authentication = authentication;
71-
return this;
72-
}
73-
74-
/// <inheritdoc/>
75-
public virtual IExternalResourceDefinitionBuilder UseAuthentication(Action<IAuthenticationPolicyDefinitionBuilder> setup)
49+
public virtual IExternalResourceDefinitionBuilder WithEndpoint(Action<IEndpointDefinitionBuilder> setup)
7650
{
7751
ArgumentNullException.ThrowIfNull(setup);
78-
var builder = new AuthenticationPolicyDefinitionBuilder();
52+
var builder = new EndpointDefinitionBuilder();
7953
setup(builder);
80-
this.Authentication = builder.Build();
54+
this.Endpoint = builder.Build();
8155
return this;
8256
}
8357

8458
/// <inheritdoc/>
8559
public virtual ExternalResourceDefinition Build()
8660
{
87-
if (this.Uri == null) throw new NullReferenceException("The uri that references the external resource must be set");
88-
var reference = new ExternalResourceDefinition()
61+
if (this.Endpoint == null) throw new NullReferenceException("The endpoint at which to get the defined resource must be set");
62+
var externalResource = new ExternalResourceDefinition()
8963
{
9064
Name = this.Name,
91-
Uri = this.Uri
65+
Endpoint = this.Endpoint
9266
};
93-
if (this.AuthenticationReference == null) reference.Authentication = new() { Ref = this.AuthenticationReference };
94-
else if (this.Authentication != null) reference.Authentication = this.Authentication;
95-
return reference;
67+
return externalResource;
9668
}
9769

98-
EndpointDefinition IEndpointDefinitionBuilder<IExternalResourceDefinitionBuilder>.Build() => this.Build();
99-
10070
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace ServerlessWorkflow.Sdk.Builders;
1717
/// Defines the fundamentals of a service used to build <see cref="ExternalResourceDefinition"/>s
1818
/// </summary>
1919
public interface IExternalResourceDefinitionBuilder
20-
: IEndpointDefinitionBuilder<IExternalResourceDefinitionBuilder>
2120
{
2221

2322
/// <summary>
@@ -27,10 +26,24 @@ public interface IExternalResourceDefinitionBuilder
2726
/// <returns>The configured <see cref="IExternalResourceDefinitionBuilder"/></returns>
2827
IExternalResourceDefinitionBuilder WithName(string name);
2928

29+
/// <summary>
30+
/// Configures the endpoint at which to get the defined resource
31+
/// </summary>
32+
/// <param name="endpoint">The endpoint at which to get the defined resource</param>
33+
/// <returns>The configured <see cref="IExternalResourceDefinitionBuilder"/></returns>
34+
IExternalResourceDefinitionBuilder WithEndpoint(OneOf<EndpointDefinition, Uri> endpoint);
35+
36+
/// <summary>
37+
/// Configures the endpoint at which to get the defined resource.
38+
/// </summary>
39+
/// <param name="setup">An <see cref="Action{T}"/> used to setup the endpoint at which to get the defined resource.</param>
40+
/// <returns>The configured <see cref="IExternalResourceDefinitionBuilder"/></returns>
41+
IExternalResourceDefinitionBuilder WithEndpoint(Action<IEndpointDefinitionBuilder> setup);
42+
3043
/// <summary>
3144
/// Builds the configured <see cref="ExternalResourceDefinition"/>
3245
/// </summary>
3346
/// <returns>A new <see cref="ExternalResourceDefinition"/></returns>
34-
new ExternalResourceDefinition Build();
47+
ExternalResourceDefinition Build();
3548

3649
}

src/ServerlessWorkflow.Sdk.Builders/ScriptProcessDefinitionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public override ScriptProcessDefinition Build()
134134
Environment = this.Environment
135135
};
136136
if(this.Source != null) process.Source = this.Source;
137-
else if(this.SourceUri != null) process.Source = new() { Uri = this.SourceUri };
137+
else if(this.SourceUri != null) process.Source = new() { Endpoint = this.SourceUri };
138138
return process;
139139
}
140140

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.9</VersionSuffix>
8+
<VersionSuffix>alpha2.10</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.9</VersionSuffix>
8+
<VersionSuffix>alpha2.10</VersionSuffix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/ServerlessWorkflow.Sdk/Models/ExternalResourceDefinition.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ namespace ServerlessWorkflow.Sdk.Models;
1818
/// </summary>
1919
[DataContract]
2020
public record ExternalResourceDefinition
21-
: EndpointDefinition
2221
{
2322

2423
/// <summary>
2524
/// Gets/sets the external resource's name, if any
2625
/// </summary>
27-
[Required]
2826
[DataMember(Name = "name", Order = 1), JsonPropertyName("name"), JsonPropertyOrder(1), YamlMember(Alias = "name", Order = 1)]
2927
public virtual string? Name { get; set; }
3028

29+
/// <summary>
30+
/// Gets/sets the endpoint at which to get the defined resource
31+
/// </summary>
32+
[Required]
33+
[DataMember(Name = "endpoint", Order = 2), JsonPropertyName("endpoint"), JsonPropertyOrder(2), YamlMember(Alias = "endpoint", Order = 2)]
34+
public virtual OneOf<EndpointDefinition, Uri> Endpoint { get; set; } = null!;
35+
3136
}

src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.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.9</VersionSuffix>
8+
<VersionSuffix>alpha2.10</VersionSuffix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy