/
type_cluster_secret.go
97 lines (83 loc) · 2.94 KB
/
type_cluster_secret.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2019 Altinity Ltd and/or its affiliates. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1
import (
core "k8s.io/api/core/v1"
)
// ClusterSecret defines the shared secret for nodes to authenticate each other with
type ClusterSecret struct {
Auto *StringBool `json:"auto,omitempty" yaml:"auto,omitempty"`
Value string `json:"value,omitempty" yaml:"value,omitempty"`
ValueFrom *DataSource `json:"valueFrom,omitempty" yaml:"valueFrom,omitempty"`
}
// ClusterSecretSourceName specifies name of the source where secret is provided
type ClusterSecretSourceName string
// Possible values for ClusterSecretSourceName secret sources
const (
ClusterSecretSourcePlaintext ClusterSecretSourceName = "plaintext"
ClusterSecretSourceSecretRef ClusterSecretSourceName = "secret_ref"
ClusterSecretSourceAuto ClusterSecretSourceName = "auto"
ClusterSecretSourceUnspecified ClusterSecretSourceName = ""
)
// Source returns name of the source where secret is provided
func (s *ClusterSecret) Source() ClusterSecretSourceName {
if s == nil {
// No secret is specified at all
return ClusterSecretSourceUnspecified
}
if s.HasValue() {
// Secret has explicit value specified
return ClusterSecretSourcePlaintext
}
if s.HasSecretKeyRef() {
// Secret has SecretKeyRef specified
return ClusterSecretSourceSecretRef
}
if s.Auto.IsTrue() {
// Secret is auto-generated
return ClusterSecretSourceAuto
}
// No secret is specified at all
return ClusterSecretSourceUnspecified
}
// HasValue checks whether explicit plaintext value is specified
func (s *ClusterSecret) HasValue() bool {
if s == nil {
return false
}
return s.Value != ""
}
// GetSecretKeyRef gets SecretKeySelector (typically named as SecretKeyRef) or nil
func (s *ClusterSecret) GetSecretKeyRef() *core.SecretKeySelector {
if s == nil {
return nil
}
if s.ValueFrom == nil {
return nil
}
return s.ValueFrom.SecretKeyRef
}
// HasSecretKeyRef checks whether SecretKeySelector (typically named as SecretKeyRef) is available
func (s *ClusterSecret) HasSecretKeyRef() bool {
return s.GetSecretKeyRef() != nil
}
// GetAutoSecretKeyRef gets SecretKeySelector (typically named as SecretKeyRef) of an auto-generated secret or nil
func (s *ClusterSecret) GetAutoSecretKeyRef(name string) *core.SecretKeySelector {
return &core.SecretKeySelector{
LocalObjectReference: core.LocalObjectReference{
Name: name,
},
Key: "secret",
}
}