From 1ad22b8881ceaa6219f0bc1ae67507c74f49bdb2 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 9 Aug 2022 11:15:04 +0100 Subject: [PATCH] gcs: add --gcs-endpoint flag and config parameter See: https://forum.rclone.org/t/how-to-modify-google-cloud-storage-endpoint-uri/32342 --- backend/googlecloudstorage/googlecloudstorage.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/googlecloudstorage/googlecloudstorage.go b/backend/googlecloudstorage/googlecloudstorage.go index 0e6a2b4ed..5ce96e672 100644 --- a/backend/googlecloudstorage/googlecloudstorage.go +++ b/backend/googlecloudstorage/googlecloudstorage.go @@ -319,6 +319,10 @@ can't check the size and hash but the file contents will be decompressed. `, Advanced: true, Default: false, + }, { + Name: "endpoint", + Help: "Endpoint for the service.\n\nLeave blank normally.", + Advanced: true, }, { Name: config.ConfigEncoding, Help: config.ConfigEncodingHelp, @@ -343,6 +347,7 @@ type Options struct { StorageClass string `config:"storage_class"` NoCheckBucket bool `config:"no_check_bucket"` Decompress bool `config:"decompress"` + Endpoint string `config:"endpoint"` Enc encoder.MultiEncoder `config:"encoding"` } @@ -523,7 +528,11 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e // Create a new authorized Drive client. f.client = oAuthClient - f.svc, err = storage.NewService(context.Background(), option.WithHTTPClient(f.client)) + gcsOpts := []option.ClientOption{option.WithHTTPClient(f.client)} + if opt.Endpoint != "" { + gcsOpts = append(gcsOpts, option.WithEndpoint(opt.Endpoint)) + } + f.svc, err = storage.NewService(context.Background(), gcsOpts...) if err != nil { return nil, fmt.Errorf("couldn't create Google Cloud Storage client: %w", err) }