-
Notifications
You must be signed in to change notification settings - Fork 53
/
secrets.go
150 lines (136 loc) · 3.46 KB
/
secrets.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package v1
import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const Redacted = "***"
func (cfg *StorageSpec) RedactSecrets() {
if cfg == nil {
return
}
if cfg.S3 != nil {
cfg.S3.RedactSecrets()
}
if cfg.Gcs != nil {
cfg.Gcs.RedactSecrets()
}
if cfg.Azure != nil {
cfg.Azure.RedactSecrets()
}
if cfg.Swift != nil {
cfg.Swift.RedactSecrets()
}
}
func (cfg *S3StorageSpec) RedactSecrets() {
if cfg.SecretAccessKey != "" {
cfg.SecretAccessKey = Redacted
}
if cfg.Sse != nil {
cfg.Sse.RedactSecrets()
}
}
func (cfg *GCSStorageSpec) RedactSecrets() {
if cfg.ServiceAccount != "" {
cfg.ServiceAccount = Redacted
}
}
func (cfg *AzureStorageSpec) RedactSecrets() {
if cfg.StorageAccountKey != "" {
cfg.StorageAccountKey = Redacted
}
if cfg.MsiResource != "" {
cfg.MsiResource = Redacted
}
}
func (cfg *SwiftStorageSpec) RedactSecrets() {
if cfg.Password != "" {
cfg.Password = Redacted
}
}
func (cfg *SSEConfig) RedactSecrets() {
if cfg.KmsEncryptionContext != "" {
cfg.KmsEncryptionContext = Redacted
}
}
func (cfg *StorageSpec) UnredactSecrets(unredacted *StorageSpec) error {
if cfg == nil {
return nil
}
if cfg.S3 != nil {
if err := cfg.S3.UnredactSecrets(unredacted.GetS3()); err != nil {
return err
}
}
if cfg.Gcs != nil {
if err := cfg.Gcs.UnredactSecrets(unredacted.GetGcs()); err != nil {
return err
}
}
if cfg.Azure != nil {
if err := cfg.Azure.UnredactSecrets(unredacted.GetAzure()); err != nil {
return err
}
}
if cfg.Swift != nil {
if err := cfg.Swift.UnredactSecrets(unredacted.GetSwift()); err != nil {
return err
}
}
return nil
}
func (cfg *S3StorageSpec) UnredactSecrets(unredacted *S3StorageSpec) error {
if cfg.SecretAccessKey == Redacted {
if unredacted.GetSecretAccessKey() == "" {
return status.Error(codes.FailedPrecondition, "no secret access key provided")
}
cfg.SecretAccessKey = unredacted.SecretAccessKey
}
if cfg.Sse != nil {
if err := cfg.Sse.UnredactSecrets(unredacted.GetSse()); err != nil {
return err
}
}
return nil
}
func (cfg *GCSStorageSpec) UnredactSecrets(unredacted *GCSStorageSpec) error {
if cfg.ServiceAccount == Redacted {
if unredacted.GetServiceAccount() == "" {
return status.Error(codes.FailedPrecondition, "no service account provided")
}
cfg.ServiceAccount = unredacted.ServiceAccount
}
return nil
}
func (cfg *AzureStorageSpec) UnredactSecrets(unredacted *AzureStorageSpec) error {
if cfg.StorageAccountKey == Redacted {
if unredacted.GetStorageAccountKey() == "" {
return status.Error(codes.FailedPrecondition, "no storage account key provided")
}
cfg.StorageAccountKey = unredacted.StorageAccountKey
}
if cfg.MsiResource == Redacted {
if unredacted.GetMsiResource() == "" {
return status.Error(codes.FailedPrecondition, "no MSI resource provided")
}
cfg.MsiResource = unredacted.MsiResource
}
return nil
}
func (cfg *SwiftStorageSpec) UnredactSecrets(unredacted *SwiftStorageSpec) error {
if cfg.Password == Redacted {
if unredacted.GetPassword() == "" {
return status.Error(codes.FailedPrecondition, "no password provided")
}
cfg.Password = unredacted.Password
}
return nil
}
func (cfg *SSEConfig) UnredactSecrets(unredacted *SSEConfig) error {
if cfg.KmsEncryptionContext == Redacted {
if unredacted.GetKmsEncryptionContext() == "" {
return status.Error(codes.FailedPrecondition, "no KMS encryption context provided")
}
cfg.KmsEncryptionContext = unredacted.KmsEncryptionContext
}
return nil
}