Skip to content

Commit

Permalink
fix(Dsl): Fixed the ComponentDefinitionCollectionValidator to valid…
Browse files Browse the repository at this point in the history
…ate `AuthenticationPolicyDefinitions`

Signed-off-by: Charles d'Avernas <[email protected]>
  • Loading branch information
cdavernas committed Oct 22, 2024
1 parent eb9c1e3 commit da6ee55
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
2 changes: 1 addition & 1 deletion src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright © 2024-Present The Serverless Workflow Specification Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using FluentValidation;
using ServerlessWorkflow.Sdk.Models;

namespace ServerlessWorkflow.Sdk.Validation;

/// <summary>
/// Represents the <see cref="IValidator"/> used to validate <see cref="AuthenticationPolicyDefinition"/> key/value pairs
/// </summary>
public class AuthenticationPolicyKeyValuePairValidator
: AbstractValidator<KeyValuePair<string, AuthenticationPolicyDefinition>>
{

/// <inheritdoc/>
public AuthenticationPolicyKeyValuePairValidator(IServiceProvider serviceProvider, ComponentDefinitionCollection? components)
{
this.ServiceProvider = serviceProvider;
this.Components = components;
this.RuleFor(t => t.Value)
.Custom((value, context) =>
{
var key = context.InstanceToValidate.Key;
var validator = new AuthenticationPolicyDefinitionValidator(serviceProvider, components);
var validationResult = validator.Validate(value);
foreach (var error in validationResult.Errors) context.AddFailure($"{key}.{error.PropertyName}", error.ErrorMessage);
});
}

/// <summary>
/// Gets the current <see cref="IServiceProvider"/>
/// </summary>
protected IServiceProvider ServiceProvider { get; }

/// <summary>
/// Gets the configured reusable components
/// </summary>
protected ComponentDefinitionCollection? Components { get; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class ComponentDefinitionCollectionValidator
public ComponentDefinitionCollectionValidator(IServiceProvider serviceProvider)
{
this.ServiceProvider = serviceProvider;
this.RuleForEach(c => c.Authentications)
.SetValidator(c => new AuthenticationPolicyKeyValuePairValidator(this.ServiceProvider, c));
this.RuleForEach(c => c.Functions)
.SetValidator(c => new TaskKeyValuePairValidator(this.ServiceProvider, c, c.Functions));
}
Expand Down

0 comments on commit da6ee55

Please sign in to comment.