diff --git a/adapter/internal/interceptor/interceptor.go b/adapter/internal/interceptor/interceptor.go index 10760a0057..8c26b24c5e 100644 --- a/adapter/internal/interceptor/interceptor.go +++ b/adapter/internal/interceptor/interceptor.go @@ -71,6 +71,7 @@ type InvocationContext struct { Vhost string ClusterName string APIProperties string + Environment string } var ( @@ -89,6 +90,7 @@ var ( organizationId = "{{.Context.OrganizationID}}", basePath = "{{.Context.BasePath}}", supportedMethods = "{{.Context.SupportedMethods}}", + environment = "{{.Context.Environment}}", apiName = "{{.Context.APIName}}", apiVersion = "{{.Context.APIVersion}}", pathTemplate = "{{.Context.PathTemplate}}", diff --git a/adapter/internal/oasparser/envoyconf/routes_with_clusters.go b/adapter/internal/oasparser/envoyconf/routes_with_clusters.go index 1792b31812..f24b87e9e4 100644 --- a/adapter/internal/oasparser/envoyconf/routes_with_clusters.go +++ b/adapter/internal/oasparser/envoyconf/routes_with_clusters.go @@ -766,6 +766,7 @@ func createRoutes(params *routeCreateParams) (routes []*routev3.Route, err error Vhost: contextExtensions[vHostContextExtension], ClusterName: contextExtensions[clusterNameContextExtension], APIProperties: getAPIProperties(params.apiProperties), + Environment: params.environment, } luaPerFilterConfig = lua.LuaPerRoute{ Override: &lua.LuaPerRoute_SourceCode{ diff --git a/adapter/internal/operator/synchronizer/gateway_synchronizer.go b/adapter/internal/operator/synchronizer/gateway_synchronizer.go index ac0b0789b4..73d01a6cd2 100644 --- a/adapter/internal/operator/synchronizer/gateway_synchronizer.go +++ b/adapter/internal/operator/synchronizer/gateway_synchronizer.go @@ -159,6 +159,7 @@ func getGlobalInterceptorScript(gatewayAPIPolicies map[string]dpv1alpha1.APIPoli OrganizationID: "", BasePath: "", SupportedMethods: "", + Environment: "", APIName: "", APIVersion: "", PathTemplate: "", diff --git a/developer/resources/interceptor-service-open-api-v1.yaml b/developer/resources/interceptor-service-open-api-v1.yaml index 90400f53af..24dbbb5d6d 100644 --- a/developer/resources/interceptor-service-open-api-v1.yaml +++ b/developer/resources/interceptor-service-open-api-v1.yaml @@ -230,6 +230,9 @@ components: keyType: type: string example: PRODUCTION + environment: + type: string + example: Development InterceptorContext: title: Interceptor Context type: object diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/InterceptorConstants.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/InterceptorConstants.java index b456a1972a..706efc52a7 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/InterceptorConstants.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/InterceptorConstants.java @@ -42,6 +42,7 @@ public static class APIMetadataFields { public static final String API_VERSION = "apiVersion"; public static final String API_VHOST = "vhost"; public static final String API_ORGANIZATION_ID = "organizationId"; + public static final String ENVIRONMENT = "environment"; } } diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/AuthFilter.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/AuthFilter.java index 59701b92b0..0715006e4e 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/AuthFilter.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/AuthFilter.java @@ -248,6 +248,8 @@ private void setInterceptorAPIMetadata(RequestContext requestContext) { Objects.toString(requestContext.getMatchedAPI().getVhost(), "")); requestContext.addMetadataToMap(InterceptorConstants.APIMetadataFields.API_ORGANIZATION_ID, Objects.toString(requestContext.getMatchedAPI().getOrganizationId(), "")); + requestContext.addMetadataToMap(InterceptorConstants.APIMetadataFields.ENVIRONMENT, + Objects.toString(requestContext.getMatchedAPI().getEnvironment(), "")); } private void populateRemoveAndProtectedAuthHeaders(RequestContext requestContext) { diff --git a/gateway/router/resources/interceptor/lib/consts.lua b/gateway/router/resources/interceptor/lib/consts.lua index e3b94a3186..ea5b89bc70 100644 --- a/gateway/router/resources/interceptor/lib/consts.lua +++ b/gateway/router/resources/interceptor/lib/consts.lua @@ -52,7 +52,8 @@ INV_CONTEXT = { VHOST = "vhost", API_NAME = "apiName", API_VERSION = "apiVersion", - AUTH_CTX = "authenticationContext" + AUTH_CTX = "authenticationContext", + ENVIRONMENT = "environment" } -- keys of the payload to the auth context diff --git a/test/interceptor-backend/ballerina/types.bal b/test/interceptor-backend/ballerina/types.bal index 76ebe5010b..70a90892da 100644 --- a/test/interceptor-backend/ballerina/types.bal +++ b/test/interceptor-backend/ballerina/types.bal @@ -142,6 +142,7 @@ public type InvocationContext record { string prodClusterName?; string sandClusterName?; string apiProperties?; + string environment?; InvocationContext_authenticationContext authenticationContext?; };