Skip to content

Commit

Permalink
Change endpoint field to path
Browse files Browse the repository at this point in the history
  • Loading branch information
kchiranjewee63 committed Aug 6, 2024
1 parent d0de25d commit a2536d5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ In this mode, incoming requests are not intercepted; instead, requests must be m

**Sample API Endpoint:** http://localhost:<agentApiPort>/verify-trat

For example, if `agentApiPort` is configured as `9030`, the full API endpoint would be: `http://localhost:9030/verify-trat`
For example, if `agentApiPort` is configured as `9030`, the full API endpoint would be: `POST http://localhost:9030/verify-trat`

This endpoint takes request data as input and responds with the result of the TraT verification.

Expand All @@ -66,7 +66,7 @@ Structure:

```json
{
"endpoint": "request URL path",
"path": "request URL path",
"method": "request HTTP method",
"body": "request JSON payload",
"headers": "JSON object of request HTTP headers",
Expand All @@ -78,7 +78,7 @@ Example:

```json
{
"endpoint": "/order",
"path": "/order",
"method": "POST",
"body": {
"stockID": 12345,
Expand Down
6 changes: 3 additions & 3 deletions service/api/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewHandlers(service *service.Service, logger *zap.Logger) *Handlers {
}

type VerifyTraTRequest struct {
Path string `json:"endpoint"`
Path string `json:"path"`
Method common.HttpMethod `json:"method"`
QueryParameters json.RawMessage `json:"queryParameters"`
Headers json.RawMessage `json:"headers"`
Expand Down Expand Up @@ -76,7 +76,7 @@ func (h *Handlers) VerifyTraTHandler(w http.ResponseWriter, r *http.Request) {
return
}

h.logger.Info("Received verify trat request", zap.String("endpoint", verifyTraTRequest.Path), zap.String("method", string(verifyTraTRequest.Method)))
h.logger.Info("Received verify trat request", zap.String("path", verifyTraTRequest.Path), zap.String("method", string(verifyTraTRequest.Method)))

trat := headers["Txn-Token"]

Expand All @@ -95,7 +95,7 @@ func (h *Handlers) VerifyTraTHandler(w http.ResponseWriter, r *http.Request) {
verifyTraTResponse.Valid = false
verifyTraTResponse.Reason = reason

h.logger.Error("Invalid trat", zap.String("endpoint", verifyTraTRequest.Path), zap.String("method", string(verifyTraTRequest.Method)), zap.String("reason", reason))
h.logger.Error("Invalid trat", zap.String("path", verifyTraTRequest.Path), zap.String("method", string(verifyTraTRequest.Method)), zap.String("reason", reason))
} else {
verifyTraTResponse.Valid = true
}
Expand Down
2 changes: 1 addition & 1 deletion service/tratinterceptor/interceptverifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (iv *TraTInterceptor) tratVerificationMiddleware(next http.Handler) http.Ha
}

if !valid {
iv.logger.Error("Invalid trat", zap.String("endpoint", r.URL.Path), zap.String("method", r.Method), zap.String("reason", reason))
iv.logger.Error("Invalid trat", zap.String("path", r.URL.Path), zap.String("method", r.Method), zap.String("reason", reason))
http.Error(w, "Invalid trat", http.StatusUnauthorized)

return
Expand Down
10 changes: 5 additions & 5 deletions service/verificationrules/v1alpha1/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type TratteriaConfigVerificationRule struct {

type TraTVerificationRule struct {
TraTName string `json:"traTName"`
Endpoint string `json:"endpoint"`
Path string `json:"path"`
Method common.HttpMethod `json:"method"`
Purp string `json:"purp"`
AzdMapping AzdMapping `json:"azdmapping,omitempty"`
Expand Down Expand Up @@ -168,12 +168,12 @@ func (vri *VerificationRulesImp) indexTraTsVerificationRules() {
if vri.verificationRules != nil && vri.verificationRules.TraTsVerificationRules != nil {
for _, serviceRules := range vri.verificationRules.TraTsVerificationRules {
for _, rule := range serviceRules.TraTVerificationRules {
if indexedRules[rule.Method][rule.Endpoint] == nil {
indexedRules[rule.Method][rule.Endpoint] = &EndpointRule{Skip: false}
if indexedRules[rule.Method][rule.Path] == nil {
indexedRules[rule.Method][rule.Path] = &EndpointRule{Skip: false}
}

indexedRules[rule.Method][rule.Endpoint].Rules = append(
indexedRules[rule.Method][rule.Endpoint].Rules, rule)
indexedRules[rule.Method][rule.Path].Rules = append(
indexedRules[rule.Method][rule.Path].Rules, rule)
}
}
}
Expand Down

0 comments on commit a2536d5

Please sign in to comment.