-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathclient.go
More file actions
34 lines (29 loc) · 922 Bytes
/
client.go
File metadata and controls
34 lines (29 loc) · 922 Bytes
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
package storage
import (
"github.com/deis/builder/pkg/sys"
s3 "github.com/minio/minio-go"
)
// Client is the S3 client combined with the S3 endpoint.
type Client struct {
*s3.Client
// Endpoint is the the endpoint information for the location that the S3 client will access.
Endpoint *Endpoint
}
// GetClient returns a S3 API compatible storage client.
func GetClient(regionStr string, fs sys.FS, env sys.Env) (*Client, error) {
auth, err := getAuth(fs)
if err != nil {
return nil, err
}
endpoint, err := getEndpoint(env)
if err != nil {
return nil, err
}
// the New function call guesses which signature version to use. Currently, it correctly guesses
// V2 for GCS and V4 for both AWS S3 and Minio.
s3Client, err := s3.New(endpoint.URLStr, auth.accessKeyID, auth.accessKeySecret, !endpoint.Secure)
if err != nil {
return nil, err
}
return &Client{Client: s3Client, Endpoint: endpoint}, nil
}