@@ -21,6 +21,7 @@ type Provider struct {
21
21
httpClient HTTPClient
22
22
endpoint string
23
23
goFeatureFlagInstance * client.GoFeatureFlag
24
+ apiKey string
24
25
}
25
26
26
27
// HTTPClient is a custom interface to be able to override it by any implementation
@@ -64,6 +65,7 @@ func NewProvider(options ProviderOptions) (*Provider, error) {
64
65
}
65
66
66
67
return & Provider {
68
+ apiKey : options .APIKey ,
67
69
endpoint : options .Endpoint ,
68
70
httpClient : httpClient ,
69
71
}, nil
@@ -276,6 +278,9 @@ func evaluateWithRelayProxy[T model.JsonType](provider *Provider, ctx context.Co
276
278
}
277
279
}
278
280
goffRequest .Header .Set ("Content-Type" , "application/json" )
281
+ if provider .apiKey != "" {
282
+ goffRequest .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , provider .apiKey ))
283
+ }
279
284
280
285
response , err := provider .httpClient .Do (goffRequest )
281
286
if err != nil {
@@ -298,6 +303,27 @@ func evaluateWithRelayProxy[T model.JsonType](provider *Provider, ctx context.Co
298
303
}
299
304
}
300
305
306
+ if response .StatusCode == http .StatusUnauthorized {
307
+ return model.GenericResolutionDetail [T ]{
308
+ Value : defaultValue ,
309
+ ProviderResolutionDetail : of.ProviderResolutionDetail {
310
+ ResolutionError : of .NewGeneralResolutionError (
311
+ "invalid token used to contact GO Feature Flag relay proxy instance" ),
312
+ Reason : of .ErrorReason ,
313
+ },
314
+ }
315
+ }
316
+ if response .StatusCode >= http .StatusBadRequest {
317
+ return model.GenericResolutionDetail [T ]{
318
+ Value : defaultValue ,
319
+ ProviderResolutionDetail : of.ProviderResolutionDetail {
320
+ ResolutionError : of .NewGeneralResolutionError (
321
+ "unexpected answer from the relay proxy" ),
322
+ Reason : of .ErrorReason ,
323
+ },
324
+ }
325
+ }
326
+
301
327
var evalResponse model.EvalResponse [T ]
302
328
err = json .Unmarshal (responseStr , & evalResponse )
303
329
if err != nil {
0 commit comments