-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
artifacts.go
256 lines (235 loc) · 8.65 KB
/
artifacts.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
package executor
import (
"context"
"fmt"
gohttp "net/http"
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/azure"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/common"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/gcs"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/git"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/hdfs"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/http"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/logging"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/oss"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/raw"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/resource"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/s3"
)
var ErrUnsupportedDriver = fmt.Errorf("unsupported artifact driver")
type NewDriverFunc func(ctx context.Context, art *wfv1.Artifact, ri resource.Interface) (common.ArtifactDriver, error)
// NewDriver initializes an instance of an artifact driver
func NewDriver(ctx context.Context, art *wfv1.Artifact, ri resource.Interface) (common.ArtifactDriver, error) {
drv, err := newDriver(ctx, art, ri)
if err != nil {
return nil, err
}
return logging.New(drv), nil
}
func newDriver(ctx context.Context, art *wfv1.Artifact, ri resource.Interface) (common.ArtifactDriver, error) {
if art.S3 != nil {
var accessKey string
var secretKey string
var serverSideCustomerKey string
var kmsKeyId string
var kmsEncryptionContext string
var enableEncryption bool
if art.S3.AccessKeySecret != nil && art.S3.AccessKeySecret.Name != "" {
accessKeyBytes, err := ri.GetSecret(ctx, art.S3.AccessKeySecret.Name, art.S3.AccessKeySecret.Key)
if err != nil {
return nil, err
}
accessKey = accessKeyBytes
secretKeyBytes, err := ri.GetSecret(ctx, art.S3.SecretKeySecret.Name, art.S3.SecretKeySecret.Key)
if err != nil {
return nil, err
}
secretKey = secretKeyBytes
}
if art.S3.EncryptionOptions != nil {
if art.S3.EncryptionOptions.ServerSideCustomerKeySecret != nil {
if art.S3.EncryptionOptions.KmsKeyId != "" {
return nil, fmt.Errorf("serverSideCustomerKeySecret and kmsKeyId cannot be set together")
}
serverSideCustomerKeyBytes, err := ri.GetSecret(ctx, art.S3.EncryptionOptions.ServerSideCustomerKeySecret.Name, art.S3.SecretKeySecret.Key)
if err != nil {
return nil, err
}
serverSideCustomerKey = serverSideCustomerKeyBytes
}
enableEncryption = art.S3.EncryptionOptions.EnableEncryption
kmsKeyId = art.S3.EncryptionOptions.KmsKeyId
kmsEncryptionContext = art.S3.EncryptionOptions.KmsEncryptionContext
}
driver := s3.ArtifactDriver{
Endpoint: art.S3.Endpoint,
AccessKey: accessKey,
SecretKey: secretKey,
Secure: art.S3.Insecure == nil || !*art.S3.Insecure,
Region: art.S3.Region,
RoleARN: art.S3.RoleARN,
UseSDKCreds: art.S3.UseSDKCreds,
KmsKeyId: kmsKeyId,
KmsEncryptionContext: kmsEncryptionContext,
EnableEncryption: enableEncryption,
ServerSideCustomerKey: serverSideCustomerKey,
}
return &driver, nil
}
if art.HTTP != nil {
var client *gohttp.Client
driver := http.ArtifactDriver{}
if art.HTTP.Auth != nil && art.HTTP.Auth.BasicAuth.UsernameSecret != nil {
usernameBytes, err := ri.GetSecret(ctx, art.HTTP.Auth.BasicAuth.UsernameSecret.Name, art.HTTP.Auth.BasicAuth.UsernameSecret.Key)
if err != nil {
return nil, err
}
driver.Username = usernameBytes
}
if art.HTTP.Auth != nil && art.HTTP.Auth.BasicAuth.PasswordSecret != nil {
passwordBytes, err := ri.GetSecret(ctx, art.HTTP.Auth.BasicAuth.PasswordSecret.Name, art.HTTP.Auth.BasicAuth.PasswordSecret.Key)
if err != nil {
return nil, err
}
driver.Password = passwordBytes
}
if art.HTTP.Auth != nil && art.HTTP.Auth.OAuth2.ClientIDSecret != nil && art.HTTP.Auth.OAuth2.ClientSecretSecret != nil && art.HTTP.Auth.OAuth2.TokenURLSecret != nil {
clientId, err := ri.GetSecret(ctx, art.HTTP.Auth.OAuth2.ClientIDSecret.Name, art.HTTP.Auth.OAuth2.ClientIDSecret.Key)
if err != nil {
return nil, err
}
clientSecret, err := ri.GetSecret(ctx, art.HTTP.Auth.OAuth2.ClientSecretSecret.Name, art.HTTP.Auth.OAuth2.ClientSecretSecret.Key)
if err != nil {
return nil, err
}
tokenURL, err := ri.GetSecret(ctx, art.HTTP.Auth.OAuth2.TokenURLSecret.Name, art.HTTP.Auth.OAuth2.TokenURLSecret.Key)
if err != nil {
return nil, err
}
client = http.CreateOauth2Client(clientId, clientSecret, tokenURL, art.HTTP.Auth.OAuth2.Scopes, art.HTTP.Auth.OAuth2.EndpointParams)
}
if art.HTTP.Auth != nil && art.HTTP.Auth.ClientCert.ClientCertSecret != nil && art.HTTP.Auth.ClientCert.ClientKeySecret != nil {
clientCert, err := ri.GetSecret(ctx, art.HTTP.Auth.ClientCert.ClientCertSecret.Name, art.HTTP.Auth.ClientCert.ClientCertSecret.Key)
if err != nil {
return nil, err
}
clientKey, err := ri.GetSecret(ctx, art.HTTP.Auth.ClientCert.ClientKeySecret.Name, art.HTTP.Auth.ClientCert.ClientKeySecret.Key)
if err != nil {
return nil, err
}
client, err = http.CreateClientWithCertificate([]byte(clientCert), []byte(clientKey))
if err != nil {
return nil, err
}
}
if client == nil {
client = &gohttp.Client{}
}
driver.Client = client
return &driver, nil
}
if art.Git != nil {
gitDriver := git.ArtifactDriver{
InsecureIgnoreHostKey: art.Git.InsecureIgnoreHostKey,
DisableSubmodules: art.Git.DisableSubmodules,
}
if art.Git.UsernameSecret != nil {
usernameBytes, err := ri.GetSecret(ctx, art.Git.UsernameSecret.Name, art.Git.UsernameSecret.Key)
if err != nil {
return nil, err
}
gitDriver.Username = usernameBytes
}
if art.Git.PasswordSecret != nil {
passwordBytes, err := ri.GetSecret(ctx, art.Git.PasswordSecret.Name, art.Git.PasswordSecret.Key)
if err != nil {
return nil, err
}
gitDriver.Password = passwordBytes
}
if art.Git.SSHPrivateKeySecret != nil {
sshPrivateKeyBytes, err := ri.GetSecret(ctx, art.Git.SSHPrivateKeySecret.Name, art.Git.SSHPrivateKeySecret.Key)
if err != nil {
return nil, err
}
gitDriver.SSHPrivateKey = sshPrivateKeyBytes
}
return &gitDriver, nil
}
if art.Artifactory != nil {
usernameBytes, err := ri.GetSecret(ctx, art.Artifactory.UsernameSecret.Name, art.Artifactory.UsernameSecret.Key)
if err != nil {
return nil, err
}
passwordBytes, err := ri.GetSecret(ctx, art.Artifactory.PasswordSecret.Name, art.Artifactory.PasswordSecret.Key)
if err != nil {
return nil, err
}
driver := http.ArtifactDriver{
Username: usernameBytes,
Password: passwordBytes,
Client: &gohttp.Client{},
}
return &driver, nil
}
if art.HDFS != nil {
return hdfs.CreateDriver(ctx, ri, art.HDFS)
}
if art.Raw != nil {
return &raw.ArtifactDriver{}, nil
}
if art.OSS != nil {
var accessKey string
var secretKey string
if art.OSS.AccessKeySecret != nil && art.OSS.AccessKeySecret.Name != "" {
accessKeyBytes, err := ri.GetSecret(ctx, art.OSS.AccessKeySecret.Name, art.OSS.AccessKeySecret.Key)
if err != nil {
return nil, err
}
accessKey = string(accessKeyBytes)
secretKeyBytes, err := ri.GetSecret(ctx, art.OSS.SecretKeySecret.Name, art.OSS.SecretKeySecret.Key)
if err != nil {
return nil, err
}
secretKey = string(secretKeyBytes)
}
driver := oss.ArtifactDriver{
Endpoint: art.OSS.Endpoint,
AccessKey: accessKey,
SecretKey: secretKey,
SecurityToken: art.OSS.SecurityToken,
}
return &driver, nil
}
if art.GCS != nil {
driver := gcs.ArtifactDriver{}
if art.GCS.ServiceAccountKeySecret != nil && art.GCS.ServiceAccountKeySecret.Name != "" {
serviceAccountKeyBytes, err := ri.GetSecret(ctx, art.GCS.ServiceAccountKeySecret.Name, art.GCS.ServiceAccountKeySecret.Key)
if err != nil {
return nil, err
}
serviceAccountKey := string(serviceAccountKeyBytes)
driver.ServiceAccountKey = serviceAccountKey
}
// key is not set, assume it is using Workload Idendity
return &driver, nil
}
if art.Azure != nil {
var accountKey string
if !art.Azure.UseSDKCreds && art.Azure.AccountKeySecret != nil && art.Azure.AccountKeySecret.Name != "" {
accountKeyBytes, err := ri.GetSecret(ctx, art.Azure.AccountKeySecret.Name, art.Azure.AccountKeySecret.Key)
if err != nil {
return nil, err
}
accountKey = accountKeyBytes
}
driver := azure.ArtifactDriver{
AccountKey: accountKey,
Container: art.Azure.Container,
Endpoint: art.Azure.Endpoint,
UseSDKCreds: art.Azure.UseSDKCreds,
}
return &driver, nil
}
return nil, ErrUnsupportedDriver
}