|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2020 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | +// Author Ewout Prangsma |
| 21 | +// |
| 22 | + |
| 23 | +package v1 |
| 24 | + |
| 25 | +import ( |
| 26 | + shared "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1" |
| 27 | + "github.com/pkg/errors" |
| 28 | +) |
| 29 | + |
| 30 | +type TLSSNIRotateMode string |
| 31 | + |
| 32 | +func (t *TLSSNIRotateMode) Get() TLSSNIRotateMode { |
| 33 | + if t == nil { |
| 34 | + return TLSSNIRotateModeInPlace |
| 35 | + } |
| 36 | + |
| 37 | + return *t |
| 38 | +} |
| 39 | + |
| 40 | +const ( |
| 41 | + TLSSNIRotateModeInPlace TLSSNIRotateMode = "inplace" |
| 42 | + TLSSNIRotateModeRecreate TLSSNIRotateMode = "recreate" |
| 43 | +) |
| 44 | + |
| 45 | +// TLSSNISpec holds TLS SNI additional certificates |
| 46 | +type TLSSNISpec struct { |
| 47 | + Mapping map[string][]string `json:"sniMapping,omitempty"` |
| 48 | + Mode *TLSSNIRotateMode `json:"mode,omitempty"` |
| 49 | +} |
| 50 | + |
| 51 | +func (s TLSSNISpec) Validate() error { |
| 52 | + mapped := map[string]interface{}{} |
| 53 | + |
| 54 | + for key, values := range s.Mapping { |
| 55 | + if err := shared.IsValidName(key); err != nil { |
| 56 | + return err |
| 57 | + } |
| 58 | + |
| 59 | + for _, value := range values { |
| 60 | + if _, exists := mapped[value]; exists { |
| 61 | + return errors.Errorf("sni for host %s is already defined", value) |
| 62 | + } |
| 63 | + |
| 64 | + // Mark value as existing |
| 65 | + mapped[value] = nil |
| 66 | + |
| 67 | + if err := shared.IsValidDomain(value); err != nil { |
| 68 | + return err |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + return nil |
| 74 | +} |
| 75 | + |
| 76 | +// SetDefaultsFrom fills unspecified fields with a value from given source spec. |
| 77 | +func (s *TLSSNISpec) SetDefaultsFrom(source *TLSSNISpec) { |
| 78 | + if source == nil { |
| 79 | + return |
| 80 | + } |
| 81 | +} |
0 commit comments