Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

gcs: fix url parse panic (#664) #673

Merged
merged 1 commit into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/storage/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
9 changes: 9 additions & 0 deletions pkg/storage/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down