Skip to content

Commit 85acb5f

Browse files
authored
Merge pull request #3751 from shanakama/header-to-metadata
Adding header-to-metadata filter
2 parents 1f817fd + fcae420 commit 85acb5f

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

adapter/internal/oasparser/envoyconf/http_filters.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
2727
envoy_config_ratelimit_v3 "github.com/envoyproxy/go-control-plane/envoy/config/ratelimit/v3"
2828
cors_filter_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/cors/v3"
29+
header_to_metadata_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/header_to_metadata/v3"
2930
ext_authv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_authz/v3"
3031
local_ratelimit_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/local_ratelimit/v3"
3132
luav3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/lua/v3"
@@ -56,8 +57,10 @@ func getHTTPFilters() []*hcmv3.HttpFilter {
5657
lua := getLuaFilter()
5758
cors := getCorsHTTPFilter()
5859
localRateLimit := getHTTPLocalRateLimitFilter()
60+
headerToMetadata := getHeaderToMetadataHTTPFilter()
5961

6062
httpFilters := []*hcmv3.HttpFilter{
63+
headerToMetadata,
6164
cors,
6265
localRateLimit,
6366
extAauth,
@@ -385,3 +388,44 @@ func getMgwWebSocketWASMFilter() *hcmv3.HttpFilter {
385388
return &mgwWebSocketFilter
386389

387390
}
391+
392+
func getHeaderToMetadataHTTPFilter() *hcmv3.HttpFilter {
393+
logger.LoggerOasparser.Debug("Creating header-to-metadata HTTP filter")
394+
headerToMetadataConf := header_to_metadata_v3.Config{
395+
ResponseRules: []*header_to_metadata_v3.Config_Rule{
396+
{
397+
Header: "x-choreo-host",
398+
OnHeaderPresent: &header_to_metadata_v3.Config_KeyValuePair{
399+
MetadataNamespace: "envoy.lb",
400+
Key: "choreo-upstream-host",
401+
Type: header_to_metadata_v3.Config_STRING,
402+
},
403+
Remove: true,
404+
},
405+
},
406+
}
407+
408+
filterTypedConf, err := anypb.New(&headerToMetadataConf)
409+
410+
if err != nil {
411+
logger.LoggerOasparser.Error("Error marshaling header-to-metadata filter configs. ", err)
412+
}
413+
logger.LoggerOasparser.Debug("Successfully created header-to-metadata filter configuration")
414+
filter := hcmv3.HttpFilter{
415+
Name: "envoy.filters.http.header_to_metadata",
416+
ConfigType: &hcmv3.HttpFilter_TypedConfig{TypedConfig: filterTypedConf},
417+
}
418+
419+
if (enableRouterConfigValidation) {
420+
err = filter.Validate()
421+
if err != nil {
422+
if panicOnValidationFailure {
423+
logger.LoggerOasparser.Fatal("Error while validating header-to-metadata HTTP filter configs. ", err)
424+
} else {
425+
logger.LoggerOasparser.Error("Error while validating header-to-metadata HTTP filter configs. ", err)
426+
}
427+
}
428+
}
429+
430+
return &filter
431+
}

adapter/pkg/config/log_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func getDefaultLogConfig() *LogConfig {
122122
"apiUuid": "%DYNAMIC_METADATA(envoy.filters.http.ext_authz:apiUUID)%",
123123
"extAuthDtls": "%DYNAMIC_METADATA(envoy.filters.http.ext_authz:extAuthDetails)%",
124124
"resourcePath": "%DYNAMIC_METADATA(envoy.filters.http.ext_authz:resourcePath)%",
125+
"choreoUpstreamHost": "%DYNAMIC_METADATA(envoy.lb:choreo-upstream-host)%",
125126
},
126127
},
127128
InsightsLogs: &insightsLog{

enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/validator/JWTValidator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.wso2.carbon.apimgt.common.gateway.exception.JWTGeneratorException;
3333
import org.wso2.carbon.apimgt.common.gateway.jwttransformer.DefaultJWTTransformer;
3434
import org.wso2.carbon.apimgt.common.gateway.jwttransformer.JWTTransformer;
35-
import org.wso2.choreo.connect.enforcer.config.ConfigHolder;
3635
import org.wso2.choreo.connect.enforcer.config.dto.ExtendedTokenIssuerDto;
3736
import org.wso2.choreo.connect.enforcer.constants.APIConstants;
3837
import org.wso2.choreo.connect.enforcer.exception.EnforcerException;

integration/test-integration/src/test/resources/testng-cc-standalone.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
<test name="cc-with-jwt-config-and-transformer" preserve-order="true" parallel="false">
8585
<classes>
8686
<class name="org.wso2.choreo.connect.tests.setup.standalone.CcWithJwtConfigAndTransformer"/>
87-
<class name="org.wso2.choreo.connect.tests.testcases.standalone.jwtGenerator.CustomJwtTransformerTestCase"/>
87+
<!-- Ignore the custom JWT transformer test due to the removal of the functionality -->
88+
<!-- <class name="org.wso2.choreo.connect.tests.testcases.standalone.jwtGenerator.CustomJwtTransformerTestCase"/>-->
8889
<class name="org.wso2.choreo.connect.tests.testcases.standalone.filter.CustomFilterTestCase"/>
8990
<class name="org.wso2.choreo.connect.tests.testcases.standalone.ratelimit.APILevelWithoutRateLimitTestCase"/>
9091
<class name="org.wso2.choreo.connect.tests.testcases.standalone.ratelimit.ApiLevelRatelimitTestCase"/>

resources/conf/log_config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ respDur = "%RESPONSE_DURATION%"
7474
apiUUID = "%DYNAMIC_METADATA(envoy.filters.http.ext_authz:apiUUID)%"
7575
extAuthDtls = "%DYNAMIC_METADATA(envoy.filters.http.ext_authz:extAuthDetails)%"
7676
resourcePath = "%DYNAMIC_METADATA(envoy.filters.http.ext_authz:resourcePath)%"
77+
choreoUpstreamHost = "%DYNAMIC_METADATA(envoy.lb:choreo-upstream-host)%"

0 commit comments

Comments
 (0)