github.com/Venafi/vcert/v5@v5.10.2/pkg/util/issuerHint.go (about) 1 /* 2 * Copyright 2023 Venafi, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package util 18 19 import ( 20 "strings" 21 22 "gopkg.in/yaml.v3" 23 ) 24 25 type IssuerHint int 26 27 const ( 28 IssuerHintGeneric IssuerHint = iota 29 IssuerHintMicrosoft 30 IssuerHintDigicert 31 IssuerHintEntrust 32 IssuerHintAllIssuers 33 34 strIssuerHintMicrosoft = "MICROSOFT" 35 strIssuerHintDigicert = "DIGICERT" 36 strIssuerHintEntrust = "ENTRUST" 37 strIssuerHintAll = "ALL_ISSUERS" 38 ) 39 40 // String returns a string representation of this object 41 func (i *IssuerHint) String() string { 42 switch *i { 43 case IssuerHintMicrosoft: 44 return strIssuerHintMicrosoft 45 case IssuerHintDigicert: 46 return strIssuerHintDigicert 47 case IssuerHintEntrust: 48 return strIssuerHintEntrust 49 case IssuerHintAllIssuers: 50 return strIssuerHintAll 51 default: 52 return "" 53 } 54 } 55 56 // MarshalYAML customizes the behavior of ChainOption when being marshaled into a YAML document. 57 // The returned value is marshaled in place of the original value implementing Marshaller 58 func (i IssuerHint) MarshalYAML() (interface{}, error) { 59 return i.String(), nil 60 } 61 62 // UnmarshalYAML customizes the behavior when being unmarshalled from a YAML document 63 func (i *IssuerHint) UnmarshalYAML(value *yaml.Node) error { 64 var strValue string 65 err := value.Decode(&strValue) 66 if err != nil { 67 return err 68 } 69 *i, err = parseInstallationType(strValue) 70 if err != nil { 71 return err 72 } 73 return nil 74 } 75 76 func parseInstallationType(issuerHint string) (IssuerHint, error) { 77 switch strings.ToUpper(issuerHint) { 78 case strIssuerHintMicrosoft: 79 return IssuerHintMicrosoft, nil 80 case strIssuerHintDigicert: 81 return IssuerHintDigicert, nil 82 case strIssuerHintEntrust: 83 return IssuerHintEntrust, nil 84 case strIssuerHintAll: 85 return IssuerHintAllIssuers, nil 86 default: 87 return IssuerHintGeneric, nil 88 } 89 }