44 "fmt"
55 "os"
66 "regexp"
7- "strings"
87
98 "github.com/open-feature/flagd/core/pkg/logger"
109 "github.com/open-feature/flagd/core/pkg/sync"
@@ -13,6 +12,7 @@ import (
1312 "github.com/open-feature/flagd/core/pkg/sync/grpc"
1413 "github.com/open-feature/flagd/core/pkg/sync/grpc/credentials"
1514 httpSync "github.com/open-feature/flagd/core/pkg/sync/http"
15+ "github.com/open-feature/flagd/core/pkg/sync/internal/bloburi"
1616 "github.com/open-feature/flagd/core/pkg/sync/internal/polling"
1717 "github.com/open-feature/flagd/core/pkg/sync/kubernetes"
1818 "go.uber.org/zap"
@@ -229,8 +229,7 @@ func (sb *SyncBuilder) newGcs(config sync.SourceConfig, logger *logger.Logger) (
229229 // Extract bucket uri and object name from the full URI:
230230 // gs://bucket/path/to/object results in gs://bucket/ as bucketUri and
231231 // path/to/object as an object name.
232- bucketURI := regGcs .FindString (config .URI )
233- objectName := regGcs .ReplaceAllString (config .URI , "" )
232+ bucketURI , objectName := bloburi .Split (config .URI , regGcs )
234233
235234 interval , poller , err := newPoller (config )
236235 if err != nil {
@@ -265,8 +264,7 @@ func (sb *SyncBuilder) newAzblob(config sync.SourceConfig, logger *logger.Logger
265264 // Extract bucket uri and object name from the full URI:
266265 // azblob://bucket/path/to/object results in azblob://bucket/ as bucketUri and
267266 // path/to/object as an object name.
268- bucketURI := regAzblob .FindString (config .URI )
269- objectName := regAzblob .ReplaceAllString (config .URI , "" )
267+ bucketURI , objectName := bloburi .Split (config .URI , regAzblob )
270268
271269 interval , poller , err := newPoller (config )
272270 if err != nil {
@@ -291,15 +289,9 @@ func (sb *SyncBuilder) newAzblob(config sync.SourceConfig, logger *logger.Logger
291289func (sb * SyncBuilder ) newS3 (config sync.SourceConfig , logger * logger.Logger ) (* blobSync.Sync , error ) {
292290 // Extract bucket uri and object name from the full URI:
293291 // s3://bucket/path/to/object results in s3://bucket/ as bucketUri and
294- // path/to/object as an object name.
295- rawURI , query , hasQuery := strings .Cut (config .URI , "?" )
296- bucketURI := regS3 .FindString (rawURI )
297- objectName := regS3 .ReplaceAllString (rawURI , "" )
298- if hasQuery && query != "" {
299- // s3blob reads use_path_style/region/etc. from the bucket URL query string;
300- // the bucket host must not carry a trailing slash before "?".
301- bucketURI = strings .TrimSuffix (bucketURI , "/" ) + "?" + query
302- }
292+ // path/to/object as an object name. Any query string (e.g. use_path_style,
293+ // region) is moved onto the bucket URL so gocloud's s3blob driver reads it.
294+ bucketURI , objectName := bloburi .Split (config .URI , regS3 )
303295
304296 interval , poller , err := newPoller (config )
305297 if err != nil {
0 commit comments