Skip to content

Commit

Permalink
draft: removing bascule/acquire
Browse files Browse the repository at this point in the history
  • Loading branch information
maurafortino committed Nov 18, 2024
1 parent e1bb210 commit 037c5bb
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 209 deletions.
2 changes: 1 addition & 1 deletion acquire/acquire.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type Acquirer interface {
AddAuth(*http.Request)
AddAuth(*http.Request) error
Acquire() (string, error)
ParseToken([]byte) (string, error)
ParseExpiration([]byte) (time.Time, error)
Expand Down
20 changes: 3 additions & 17 deletions chrysom/basicClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,18 @@ type Items []model.Item

// NewBasicClient creates a new BasicClient that can be used to
// make requests to Argus.
func NewBasicClient(config BasicClientConfig) (*BasicClient, error) {
func NewBasicClient(config BasicClientConfig, auth acquire.Acquirer) (*BasicClient, error) {
err := validateBasicConfig(&config)
if err != nil {
return nil, err
}

tokenAcquirer, err := buildTokenAcquirer(config.Auth)
if err != nil {
return nil, err
}
clientStore := &BasicClient{
client: config.HTTPClient,
auth: tokenAcquirer,
auth: auth,
bucket: config.Bucket,
storeBaseURL: config.Address + storeAPIPath,
}
Expand Down Expand Up @@ -200,7 +199,7 @@ func (c *BasicClient) sendRequest(ctx context.Context, owner, method, url string
if err != nil {
return response{}, fmt.Errorf(errWrappedFmt, errNewRequestFailure, err.Error())
}
err = acquire.AddAuth(r, c.auth)
err = c.auth.AddAuth(r)
if err != nil {
return response{}, fmt.Errorf(errWrappedFmt, ErrAuthAcquirerFailure, err.Error())
}
Expand All @@ -224,10 +223,6 @@ func (c *BasicClient) sendRequest(ctx context.Context, owner, method, url string
return sqResp, nil
}

func isEmpty(options acquire.RemoteBearerTokenAcquirerOptions) bool {
return len(options.AuthURL) < 1 || options.Buffer == 0 || options.Timeout == 0
}

// translateNonSuccessStatusCode returns as specific error
// for known Argus status codes.
func translateNonSuccessStatusCode(code int) error {
Expand All @@ -241,15 +236,6 @@ func translateNonSuccessStatusCode(code int) error {
}
}

func buildTokenAcquirer(auth Auth) (acquire.Acquirer, error) {
if !isEmpty(auth.JWT) {
return acquire.NewRemoteBearerTokenAcquirer(auth.JWT)
} else if len(auth.Basic) > 0 {
return acquire.NewFixedAuthAcquirer(auth.Basic)
}
return &acquire.DefaultAcquirer{}, nil
}

func validateBasicConfig(config *BasicClientConfig) error {
if config.Address == "" {
return ErrAddressEmpty
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ toolchain go1.22.9
require (
github.com/aws/aws-sdk-go v1.54.19
github.com/go-kit/kit v0.13.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/lestrrat-go/jwx/v2 v2.1.2
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/client_model v0.6.1
github.com/spf13/cast v1.6.0
github.com/stretchr/testify v1.9.0
github.com/xmidt-org/bascule v0.11.6
github.com/xmidt-org/httpaux v0.4.0
github.com/xmidt-org/sallust v0.2.2
github.com/xmidt-org/touchstone v0.1.5
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
Expand Down Expand Up @@ -65,8 +63,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xmidt-org/bascule v0.11.6 h1:i46FAI97XPMt3OKraiNyKa+mt36AhLO8iuInAypXKNM=
github.com/xmidt-org/bascule v0.11.6/go.mod h1:BXb5PEm/tjqdiEGsd+phm+fItMJx+Huv6LTCEU/zTzg=
github.com/xmidt-org/httpaux v0.4.0 h1:cAL/MzIBpSsv4xZZeq/Eu1J5M3vfNe49xr41mP3COKU=
github.com/xmidt-org/httpaux v0.4.0/go.mod h1:UypqZwuZV1nn8D6+K1JDb+im9IZrLNg/2oO/Bgiybxc=
github.com/xmidt-org/sallust v0.2.2 h1:MrINLEr7cMj6ENx/O76fvpfd5LNGYnk7OipZAGXPYA0=
Expand Down
76 changes: 0 additions & 76 deletions jwtAcquireParser.go

This file was deleted.

94 changes: 0 additions & 94 deletions jwtAcquireParser_test.go

This file was deleted.

22 changes: 7 additions & 15 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"time"

"github.com/xmidt-org/ancla/acquire"
"github.com/xmidt-org/ancla/chrysom"
"github.com/xmidt-org/sallust"
"go.uber.org/fx"
Expand Down Expand Up @@ -47,7 +48,7 @@ type Config struct {
// Simple: parser assumes token payloads have the following structure: https://github.com/xmidt-org/bascule/blob/c011b128d6b95fa8358228535c63d1945347adaa/acquire/bearer.go#L77
// Raw: parser assumes all of the token payload == JWT token
// (Optional). Defaults to 'simple'
JWTParserType jwtAcquireParserType
JWTParserType string

// DisablePartnerIDs, if true, will allow webhooks to register without
// checking the validity of the partnerIDs in the request
Expand All @@ -68,9 +69,8 @@ type ClientService struct {
}

// NewService builds the Argus client service from the given configuration.
func NewService(cfg Config) (*ClientService, error) {
prepArgusBasicClientConfig(&cfg)
basic, err := chrysom.NewBasicClient(cfg.BasicClientConfig)
func NewService(cfg Config, auth acquire.Acquirer) (*ClientService, error) {
basic, err := chrysom.NewBasicClient(cfg.BasicClientConfig, auth)
if err != nil {
return nil, fmt.Errorf("failed to create chrysom basic client: %v", err)
}
Expand Down Expand Up @@ -133,16 +133,6 @@ func (s *ClientService) GetAll(ctx context.Context) ([]Register, error) {
return iws, nil
}

func prepArgusBasicClientConfig(cfg *Config) error {
p, err := newJWTAcquireParser(cfg.JWTParserType)
if err != nil {
return err
}
cfg.BasicClientConfig.Auth.JWT.GetToken = p.token
cfg.BasicClientConfig.Auth.JWT.GetExpiration = p.expiration
return nil
}

func prepArgusListenerConfig(cfg *chrysom.ListenerConfig, metrics chrysom.Measures, watches ...Watch) {
watches = append(watches, webhookListSizeWatch(metrics.WebhookListSizeGauge))
cfg.Listener = chrysom.ListenerFunc(func(ctx context.Context, items chrysom.Items) {
Expand All @@ -160,14 +150,16 @@ func prepArgusListenerConfig(cfg *chrysom.ListenerConfig, metrics chrysom.Measur

type ServiceIn struct {
fx.In

Config Config
Client *http.Client
Auth acquire.Acquirer
}

func ProvideService() fx.Option {
return fx.Provide(
func(in ServiceIn) (*ClientService, error) {
svc, err := NewService(in.Config)
svc, err := NewService(in.Config, in.Auth)
if err != nil {
return nil, errors.Join(errFailedConfig, err)
}
Expand Down

0 comments on commit 037c5bb

Please sign in to comment.