Skip to content

Commit

Permalink
For analytics records, upload a singular product that was used for an…
Browse files Browse the repository at this point in the history
… authorized operation. This replaces the existing functionality that picked a random matching product from the credential
  • Loading branch information
KyleWiese committed Sep 26, 2024
1 parent 0673c38 commit d2cf05e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
6 changes: 1 addition & 5 deletions analytics/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@ func (r Record) EnsureFields(authContext *auth.Context) Record {
r.ClientID = authContext.ClientID
r.Organization = authContext.Organization()
r.Environment = authContext.Environment()

r.GatewayFlowID = uuid.New().String()
r.APIProduct = authContext.AnalyticsProduct

// select arbitrary APIProduct
if len(authContext.APIProducts) > 0 {
r.APIProduct = authContext.APIProducts[0]
}
return r
}

Expand Down
1 change: 1 addition & 0 deletions auth/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Context struct {
Scopes []string
APIKey string
CustomAttributes string
AnalyticsProduct string // A single product to attatch to analytics records based on matched operations.
}

// if claims can't be processed, returns error and sets no fields
Expand Down
1 change: 1 addition & 0 deletions product/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type AuthorizedOperation struct {
QuotaLimit int64
QuotaInterval int64
QuotaTimeUnit string
APIProduct string
}

// Authorize a request against API Products and its Operations
Expand Down
2 changes: 2 additions & 0 deletions product/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func (p *APIProduct) authorize(authContext *auth.Context, api, path, method stri
QuotaLimit: p.QuotaLimitInt,
QuotaInterval: p.QuotaIntervalInt,
QuotaTimeUnit: p.QuotaTimeUnit,
APIProduct: p.Name,
}
// OperationConfig quota is an override
if oc.Quota != nil && oc.Quota.LimitInt > 0 {
Expand Down Expand Up @@ -353,6 +354,7 @@ func (p *APIProduct) authorize(authContext *auth.Context, api, path, method stri
QuotaLimit: p.QuotaLimitInt,
QuotaInterval: p.QuotaIntervalInt,
QuotaTimeUnit: p.QuotaTimeUnit,
APIProduct: p.Name,
})
hint = " authorized\n"

Expand Down
2 changes: 2 additions & 0 deletions product/product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func TestAuthorize(t *testing.T) {
wantAuthOp: &AuthorizedOperation{
ID: "Name [email protected]",
QuotaLimit: productsMap["Name 2"].QuotaLimitInt,
APIProduct: "Name 2",
},
wantHints: `Authorizing request:
environment: prod
Expand Down Expand Up @@ -255,6 +256,7 @@ func TestAuthorize(t *testing.T) {
wantAuthOp: &AuthorizedOperation{
ID: "Name [email protected]",
QuotaLimit: productsMap["Name 1"].QuotaLimitInt,
APIProduct: "Name 1",
},
wantHints: `Authorizing request:
environment: prod
Expand Down

0 comments on commit d2cf05e

Please sign in to comment.