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
+ }
0 commit comments