2017-04-03 14:08:01 +02:00
|
|
|
package main
|
2017-02-22 11:18:20 +01:00
|
|
|
|
|
|
|
import (
|
2017-04-09 22:27:41 +02:00
|
|
|
"errors"
|
2017-02-22 11:18:20 +01:00
|
|
|
"os"
|
|
|
|
|
2017-03-17 23:57:58 +01:00
|
|
|
"github.com/minio/minio-go"
|
2017-02-22 11:18:20 +01:00
|
|
|
)
|
|
|
|
|
2017-04-03 23:52:41 +02:00
|
|
|
// newMinioClient creates a new Minio client
|
2017-04-09 22:27:41 +02:00
|
|
|
func newMinioClient() (*minio.Client, error) {
|
2017-02-22 11:18:20 +01:00
|
|
|
var err error
|
2017-04-09 22:27:41 +02:00
|
|
|
var c *minio.Client
|
2017-02-22 11:18:20 +01:00
|
|
|
|
|
|
|
s3Endpoint := os.Getenv("S3_ENDPOINT")
|
2017-04-03 23:52:41 +02:00
|
|
|
if s3Endpoint == "" {
|
2017-02-22 11:18:20 +01:00
|
|
|
s3Endpoint = "s3.amazonaws.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
s3AccessKeyID := os.Getenv("S3_ACCESS_KEY_ID")
|
2017-04-03 23:52:41 +02:00
|
|
|
if s3AccessKeyID == "" {
|
2017-04-14 19:52:16 +02:00
|
|
|
return nil, errors.New("no S3_ACCESS_KEY_ID found")
|
2017-02-22 11:18:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
s3SecretAccessKey := os.Getenv("S3_SECRET_ACCESS_KEY")
|
2017-04-03 23:52:41 +02:00
|
|
|
if s3SecretAccessKey == "" {
|
2017-04-14 19:52:16 +02:00
|
|
|
return nil, errors.New("no S3_SECRET_ACCESS_KEY found")
|
2017-02-22 11:18:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if os.Getenv("V2_SIGNING") == "true" {
|
2017-04-09 22:27:41 +02:00
|
|
|
c, err = minio.NewV2(s3Endpoint, s3AccessKeyID, s3SecretAccessKey, true)
|
2017-02-22 11:18:20 +01:00
|
|
|
} else {
|
2017-04-09 22:27:41 +02:00
|
|
|
c, err = minio.New(s3Endpoint, s3AccessKeyID, s3SecretAccessKey, true)
|
2017-02-22 11:18:20 +01:00
|
|
|
}
|
2017-03-09 21:20:40 +01:00
|
|
|
|
2017-04-09 22:27:41 +02:00
|
|
|
return c, err
|
2017-02-22 11:18:20 +01:00
|
|
|
}
|