Skip to content

Commit

Permalink
added for other providers
Browse files Browse the repository at this point in the history
Signed-off-by: Vanshikav123 <[email protected]>
  • Loading branch information
Vanshikav123 committed Jun 2, 2024
1 parent 1b2aa76 commit bd0b7b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewBucket(logger log.Logger, confContentYaml []byte, component string, rt h
case string(OCI):
bucket, err = oci.NewBucket(logger, config, rt)
case string(OBS):
bucket, err = obs.NewBucket(logger, config)
bucket, err = obs.NewBucket(logger, config, rt)
default:
return nil, errors.Errorf("bucket with type %s is not supported", bucketConf.Type)
}
Expand Down
27 changes: 19 additions & 8 deletions providers/obs/obs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"io"
"math"
"net/http"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -74,13 +75,13 @@ type Bucket struct {
name string
}

func NewBucket(logger log.Logger, conf []byte) (*Bucket, error) {
func NewBucket(logger log.Logger, conf []byte, rt http.RoundTripper) (*Bucket, error) {
config, err := parseConfig(conf)
if err != nil {
return nil, errors.Wrap(err, "parsing cos configuration")
}

return NewBucketWithConfig(logger, config)
return NewBucketWithConfig(logger, config, rt)
}

func parseConfig(conf []byte) (Config, error) {
Expand All @@ -92,17 +93,27 @@ func parseConfig(conf []byte) (Config, error) {
return config, nil
}

func NewBucketWithConfig(logger log.Logger, config Config) (*Bucket, error) {
func NewBucketWithConfig(logger log.Logger, config Config, rt http.RoundTripper) (*Bucket, error) {
if err := config.validate(); err != nil {
return nil, errors.Wrap(err, "validate obs config err")
}
var tpt *http.Transport
var err error

rt, err := exthttp.DefaultTransport(config.HTTPConfig)
if err != nil {
return nil, errors.Wrap(err, "get http transport err")
if rt != nil {
var ok bool
tpt, ok = rt.(*http.Transport)
if !ok {
return nil, errors.New("provided RoundTripper is not an *http.Transport")
}
} else {
tpt, err = exthttp.DefaultTransport(config.HTTPConfig)
if err != nil {
return nil, errors.Wrap(err, "get http transport err")
}
}

client, err := obs.New(config.AccessKey, config.SecretKey, config.Endpoint, obs.WithHttpTransport(rt))
client, err := obs.New(config.AccessKey, config.SecretKey, config.Endpoint, obs.WithHttpTransport(tpt))
if err != nil {
return nil, errors.Wrap(err, "initialize obs client err")
}
Expand Down Expand Up @@ -369,7 +380,7 @@ func NewTestBucketFromConfig(t testing.TB, c Config, reuseBucket bool, location
if err != nil {
return nil, nil, err
}
b, err := NewBucket(log.NewNopLogger(), bc)
b, err := NewBucket(log.NewNopLogger(), bc, http.DefaultTransport)
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit bd0b7b3

Please sign in to comment.