Skip to content

Commit d70a27f

Browse files
committed
removed acquire package; moved aquire to chrysom; added back in auth to basicclientconfig
1 parent 037c5bb commit d70a27f

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed
+2-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
// SPDX-FileCopyrightText: 2024 Comcast Cable Communications Management, LLC
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package acquire
4+
package chrysom
55

66
import (
77
"net/http"
8-
"time"
98
)
109

10+
// Acquirer adds an authorization header and value to a given http request.
1111
type Acquirer interface {
1212
AddAuth(*http.Request) error
13-
Acquire() (string, error)
14-
ParseToken([]byte) (string, error)
15-
ParseExpiration([]byte) (time.Time, error)
1613
}

chrysom/basicClient.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"io"
1313
"net/http"
1414

15-
"github.com/xmidt-org/ancla/acquire"
1615
"github.com/xmidt-org/ancla/model"
1716
"github.com/xmidt-org/sallust"
1817
"go.uber.org/zap"
@@ -55,12 +54,16 @@ type BasicClientConfig struct {
5554
// HTTPClient refers to the client that will be used to send requests.
5655
// (Optional) Defaults to http.DefaultClient.
5756
HTTPClient *http.Client
57+
58+
// Auth provides the mechanism to add auth headers to outgoing requests.
59+
// (Optional) If not provided, no auth headers are added.
60+
Auth Acquirer
5861
}
5962

6063
// BasicClient is the client used to make requests to Argus.
6164
type BasicClient struct {
6265
client *http.Client
63-
auth acquire.Acquirer
66+
auth Acquirer
6467
storeBaseURL string
6568
bucket string
6669
}
@@ -83,7 +86,7 @@ type Items []model.Item
8386

8487
// NewBasicClient creates a new BasicClient that can be used to
8588
// make requests to Argus.
86-
func NewBasicClient(config BasicClientConfig, auth acquire.Acquirer) (*BasicClient, error) {
89+
func NewBasicClient(config BasicClientConfig) (*BasicClient, error) {
8790
err := validateBasicConfig(&config)
8891
if err != nil {
8992
return nil, err
@@ -94,7 +97,7 @@ func NewBasicClient(config BasicClientConfig, auth acquire.Acquirer) (*BasicClie
9497
}
9598
clientStore := &BasicClient{
9699
client: config.HTTPClient,
97-
auth: auth,
100+
auth: config.Auth,
98101
bucket: config.Bucket,
99102
storeBaseURL: config.Address + storeAPIPath,
100103
}

service.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"net/http"
1111
"time"
1212

13-
"github.com/xmidt-org/ancla/acquire"
1413
"github.com/xmidt-org/ancla/chrysom"
1514
"github.com/xmidt-org/sallust"
1615
"go.uber.org/fx"
@@ -43,13 +42,6 @@ type Service interface {
4342
type Config struct {
4443
BasicClientConfig chrysom.BasicClientConfig
4544

46-
// JWTParserType establishes which parser type will be used by the JWT token
47-
// acquirer used by Argus. Options include 'simple' and 'raw'.
48-
// Simple: parser assumes token payloads have the following structure: https://github.com/xmidt-org/bascule/blob/c011b128d6b95fa8358228535c63d1945347adaa/acquire/bearer.go#L77
49-
// Raw: parser assumes all of the token payload == JWT token
50-
// (Optional). Defaults to 'simple'
51-
JWTParserType string
52-
5345
// DisablePartnerIDs, if true, will allow webhooks to register without
5446
// checking the validity of the partnerIDs in the request
5547
DisablePartnerIDs bool
@@ -69,8 +61,8 @@ type ClientService struct {
6961
}
7062

7163
// NewService builds the Argus client service from the given configuration.
72-
func NewService(cfg Config, auth acquire.Acquirer) (*ClientService, error) {
73-
basic, err := chrysom.NewBasicClient(cfg.BasicClientConfig, auth)
64+
func NewService(cfg Config) (*ClientService, error) {
65+
basic, err := chrysom.NewBasicClient(cfg.BasicClientConfig)
7466
if err != nil {
7567
return nil, fmt.Errorf("failed to create chrysom basic client: %v", err)
7668
}
@@ -153,13 +145,13 @@ type ServiceIn struct {
153145

154146
Config Config
155147
Client *http.Client
156-
Auth acquire.Acquirer
148+
Auth chrysom.Acquirer
157149
}
158150

159151
func ProvideService() fx.Option {
160152
return fx.Provide(
161153
func(in ServiceIn) (*ClientService, error) {
162-
svc, err := NewService(in.Config, in.Auth)
154+
svc, err := NewService(in.Config)
163155
if err != nil {
164156
return nil, errors.Join(errFailedConfig, err)
165157
}

0 commit comments

Comments
 (0)