forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifacts.go
111 lines (100 loc) · 3.19 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
package executor
import (
"fmt"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/workflow/artifacts/artifactory"
"github.com/argoproj/argo/workflow/artifacts/git"
"github.com/argoproj/argo/workflow/artifacts/hdfs"
"github.com/argoproj/argo/workflow/artifacts/http"
"github.com/argoproj/argo/workflow/artifacts/raw"
"github.com/argoproj/argo/workflow/artifacts/resource"
"github.com/argoproj/argo/workflow/artifacts/s3"
)
// ArtifactDriver is the interface for loading and saving of artifacts
type ArtifactDriver interface {
// Load accepts an artifact source URL and places it at specified path
Load(inputArtifact *wfv1.Artifact, path string) error
// Save uploads the path to artifact destination
Save(path string, outputArtifact *wfv1.Artifact) error
}
var ErrUnsupportedDriver = fmt.Errorf("unsupported artifact driver")
// NewDriver initializes an instance of an artifact driver
func NewDriver(art *wfv1.Artifact, ri resource.Interface) (ArtifactDriver, error) {
if art.S3 != nil {
var accessKey string
var secretKey string
if art.S3.AccessKeySecret.Name != "" {
accessKeyBytes, err := ri.GetSecret(art.S3.AccessKeySecret.Name, art.S3.AccessKeySecret.Key)
if err != nil {
return nil, err
}
accessKey = accessKeyBytes
secretKeyBytes, err := ri.GetSecret(art.S3.SecretKeySecret.Name, art.S3.SecretKeySecret.Key)
if err != nil {
return nil, err
}
secretKey = secretKeyBytes
}
driver := s3.S3ArtifactDriver{
Endpoint: art.S3.Endpoint,
AccessKey: accessKey,
SecretKey: secretKey,
Secure: art.S3.Insecure == nil || !*art.S3.Insecure,
Region: art.S3.Region,
RoleARN: art.S3.RoleARN,
}
return &driver, nil
}
if art.HTTP != nil {
return &http.HTTPArtifactDriver{}, nil
}
if art.Git != nil {
gitDriver := git.GitArtifactDriver{
InsecureIgnoreHostKey: art.Git.InsecureIgnoreHostKey,
}
if art.Git.UsernameSecret != nil {
usernameBytes, err := ri.GetSecret(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(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(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(art.Artifactory.UsernameSecret.Name, art.Artifactory.UsernameSecret.Key)
if err != nil {
return nil, err
}
passwordBytes, err := ri.GetSecret(art.Artifactory.PasswordSecret.Name, art.Artifactory.PasswordSecret.Key)
if err != nil {
return nil, err
}
driver := artifactory.ArtifactoryArtifactDriver{
Username: usernameBytes,
Password: passwordBytes,
}
return &driver, nil
}
if art.HDFS != nil {
return hdfs.CreateDriver(ri, art.HDFS)
}
if art.Raw != nil {
return &raw.RawArtifactDriver{}, nil
}
return nil, ErrUnsupportedDriver
}