diff --git a/pkg/storage/parse.go b/pkg/storage/parse.go index 36487cc54..42a50cdf4 100644 --- a/pkg/storage/parse.go +++ b/pkg/storage/parse.go @@ -70,7 +70,10 @@ func ParseBackend(rawURL string, options *BackendOptions) (*backup.StorageBacken return &backup.StorageBackend{Backend: &backup.StorageBackend_S3{S3: s3}}, nil case "gs", "gcs": - prefix := strings.Trim(u.Path[1:], "/") + if u.Host == "" { + return nil, errors.Annotatef(berrors.ErrStorageInvalidConfig, "please specify the bucket for gcs in %s", rawURL) + } + prefix := strings.Trim(u.Path, "/") gcs := &backup.GCS{Bucket: u.Host, Prefix: prefix} if options == nil { options = &BackendOptions{} diff --git a/pkg/storage/parse_test.go b/pkg/storage/parse_test.go index 4b2072f0c..cd4312081 100644 --- a/pkg/storage/parse_test.go +++ b/pkg/storage/parse_test.go @@ -91,6 +91,15 @@ func (r *testStorageSuite) TestCreateStorage(c *C) { c.Assert(gcs.Endpoint, Equals, "https://gcs.example.com/") c.Assert(gcs.CredentialsBlob, Equals, "") + s, err = ParseBackend("gcs://bucket2", gcsOpt) + c.Assert(err, IsNil) + gcs = s.GetGcs() + c.Assert(gcs, NotNil) + c.Assert(gcs.Bucket, Equals, "bucket2") + c.Assert(gcs.Prefix, Equals, "") + c.Assert(gcs.Endpoint, Equals, "https://gcs.example.com/") + c.Assert(gcs.CredentialsBlob, Equals, "") + var credFeilPerm os.FileMode = 0o600 fakeCredentialsFile := filepath.Join(c.MkDir(), "fakeCredentialsFile") err = ioutil.WriteFile(fakeCredentialsFile, []byte("fakeCredentials"), credFeilPerm)