github.com/nilium/gitlab-runner@v12.5.0+incompatible/cache/s3/minio.go (about) 1 package s3 2 3 import ( 4 "net/url" 5 "time" 6 7 "github.com/minio/minio-go" 8 "github.com/minio/minio-go/pkg/credentials" 9 10 "gitlab.com/gitlab-org/gitlab-runner/common" 11 ) 12 13 const DefaultAWSS3Server = "s3.amazonaws.com" 14 15 type minioClient interface { 16 PresignedGetObject(bucketName string, objectName string, expires time.Duration, reqParams url.Values) (*url.URL, error) 17 PresignedPutObject(bucketName string, objectName string, expires time.Duration) (*url.URL, error) 18 } 19 20 var newMinio = minio.New 21 var newMinioWithCredentials = minio.NewWithCredentials 22 23 var newMinioClient = func(s3 *common.CacheS3Config) (minioClient, error) { 24 var client *minio.Client 25 var err error 26 27 if s3.ShouldUseIAMCredentials() { 28 iam := credentials.NewIAM("") 29 client, err = newMinioWithCredentials(DefaultAWSS3Server, iam, true, "") 30 } else { 31 client, err = newMinio(s3.ServerAddress, s3.AccessKey, s3.SecretKey, !s3.Insecure) 32 } 33 34 if err != nil { 35 return nil, err 36 } 37 38 client.SetCustomTransport(&bucketLocationTripper{ 39 bucketLocation: s3.BucketLocation, 40 }) 41 42 return client, nil 43 }