mirror of
https://github.com/restic/restic.git
synced 2025-03-23 00:00:04 +01:00

Implemented Google Cloud Storage support using the existing minio libraries. GCS repositories get specified using gs://bucketname/prefix syntax. Cloned the existing S3 support and tests to use them for GCS as well. Added tests for the various cases to config_test and location_test. Remove trailing slashes in repository specification.
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package gcs
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
// Config contains all configuration necessary to connect to an s3 compatible
|
|
// server.
|
|
type Config struct {
|
|
Endpoint string
|
|
UseHTTP bool
|
|
KeyID, Secret string
|
|
Bucket string
|
|
Prefix string
|
|
}
|
|
|
|
const Scheme = "gs"
|
|
const defaultPrefix = "restic"
|
|
const gcsEndpoint = "storage.googleapis.com"
|
|
|
|
// ParseConfig parses the string s and extracts the gcs config. The two
|
|
// supported configuration formats are gcs://bucketname/prefix and
|
|
// gcs:bucketname/prefix.
|
|
func ParseConfig(s string) (interface {}, error) {
|
|
if strings.HasPrefix(s, "gs://") {
|
|
s = s[5:]
|
|
} else if strings.HasPrefix(s, "gs:") {
|
|
s = s[3:]
|
|
} else {
|
|
return nil, errors.New(`gcs: config does not start with "gcs"`)
|
|
}
|
|
|
|
// be dfensive against wron user input and trim trailing slashes
|
|
data := strings.SplitN(strings.TrimRight(s, "/"), "/", 2)
|
|
if len(data) < 1 {
|
|
return nil, errors.New("gcs: invalid format, bucket name not found")
|
|
}
|
|
prefix := defaultPrefix
|
|
|
|
if len(data) > 1 {
|
|
prefix = data[1]
|
|
}
|
|
cfg := Config{
|
|
Endpoint: gcsEndpoint,
|
|
Bucket: data[0],
|
|
Prefix: prefix,
|
|
}
|
|
return cfg, nil
|
|
}
|