1 // Copyright (C) MongoDB, Inc. 2017-present. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Based on github.com/aws/aws-sdk-go by Amazon.com, Inc. with code from: 8 // - github.com/aws/aws-sdk-go/blob/v1.44.225/aws/signer/v4/header_rules.go 9 // See THIRD-PARTY-NOTICES for original license terms 10 11 package v4 12 13 // validator houses a set of rule needed for validation of a 14 // string value 15 type rules []rule 16 17 // rule interface allows for more flexible rules and just simply 18 // checks whether or not a value adheres to that rule 19 type rule interface { 20 IsValid(value string) bool 21 } 22 23 // IsValid will iterate through all rules and see if any rules 24 // apply to the value and supports nested rules 25 func (r rules) IsValid(value string) bool { 26 for _, rule := range r { 27 if rule.IsValid(value) { 28 return true 29 } 30 } 31 return false 32 } 33 34 // mapRule generic rule for maps 35 type mapRule map[string]struct{} 36 37 // IsValid for the map rule satisfies whether it exists in the map 38 func (m mapRule) IsValid(value string) bool { 39 _, ok := m[value] 40 return ok 41 } 42 43 // excludeList is a generic rule for exclude listing 44 type excludeList struct { 45 rule 46 } 47 48 // IsValid for exclude list checks if the value is within the exclude list 49 func (b excludeList) IsValid(value string) bool { 50 return !b.rule.IsValid(value) 51 } 52