Skip to content

Commit

Permalink
Passing environment field to the interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
pubudu538 committed Oct 18, 2023
1 parent 16c5a85 commit 8072497
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions adapter/internal/interceptor/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type InvocationContext struct {
Vhost string
ClusterName string
APIProperties string
Environment string
}

var (
Expand All @@ -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}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func getGlobalInterceptorScript(gatewayAPIPolicies map[string]dpv1alpha1.APIPoli
OrganizationID: "",
BasePath: "",
SupportedMethods: "",
Environment: "",
APIName: "",
APIVersion: "",
PathTemplate: "",
Expand Down
3 changes: 3 additions & 0 deletions developer/resources/interceptor-service-open-api-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ components:
keyType:
type: string
example: PRODUCTION
environment:
type: string
example: Development
InterceptorContext:
title: Interceptor Context
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion gateway/router/resources/interceptor/lib/consts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/interceptor-backend/ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public type InvocationContext record {
string prodClusterName?;
string sandClusterName?;
string apiProperties?;
string environment?;
InvocationContext_authenticationContext authenticationContext?;
};

Expand Down

0 comments on commit 8072497

Please sign in to comment.