Add an option to configure the S3 endpoint
This enables the use of other (AWS S3 compatible) S3 endpoints.
This commit is contained in:
parent
94b15b78bc
commit
c65b63d152
|
@ -69,7 +69,7 @@ type Entry struct {
|
|||
// Factory is the factory function to create a physical backend.
|
||||
type Factory func(map[string]string) (Backend, error)
|
||||
|
||||
// NewBackend returns a new Bckend with the given type and configuration.
|
||||
// NewBackend returns a new backend with the given type and configuration.
|
||||
// The backend is looked up in the BuiltinBackends variable.
|
||||
func NewBackend(t string, conf map[string]string) (Backend, error) {
|
||||
f, ok := BuiltinBackends[t]
|
||||
|
|
|
@ -47,6 +47,10 @@ func newS3Backend(conf map[string]string) (Backend, error) {
|
|||
if !ok {
|
||||
session_token = ""
|
||||
}
|
||||
endpoint, ok := conf["endpoint"]
|
||||
if !ok {
|
||||
endpoint = ""
|
||||
}
|
||||
region, ok := conf["region"]
|
||||
if !ok {
|
||||
region = os.Getenv("AWS_DEFAULT_REGION")
|
||||
|
@ -68,6 +72,7 @@ func newS3Backend(conf map[string]string) (Backend, error) {
|
|||
|
||||
s3conn := s3.New(session.New(&aws.Config{
|
||||
Credentials: creds,
|
||||
Endpoint: aws.String(endpoint),
|
||||
Region: aws.String(region),
|
||||
}))
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@ func TestS3Backend(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// If the variable is empty or doesn't exist, the default
|
||||
// AWS endpoints will be used
|
||||
endpoint := os.Getenv("AWS_S3_ENDPOINT")
|
||||
|
||||
region := os.Getenv("AWS_DEFAULT_REGION")
|
||||
if region == "" {
|
||||
region = "us-east-1"
|
||||
|
@ -30,6 +34,7 @@ func TestS3Backend(t *testing.T) {
|
|||
|
||||
s3conn := s3.New(session.New(&aws.Config{
|
||||
Credentials: credentials.NewEnvCredentials(),
|
||||
Endpoint: aws.String(endpoint),
|
||||
Region: aws.String(region),
|
||||
}))
|
||||
|
||||
|
|
Loading…
Reference in a new issue