@@ -8,32 +8,44 @@ import (
8
8
)
9
9
10
10
type DataStorage string
11
+ type S3CredentialType string
11
12
12
13
const (
13
- DataStorageUnknown DataStorage = "unknown"
14
- DataStorageS3 DataStorage = "s3"
15
- DataStorageFile DataStorage = "file"
14
+ DataStorageUnknown DataStorage = "unknown"
15
+ DataStorageS3 DataStorage = "s3"
16
+ DataStorageFile DataStorage = "file"
17
+ S3CredentialUnknown S3CredentialType = "unknown"
18
+ S3CredentialStatic S3CredentialType = "static"
19
+ S3CredentialIAM S3CredentialType = "iam"
16
20
)
17
21
18
22
type S3Config struct {
19
- Endpoint string
20
- AccessKey string
21
- SecretAccessKey string
22
- UseHttps bool
23
- Bucket string
23
+ Endpoint string
24
+ UseHttps bool
25
+ Bucket string
26
+
27
+ S3CredentialType S3CredentialType
28
+ AccessKey string
29
+ SecretAccessKey string
24
30
}
25
31
26
32
func (c S3Config ) check () error {
27
33
if c .Endpoint == "" {
28
34
return errors .New ("s3 endpoint must be set" )
29
35
}
30
36
31
- if c .AccessKey == "" {
32
- return errors .New ("s3 access key must be set" )
37
+ if c .S3CredentialType == S3CredentialUnknown {
38
+ return errors .New ("s3 credential type must be set" )
33
39
}
34
40
35
- if c .SecretAccessKey == "" {
36
- return errors .New ("s3 secret access key must be set" )
41
+ if c .S3CredentialType == S3CredentialStatic {
42
+ if c .AccessKey == "" {
43
+ return errors .New ("s3 access key must be set" )
44
+ }
45
+
46
+ if c .SecretAccessKey == "" {
47
+ return errors .New ("s3 secret access key must be set" )
48
+ }
37
49
}
38
50
39
51
if c .Bucket == "" {
@@ -85,12 +97,22 @@ func toDataStorage(s string) DataStorage {
85
97
86
98
func readS3Config (ctx * cli.Context ) S3Config {
87
99
return S3Config {
88
- Endpoint : ctx .String (S3EndpointFlagName ),
89
- AccessKey : ctx .String (S3AccessKeyFlagName ),
90
- SecretAccessKey : ctx .String (S3SecretAccessKeyFlagName ),
91
- UseHttps : ctx .Bool (S3EndpointHttpsFlagName ),
92
- Bucket : ctx .String (S3BucketFlagName ),
100
+ Endpoint : ctx .String (S3EndpointFlagName ),
101
+ AccessKey : ctx .String (S3AccessKeyFlagName ),
102
+ SecretAccessKey : ctx .String (S3SecretAccessKeyFlagName ),
103
+ UseHttps : ctx .Bool (S3EndpointHttpsFlagName ),
104
+ Bucket : ctx .String (S3BucketFlagName ),
105
+ S3CredentialType : toS3CredentialType (ctx .String (S3CredentialTypeFlagName )),
106
+ }
107
+ }
108
+
109
+ func toS3CredentialType (s string ) S3CredentialType {
110
+ if s == string (S3CredentialStatic ) {
111
+ return S3CredentialStatic
112
+ } else if s == string (S3CredentialIAM ) {
113
+ return S3CredentialIAM
93
114
}
115
+ return S3CredentialUnknown
94
116
}
95
117
96
118
func (c BeaconConfig ) Check () error {
0 commit comments