Skip to content

Commit 9112f29

Browse files
feat(gcs): make it possible to override default endpoint with config
Refs scylladb/scylla-manager#4598
1 parent afe1fd2 commit 9112f29

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

backend/googlecloudstorage/googlecloudstorage.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"golang.org/x/oauth2"
4545
"golang.org/x/oauth2/google"
4646
"google.golang.org/api/googleapi"
47+
"google.golang.org/api/option"
4748

4849
// NOTE: This API is deprecated
4950
storage "google.golang.org/api/storage/v1"
@@ -93,6 +94,9 @@ func init() {
9394
}
9495
},
9596
Options: append(oauthutil.SharedOptions, []fs.Option{{
97+
Name: "endpoint",
98+
Help: "Endpoint for GS API.\nRequired when using an GS clone.",
99+
}, {
96100
Name: "project_number",
97101
Help: "Project number.\nOptional - needed only for list/create/delete buckets - see your developer console.",
98102
}, {
@@ -302,6 +306,7 @@ If bucket doesn't exists, error will be returned.'`,
302306

303307
// Options defines the configuration for this backend
304308
type Options struct {
309+
Endpoint string `config:"endpoint"`
305310
ProjectNumber string `config:"project_number"`
306311
ServiceAccountFile string `config:"service_account_file"`
307312
ServiceAccountCredentials string `config:"service_account_credentials"`
@@ -499,7 +504,11 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
499504

500505
// Create a new authorized Drive client.
501506
f.client = oAuthClient
502-
f.svc, err = storage.New(f.client)
507+
clientOpts := []option.ClientOption{option.WithHTTPClient(f.client)}
508+
if opt.Endpoint != "" {
509+
clientOpts = append(clientOpts, option.WithEndpoint(opt.Endpoint))
510+
}
511+
f.svc, err = storage.NewService(ctx, clientOpts...)
503512
if err != nil {
504513
return nil, errors.Wrap(err, "couldn't create Google Cloud Storage client")
505514
}
@@ -556,7 +565,7 @@ type listFn func(remote string, object *storage.Object, isDirectory bool) error
556565
//
557566
// dir is the starting directory, "" for root
558567
//
559-
// Set recurse to read sub directories
568+
// # Set recurse to read sub directories
560569
//
561570
// The remote has prefix removed from it and if addBucket is set
562571
// then it adds the bucket to the start.
@@ -774,7 +783,7 @@ func (f *Fs) ListR(ctx context.Context, dir string, callback fs.ListRCallback) (
774783

775784
// Put the object into the bucket
776785
//
777-
// Copy the reader in to the new object which is returned
786+
// # Copy the reader in to the new object which is returned
778787
//
779788
// The new object may have been created if an error is returned
780789
func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error) {
@@ -871,9 +880,9 @@ func (f *Fs) Precision() time.Duration {
871880

872881
// Copy src to this remote using server-side copy operations.
873882
//
874-
// This is stored with the remote path given
883+
// # This is stored with the remote path given
875884
//
876-
// It returns the destination Object and a possible error
885+
// # It returns the destination Object and a possible error
877886
//
878887
// Will only be called if src.Fs().Name() == f.Name()
879888
//

0 commit comments

Comments
 (0)