Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the ComponentDefinitionCollectionValidator to validate AuthenticationPolicyDefinitions #64

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading