@@ -13,7 +13,6 @@ import (
13
13
"net/http"
14
14
15
15
"github.com/xmidt-org/ancla/model"
16
- "github.com/xmidt-org/bascule/acquire"
17
16
"github.com/xmidt-org/sallust"
18
17
"go.uber.org/zap"
19
18
)
25
24
ErrItemDataEmpty = errors .New ("data field in item is required" )
26
25
ErrUndefinedIntervalTicker = errors .New ("interval ticker is nil. Can't listen for updates" )
27
26
ErrAuthAcquirerFailure = errors .New ("failed acquiring auth token" )
27
+ ErrAuthAcquirerNil = errors .New ("auth aquirer is nil" )
28
28
ErrBadRequest = errors .New ("argus rejected the request as invalid" )
29
29
)
30
30
@@ -58,23 +58,17 @@ type BasicClientConfig struct {
58
58
59
59
// Auth provides the mechanism to add auth headers to outgoing requests.
60
60
// (Optional) If not provided, no auth headers are added.
61
- Auth Auth
61
+ Auth Acquirer
62
62
}
63
63
64
64
// BasicClient is the client used to make requests to Argus.
65
65
type BasicClient struct {
66
66
client * http.Client
67
- auth acquire. Acquirer
67
+ auth Acquirer
68
68
storeBaseURL string
69
69
bucket string
70
70
}
71
71
72
- // Auth contains authorization data for requests to Argus.
73
- type Auth struct {
74
- JWT acquire.RemoteBearerTokenAcquirerOptions
75
- Basic string
76
- }
77
-
78
72
type response struct {
79
73
Body []byte
80
74
ArgusErrorHeader string
@@ -99,13 +93,9 @@ func NewBasicClient(config BasicClientConfig) (*BasicClient, error) {
99
93
return nil , err
100
94
}
101
95
102
- tokenAcquirer , err := buildTokenAcquirer (config .Auth )
103
- if err != nil {
104
- return nil , err
105
- }
106
96
clientStore := & BasicClient {
107
97
client : config .HTTPClient ,
108
- auth : tokenAcquirer ,
98
+ auth : config . Auth ,
109
99
bucket : config .Bucket ,
110
100
storeBaseURL : config .Address + storeAPIPath ,
111
101
}
@@ -210,7 +200,10 @@ func (c *BasicClient) sendRequest(ctx context.Context, owner, method, url string
210
200
if err != nil {
211
201
return response {}, fmt .Errorf (errWrappedFmt , errNewRequestFailure , err .Error ())
212
202
}
213
- err = acquire .AddAuth (r , c .auth )
203
+ if c .auth == nil {
204
+ return response {}, ErrAuthAcquirerNil
205
+ }
206
+ err = c .auth .AddAuth (r )
214
207
if err != nil {
215
208
return response {}, fmt .Errorf (errWrappedFmt , ErrAuthAcquirerFailure , err .Error ())
216
209
}
@@ -234,10 +227,6 @@ func (c *BasicClient) sendRequest(ctx context.Context, owner, method, url string
234
227
return sqResp , nil
235
228
}
236
229
237
- func isEmpty (options acquire.RemoteBearerTokenAcquirerOptions ) bool {
238
- return len (options .AuthURL ) < 1 || options .Buffer == 0 || options .Timeout == 0
239
- }
240
-
241
230
// translateNonSuccessStatusCode returns as specific error
242
231
// for known Argus status codes.
243
232
func translateNonSuccessStatusCode (code int ) error {
@@ -251,15 +240,6 @@ func translateNonSuccessStatusCode(code int) error {
251
240
}
252
241
}
253
242
254
- func buildTokenAcquirer (auth Auth ) (acquire.Acquirer , error ) {
255
- if ! isEmpty (auth .JWT ) {
256
- return acquire .NewRemoteBearerTokenAcquirer (auth .JWT )
257
- } else if len (auth .Basic ) > 0 {
258
- return acquire .NewFixedAuthAcquirer (auth .Basic )
259
- }
260
- return & acquire.DefaultAcquirer {}, nil
261
- }
262
-
263
243
func validateBasicConfig (config * BasicClientConfig ) error {
264
244
if config .Address == "" {
265
245
return ErrAddressEmpty
0 commit comments