Skip to content

Commit da6ee55

Browse files
committed
fix(Dsl): Fixed the ComponentDefinitionCollectionValidator to validate AuthenticationPolicyDefinitions
Signed-off-by: Charles d'Avernas <charles.davernas@neuroglia.io>
1 parent eb9c1e3 commit da6ee55

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

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

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>alpha4</VersionSuffix>
8+
<VersionSuffix>alpha4.1</VersionSuffix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
using FluentValidation;
15+
using ServerlessWorkflow.Sdk.Models;
16+
17+
namespace ServerlessWorkflow.Sdk.Validation;
18+
19+
/// <summary>
20+
/// Represents the <see cref="IValidator"/> used to validate <see cref="AuthenticationPolicyDefinition"/> key/value pairs
21+
/// </summary>
22+
public class AuthenticationPolicyKeyValuePairValidator
23+
: AbstractValidator<KeyValuePair<string, AuthenticationPolicyDefinition>>
24+
{
25+
26+
/// <inheritdoc/>
27+
public AuthenticationPolicyKeyValuePairValidator(IServiceProvider serviceProvider, ComponentDefinitionCollection? components)
28+
{
29+
this.ServiceProvider = serviceProvider;
30+
this.Components = components;
31+
this.RuleFor(t => t.Value)
32+
.Custom((value, context) =>
33+
{
34+
var key = context.InstanceToValidate.Key;
35+
var validator = new AuthenticationPolicyDefinitionValidator(serviceProvider, components);
36+
var validationResult = validator.Validate(value);
37+
foreach (var error in validationResult.Errors) context.AddFailure($"{key}.{error.PropertyName}", error.ErrorMessage);
38+
});
39+
}
40+
41+
/// <summary>
42+
/// Gets the current <see cref="IServiceProvider"/>
43+
/// </summary>
44+
protected IServiceProvider ServiceProvider { get; }
45+
46+
/// <summary>
47+
/// Gets the configured reusable components
48+
/// </summary>
49+
protected ComponentDefinitionCollection? Components { get; }
50+
51+
}

src/ServerlessWorkflow.Sdk/Validation/ComponentDefinitionCollectionValidator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class ComponentDefinitionCollectionValidator
2727
public ComponentDefinitionCollectionValidator(IServiceProvider serviceProvider)
2828
{
2929
this.ServiceProvider = serviceProvider;
30+
this.RuleForEach(c => c.Authentications)
31+
.SetValidator(c => new AuthenticationPolicyKeyValuePairValidator(this.ServiceProvider, c));
3032
this.RuleForEach(c => c.Functions)
3133
.SetValidator(c => new TaskKeyValuePairValidator(this.ServiceProvider, c, c.Functions));
3234
}

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