-
Notifications
You must be signed in to change notification settings - Fork 23
/
types.go
113 lines (94 loc) · 3.7 KB
/
types.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package v1
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ExternalSecret represents a collection of mappings of Secrets to destinations in the underlying secret store (e.g. Vault keys)
//
// +k8s:openapi-gen=true
type ExternalSecret struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata" yaml:"metadata"`
// Spec holds the desired state of the ExternalSecret from the client
// +optional
Spec ExternalSecretSpec `json:"spec" yaml:"spec"`
// Status holds the current status
// +optional
Status *ExternalSecretStatus `json:"status,omitempty" yaml:"status,omitempty"`
}
// Keys returns the keys for the secret
func (s *ExternalSecret) Keys() []string {
var keys []string
if s.Spec.Data != nil {
for _, d := range s.Spec.Data {
keys = append(keys, d.Key)
}
}
return keys
}
// KeyAndNames returns the data key and names for the secret
func (s *ExternalSecret) KeyAndNames() []string {
var keys []string
if s.Spec.Data != nil {
for _, d := range s.Spec.Data {
keys = append(keys, d.Key+"/"+d.Name)
}
}
return keys
}
// KeyAndProperty returns the secret key and property for a given secret data entry defined by name
func (s *ExternalSecret) KeyAndProperty(name string) (string, string, error) {
for _, d := range s.Spec.Data {
if d.Name == name {
return d.Key, d.Property, nil
}
}
return "", "", fmt.Errorf("unable to find secret data entry of %s of External Secret %s", name, s.Name)
}
// ExternalSecretSpec defines the desired state of ExternalSecret.
type ExternalSecretSpec struct {
BackendType string `json:"backendType,omitempty" yaml:"backendType,omitempty"`
VaultMountPoint string `json:"vaultMountPoint,omitempty" yaml:"vaultMountPoint,omitempty"`
VaultRole string `json:"vaultRole,omitempty" yaml:"vaultRole,omitempty"`
ProjectID string `json:"projectId,omitempty" yaml:"projectId,omitempty"`
KeyVaultName string `json:"keyVaultName,omitempty" yaml:"keyVaultName,omitempty"`
// Data the data for each entry in the Secret
Data []Data `json:"data,omitempty" yaml:"data,omitempty"`
// Template
Template Template `json:"template,omitempty" yaml:"template,omitempty"`
}
// ExternalSecretStatus defines the current status of the ExternalSecret.
type ExternalSecretStatus struct {
LastSync metav1.Time `json:"lastSync,omitempty" yaml:"lastSync,omitempty"`
ObservedGeneration int `json:"observedGeneration,omitempty" yaml:"observedGeneration,omitempty"`
Status string `json:"status,omitempty" yaml:"status,omitempty"`
}
// ExternalSecretList contains a list of ExternalSecret
//
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ExternalSecretList struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
Items []ExternalSecret `json:"items" yaml:"items"`
}
// Data the data properties
type Data struct {
// Name name of the secret data entry
Name string `json:"name,omitempty" yaml:"name,omitempty"`
// Key the key in the underlying secret storage (e.g. the key in vault)
Key string `json:"key,omitempty" yaml:"key,omitempty"`
// Property the property in the underlying secret storage (e.g. in vault)
Property string `json:"property,omitempty" yaml:"property,omitempty"`
}
// Template the template data
type Template struct {
// Type the type of the secret
Type string `json:"type,omitempty" yaml:"type,omitempty"`
// Metadata the metadata such as labels or annotations
Metadata metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}