-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
artifacts.go
177 lines (159 loc) · 5.69 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
package executor
import (
"context"
"fmt"
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo-workflows/v3/workflow/artifacts/artifactory"
"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/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) {
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 {
return &http.ArtifactDriver{}, 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 := artifactory.ArtifactDriver{
Username: usernameBytes,
Password: passwordBytes,
}
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
}
return nil, ErrUnsupportedDriver
}