@@ -52,7 +52,8 @@ type Config struct {
52
52
// ChunkSizeBytes controls the maximum number of bytes of the object that the
53
53
// Writer will attempt to send to the server in a single request
54
54
// Used as storage.Writer.ChunkSize of https://pkg.go.dev/google.golang.org/cloud/storage#Writer
55
- ChunkSizeBytes int `yaml:"chunk_size_bytes"`
55
+ ChunkSizeBytes int `yaml:"chunk_size_bytes"`
56
+ noAuth bool `yaml:"no_auth"`
56
57
}
57
58
58
59
// Bucket implements the store.Bucket and shipper.Bucket interfaces against GCS.
@@ -76,20 +77,22 @@ func parseConfig(conf []byte) (Config, error) {
76
77
}
77
78
78
79
// NewBucket returns a new Bucket against the given bucket handle.
79
- func NewBucket (ctx context.Context , logger log.Logger , conf []byte , component string ) (* Bucket , error ) {
80
+ func NewBucket (ctx context.Context , logger log.Logger , conf []byte , component string , rt http. RoundTripper ) (* Bucket , error ) {
80
81
config , err := parseConfig (conf )
81
82
if err != nil {
82
83
return nil , err
83
84
}
84
- return NewBucketWithConfig (ctx , logger , config , component )
85
+ return NewBucketWithConfig (ctx , logger , config , component , rt )
85
86
}
86
87
87
88
// NewBucketWithConfig returns a new Bucket with gcs Config struct.
88
- func NewBucketWithConfig (ctx context.Context , logger log.Logger , gc Config , component string ) (* Bucket , error ) {
89
+ func NewBucketWithConfig (ctx context.Context , logger log.Logger , gc Config , component string , rt http. RoundTripper ) (* Bucket , error ) {
89
90
if gc .Bucket == "" {
90
91
return nil , errors .New ("missing Google Cloud Storage bucket name for stored blocks" )
91
92
}
92
-
93
+ if rt != nil {
94
+ gc .HTTPConfig .Transport = rt
95
+ }
93
96
var opts []option.ClientOption
94
97
95
98
// If ServiceAccount is provided, use them in GCS client, otherwise fallback to Google default logic.
@@ -100,7 +103,9 @@ func NewBucketWithConfig(ctx context.Context, logger log.Logger, gc Config, comp
100
103
}
101
104
opts = append (opts , option .WithCredentials (credentials ))
102
105
}
103
-
106
+ if gc .noAuth {
107
+ opts = append (opts , option .WithoutAuthentication ())
108
+ }
104
109
opts = append (opts ,
105
110
option .WithUserAgent (fmt .Sprintf ("thanos-%s/%s (%s)" , component , version .Version , runtime .Version ())),
106
111
)
@@ -120,14 +125,12 @@ func appendHttpOptions(gc Config, opts []option.ClientOption) ([]option.ClientOp
120
125
// Check if a roundtripper has been set in the config
121
126
// otherwise build the default transport.
122
127
var rt http.RoundTripper
128
+ rt , err := exthttp .DefaultTransport (gc .HTTPConfig )
129
+ if err != nil {
130
+ return nil , err
131
+ }
123
132
if gc .HTTPConfig .Transport != nil {
124
133
rt = gc .HTTPConfig .Transport
125
- } else {
126
- var err error
127
- rt , err = exthttp .DefaultTransport (gc .HTTPConfig )
128
- if err != nil {
129
- return nil , err
130
- }
131
134
}
132
135
133
136
// GCS uses some defaults when "options.WithHTTPClient" is not used that are important when we call
@@ -312,7 +315,7 @@ func NewTestBucket(t testing.TB, project string) (objstore.Bucket, func(), error
312
315
return nil , nil , err
313
316
}
314
317
315
- b , err := NewBucket (ctx , log .NewNopLogger (), bc , "thanos-e2e-test" )
318
+ b , err := NewBucket (ctx , log .NewNopLogger (), bc , "thanos-e2e-test" , nil )
316
319
if err != nil {
317
320
return nil , nil , err
318
321
}
0 commit comments