github.com/spinnaker/spin@v1.30.0/config/auth/x509/config.go (about) 1 // Copyright (c) 2018, Google, Inc. 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 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package x509 16 17 // Config is the configuration for using X.509 certs to 18 // authenticate with Spinnaker. 19 type Config struct { 20 CertPath string `json:"certPath" yaml:"certPath"` 21 KeyPath string `json:"keyPath" yaml:"keyPath"` 22 Cert string `json:"cert" yaml:"cert"` // Cert is base64 encoded PEM block. 23 Key string `json:"key" yaml:"key"` // Key is base64 encoded PEM block. 24 } 25 26 func (x *Config) IsValid() bool { 27 // Only one pair of configs properties should be set. 28 pathPropertySet := x.CertPath != "" || x.KeyPath != "" 29 pemPropertySet := x.Cert != "" || x.Key != "" 30 if pathPropertySet && pemPropertySet { 31 return false 32 } 33 34 pathPropertyMismatch := (x.CertPath != "" && x.KeyPath == "") || (x.KeyPath != "" && x.CertPath == "") 35 pemPropertyMismatch := (x.Cert != "" && x.Key == "") || (x.Key != "" && x.Cert == "") 36 if pathPropertyMismatch || pemPropertyMismatch { 37 return false 38 } 39 40 return true 41 }