1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-03-16 00:00:05 +01:00

Exported s3.createConfig as s3.NewConfig to make it usable by

gcs.ParseConfig.

Updated gcs.ParseConfig to use s3.NewConfig
This commit is contained in:
Christian Kemper 2016-02-21 08:14:03 -08:00
parent af964669a4
commit 13cbd11818
2 changed files with 11 additions and 23 deletions

View file

@ -2,7 +2,6 @@ package gcs
import (
"errors"
"path"
"restic/backend/s3"
"strings"
)
@ -25,19 +24,5 @@ func ParseConfig(s string) (interface{}, error) {
return nil, errors.New(`gcs: config does not start with "gs"`)
}
p := strings.SplitN(s, "/", 2)
var prefix string
switch {
case len(p) < 1:
return nil, errors.New("gcs: invalid format: bucket name not found")
case len(p) == 1 || p[1] == "":
prefix = defaultPrefix
default:
prefix = path.Clean(p[1])
}
return s3.Config{
Endpoint: gcsEndpoint,
UseHTTP: false,
Bucket: p[0],
Prefix: prefix,
}, nil
return s3.NewConfig(gcsEndpoint, p, false)
}

View file

@ -41,7 +41,7 @@ func ParseConfig(s string) (interface{}, error) {
}
path := strings.SplitN(url.Path[1:], "/", 2)
return createConfig(url.Host, path, url.Scheme == "http")
return NewConfig(url.Host, path, url.Scheme == "http")
case strings.HasPrefix(s, "s3://"):
s = s[5:]
case strings.HasPrefix(s, "s3:"):
@ -52,23 +52,26 @@ func ParseConfig(s string) (interface{}, error) {
// use the first entry of the path as the endpoint and the
// remainder as bucket name and prefix
path := strings.SplitN(s, "/", 3)
return createConfig(path[0], path[1:], false)
return NewConfig(path[0], path[1:], false)
}
func createConfig(endpoint string, p []string, useHTTP bool) (interface{}, error) {
// NewConfig creates a Config at the specified endpoint. The Bucket is
// the first entry in p and the remaining entries will be used as the
// object name prefix.
func NewConfig(endpoint string, bucketPrefix []string, useHTTP bool) (interface{}, error) {
var prefix string
switch {
case len(p) < 1:
case len(bucketPrefix) < 1:
return nil, errors.New("s3: invalid format, host/region or bucket name not found")
case len(p) == 1 || p[1] == "":
case len(bucketPrefix) == 1 || bucketPrefix[1] == "":
prefix = defaultPrefix
default:
prefix = path.Clean(p[1])
prefix = path.Clean(bucketPrefix[1])
}
return Config{
Endpoint: endpoint,
UseHTTP: useHTTP,
Bucket: p[0],
Bucket: bucketPrefix[0],
Prefix: prefix,
}, nil
}