Skip to content

Commit

Permalink
Fixed subscription issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Krishanx92 committed Feb 7, 2025
1 parent c5fd883 commit 1916110
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions gateway/enforcer/internal/authorization/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ValidateSubscription(rch *requestconfig.Holder, subAppDataStore *datastore.
clientID := rch.JWTValidationInfo.ClientID
if rch.MatchedAPI.SubscriptionValidation {
if rch.JWTValidationInfo.ClientID != "" {
appID := getAppIDUsingConsumerKey(clientID, subAppDataStore, api, "oauth2")
appID := getAppIDUsingConsumerKey(clientID, subAppDataStore, api, "OAuth2")
if appID != "" {
appMaps := subAppDataStore.GetApplicationMappings(api.OrganizationID, appID)
for _, appMap := range appMaps {
Expand Down Expand Up @@ -46,7 +46,7 @@ func getAppIDUsingConsumerKey(consumerKey string, subAppDatastore *datastore.Sub
appKeyMapKey := util.PrepareApplicationKeyMappingCacheKey(consumerKey, api.EnvType, securityScheme, api.Environment)
appKeyMap := subAppDatastore.GetApplicationKeyMapping(api.OrganizationID, appKeyMapKey)
if appKeyMap != nil {
return appKeyMap.ApplicationIdentifier
return appKeyMap.ApplicationUUID
}
return ""
}
15 changes: 7 additions & 8 deletions gateway/enforcer/internal/extproc/ext_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_service_proc_v3 "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
v32 "github.com/envoyproxy/go-control-plane/envoy/type/v3"
"github.com/wso2/apk/common-go-libs/loggers"
"github.com/wso2/apk/gateway/enforcer/internal/analytics"
"github.com/wso2/apk/gateway/enforcer/internal/authorization"
"github.com/wso2/apk/gateway/enforcer/internal/config"
Expand Down Expand Up @@ -86,8 +87,7 @@ const (
matchedAPIMetadataKey string = "request:matchedapi"
matchedResourceMetadataKey string = "request:matchedresource"
matchedSubscriptionMetadataKey string = "request:matchedsubscription"
matchedApplicationMetadataKey string = "request:matchedapplication"

matchedApplicationMetadataKey string = "request:matchedapplication"

modelMetadataKey string = "aitoken:model"
)
Expand Down Expand Up @@ -224,6 +224,7 @@ func (s *ExternalProcessingServer) Process(srv envoy_service_proc_v3.ExternalPro
}
resp = &envoy_service_proc_v3.ProcessingResponse{}
if requestConfigHolder.MatchedSubscription != nil && requestConfigHolder.MatchedSubscription.RatelimitTier != "Unlimited" && requestConfigHolder.MatchedSubscription.RatelimitTier != "" {
loggers.LoggerAPK.Info(fmt.Sprintf("Ratelimit Tier: %s", requestConfigHolder.MatchedSubscription.RatelimitTier))
dynamicMetadataKeyValuePairs[subscriptionMetadataKey] = requestConfigHolder.MatchedSubscription.UUID
dynamicMetadataKeyValuePairs[usagePolicyMetadataKey] = requestConfigHolder.MatchedSubscription.RatelimitTier
dynamicMetadataKeyValuePairs[organizationMetadataKey] = requestConfigHolder.MatchedAPI.OrganizationID
Expand Down Expand Up @@ -253,11 +254,10 @@ func (s *ExternalProcessingServer) Process(srv envoy_service_proc_v3.ExternalPro
}
if backendJWT != "" {
rhq.Response.HeaderMutation.SetHeaders = append(rhq.Response.HeaderMutation.SetHeaders, &corev3.HeaderValueOption{
Header: &corev3.HeaderValue{
Key: requestConfigHolder.MatchedAPI.BackendJwtConfiguration.JWTHeader,
RawValue: []byte(backendJWT),
},

Header: &corev3.HeaderValue{
Key: requestConfigHolder.MatchedAPI.BackendJwtConfiguration.JWTHeader,
RawValue: []byte(backendJWT),
},
})
s.cfg.Logger.Info(fmt.Sprintf("Added backend JWT to the header: %s, header name: %s", backendJWT, requestConfigHolder.MatchedAPI.BackendJwtConfiguration.JWTHeader))
}
Expand All @@ -271,7 +271,6 @@ func (s *ExternalProcessingServer) Process(srv envoy_service_proc_v3.ExternalPro
if requestConfigHolder.MatchedSubscription != nil {
dynamicMetadataKeyValuePairs[matchedSubscriptionMetadataKey] = requestConfigHolder.MatchedSubscription.UUID
}


case *envoy_service_proc_v3.ProcessingRequest_RequestBody:
// httpBody := req.GetRequestBody()
Expand Down

0 comments on commit 1916110

Please sign in to comment.