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

Commit

Permalink
cherry pick #664 to release-4.0 (#673)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: 3pointer <luancheng@pingcap.com>
  • Loading branch information
ti-srebot and 3pointer authored Jan 8, 2021
1 parent 804aa90 commit 707abab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit 707abab

Please sign in to comment.