@@ -91,31 +91,41 @@ func createDefaultS3Storage(s3Bucket, project string, storageConfig StorageConfi
91
91
}
92
92
93
93
func createS3StorageUsingEndpoint (s3Bucket , project , s3Url string , storageConfig StorageConfig ) (* S3Storage , error ) {
94
- resolver := aws .EndpointResolverFunc (func (service , region string ) (aws.Endpoint , error ) {
95
- return aws.Endpoint {
96
- URL : s3Url ,
97
- }, nil
98
- })
94
+ options := []func (* awsConfig.LoadOptions ) error {
95
+ awsConfig .WithRegion ("auto" ),
96
+ awsConfig .WithEndpointResolverWithOptions (
97
+ aws .EndpointResolverWithOptionsFunc (func (service , region string , options ... interface {}) (aws.Endpoint , error ) {
98
+ return aws.Endpoint {
99
+ URL : s3Url ,
100
+ }, nil
101
+ }),
102
+ ),
103
+ }
99
104
100
- creds := credentials .NewStaticCredentialsProvider ("minioadmin" , "minioadmin" , "" )
101
- cfg , err := awsConfig .LoadDefaultConfig (context .TODO (),
102
- awsConfig .WithCredentialsProvider (creds ),
103
- awsConfig .WithEndpointResolver (resolver ),
104
- )
105
+ // If a key/secret pair is passed, we use them.
106
+ // Otherwise, we just rely on the default configuration methods
107
+ // used by LoadDefaultConfig(), for example,
108
+ // AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID environment variables.
109
+ s3Key := os .Getenv ("SEMAPHORE_CACHE_S3_KEY" )
110
+ s3Secret := os .Getenv ("SEMAPHORE_CACHE_S3_SECRET" )
111
+ if s3Key != "" && s3Secret != "" {
112
+ options = append (options , awsConfig .WithCredentialsProvider (
113
+ credentials .NewStaticCredentialsProvider (s3Key , s3Secret , "" ),
114
+ ))
115
+ }
105
116
117
+ cfg , err := awsConfig .LoadDefaultConfig (context .TODO (), options ... )
106
118
if err != nil {
107
119
return nil , err
108
120
}
109
121
110
- svc := s3 .NewFromConfig (cfg , func (o * s3.Options ) {
111
- o .UsePathStyle = true
112
- })
113
-
114
122
return & S3Storage {
115
- Client : svc ,
116
123
Bucket : s3Bucket ,
117
124
Project : project ,
118
125
StorageConfig : storageConfig ,
126
+ Client : s3 .NewFromConfig (cfg , func (o * s3.Options ) {
127
+ o .UsePathStyle = true
128
+ }),
119
129
}, nil
120
130
}
121
131
0 commit comments