diff --git a/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj b/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj index 642bb56..fe79026 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj +++ b/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj @@ -5,7 +5,7 @@ enable enable 1.0.0 - alpha4 + alpha4.1 $(VersionPrefix) $(VersionPrefix) en diff --git a/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj b/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj index 08fb9e1..201d021 100644 --- a/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj +++ b/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj @@ -5,7 +5,7 @@ enable enable 1.0.0 - alpha4 + alpha4.1 $(VersionPrefix) $(VersionPrefix) en diff --git a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj index 823428d..5d8ecc0 100644 --- a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj +++ b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj @@ -5,7 +5,7 @@ enable enable 1.0.0 - alpha4 + alpha4.1 $(VersionPrefix) $(VersionPrefix) en diff --git a/src/ServerlessWorkflow.Sdk/Validation/AuthenticationPolicyKeyValuePairValidator.cs b/src/ServerlessWorkflow.Sdk/Validation/AuthenticationPolicyKeyValuePairValidator.cs new file mode 100644 index 0000000..8a2b1ca --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Validation/AuthenticationPolicyKeyValuePairValidator.cs @@ -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; + +/// +/// Represents the used to validate key/value pairs +/// +public class AuthenticationPolicyKeyValuePairValidator + : AbstractValidator> +{ + + /// + 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); + }); + } + + /// + /// Gets the current + /// + protected IServiceProvider ServiceProvider { get; } + + /// + /// Gets the configured reusable components + /// + protected ComponentDefinitionCollection? Components { get; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Validation/ComponentDefinitionCollectionValidator.cs b/src/ServerlessWorkflow.Sdk/Validation/ComponentDefinitionCollectionValidator.cs index 6a68df5..1e2045d 100644 --- a/src/ServerlessWorkflow.Sdk/Validation/ComponentDefinitionCollectionValidator.cs +++ b/src/ServerlessWorkflow.Sdk/Validation/ComponentDefinitionCollectionValidator.cs @@ -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)); }