Skip to content

Commit

Permalink
add gql routes support
Browse files Browse the repository at this point in the history
  • Loading branch information
AmaliMatharaarachchi committed Dec 6, 2023
1 parent d437e7a commit b9dac14
Show file tree
Hide file tree
Showing 65 changed files with 5,401 additions and 1,363 deletions.
8 changes: 6 additions & 2 deletions adapter/api/proto/wso2/discovery/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ package wso2.discovery.api;
import "wso2/discovery/api/Resource.proto";
import "wso2/discovery/api/Certificate.proto";
import "wso2/discovery/api/BackendJWTTokenInfo.proto";
// import "wso2/discovery/api/graphql.proto";
import "wso2/discovery/api/endpoint_cluster.proto";
import "wso2/discovery/api/security_info.proto";
import "wso2/discovery/api/graphql.proto";

option go_package = "github.com/envoyproxy/go-control-plane/wso2/discovery/api;api";
option java_package = "org.wso2.apk.enforcer.discovery.api";
Expand Down Expand Up @@ -50,10 +52,12 @@ message Api {
string mutualSSL = 15;
bool applicationSecurity = 16;
/// string graphQLSchema = 22;
// repeated GraphqlComplexity graphqlComplexityInfo = 23;
repeated GraphqlComplexity graphqlComplexityInfo = 23;
bool systemAPI = 24;
BackendJWTTokenInfo backendJWTTokenInfo = 25;
bytes apiDefinitionFile = 26;
string environment = 27;
bool subscriptionValidation = 28;
EndpointCluster endpoints = 29;
repeated SecurityInfo endpointSecurity = 30;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ syntax = "proto3";

package wso2.discovery.config.enforcer;

import "wso2/discovery/config/enforcer/service.proto";

option go_package = "github.com/envoyproxy/go-control-plane/wso2/discovery/config/enforcer;enforcer";
option java_package = "org.wso2.apk.enforcer.discovery.config.enforcer";
option java_outer_classname = "AnalyticsPublisherProto";
Expand Down
1 change: 0 additions & 1 deletion adapter/config/default_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ var defaultConfig = &Config{
},
},
PayloadPassingToEnforcer: payloadPassingToEnforcer{
PassRequestPayload: false,
MaxRequestBytes: 102400,
AllowPartialMessage: false,
PackAsBytes: false,
Expand Down
1 change: 0 additions & 1 deletion adapter/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ type consul struct {

// Router to enforcer request body passing configurations
type payloadPassingToEnforcer struct {
PassRequestPayload bool
MaxRequestBytes uint32
AllowPartialMessage bool
PackAsBytes bool
Expand Down
2 changes: 1 addition & 1 deletion adapter/internal/discovery/xds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func init() {
orgIDvHostBasepathMap = make(map[string]map[string]string)

enforcerLabelMap = make(map[string]*EnforcerInternalAPI)
//TODO(amali) currently subscriptions, configs, applications, applicationPolicies, subscriptionPolicies,
// currently subscriptions, configs, applications, applicationPolicies, subscriptionPolicies,
// applicationKeyMappings, keyManagerConfigList, revokedTokens are supported with the hard coded label for Enforcer
enforcerLabelMap[commonEnforcerLabel] = &EnforcerInternalAPI{}
rand.Seed(time.Now().UnixNano())
Expand Down
2 changes: 2 additions & 0 deletions adapter/internal/oasparser/config_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ func GetEnforcerAPI(adapterInternalAPI model.AdapterInternalAPI, vhost string) *
Vhost: vhost,
EnvType: adapterInternalAPI.EnvType,
BackendJWTTokenInfo: backendJWTTokenInfo,
Endpoints: generateRPCEndpointCluster(adapterInternalAPI.Endpoints),
EndpointSecurity: generateRPCEndpointSecurity(adapterInternalAPI.EndpointSecurity),
// IsMockedApi: isMockedAPI,
ClientCertificates: clientCertificates,
MutualSSL: adapterInternalAPI.GetXWSO2MutualSSL(),
Expand Down
8 changes: 7 additions & 1 deletion adapter/internal/oasparser/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const (
REST string = "REST"
SOAP string = "SOAP"
WS string = "WS"
GRAPHQL string = "GRAPHQL"
GRAPHQL string = "GraphQL"
WEBHOOK string = "WEBHOOK"
SSE string = "SSE"
Prototyped string = "prototyped"
Expand Down Expand Up @@ -131,3 +131,9 @@ const (
KindScope = "Scope"
KindRateLimitPolicy = "RateLimitPolicy"
)

// API environment types
const (
Production = "Production"
Sandbox = "Sandbox"
)
32 changes: 25 additions & 7 deletions adapter/internal/oasparser/envoyconf/envoyconf_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestCreateRoute(t *testing.T) {

resourceWithGet := model.CreateMinimalDummyResourceForTests("/xWso2BasePath/resourcePath",
[]*model.Operation{model.NewOperationWithPolicies("GET", policies)},
"resource_operation_id", []model.Endpoint{}, true)
"resource_operation_id", []model.Endpoint{endpoint}, true)
clusterName := "resource_operation_id"
hostRewriteSpecifier := &routev3.RouteAction_AutoHostRewrite{
AutoHostRewrite: &wrapperspb.BoolValue{
Expand Down Expand Up @@ -107,11 +107,11 @@ func TestCreateRoute(t *testing.T) {
},
}

routeParams := generateRouteCreateParamsForUnitTests(title, apiType, vHost, xWso2BasePath, version,
endpoint.Basepath, &resourceWithGet, clusterName, nil, false)
routeParams.routeConfig = &model.EndpointConfig{
resourceWithGet.GetEndpoints().Config = &model.EndpointConfig{
IdleTimeoutInSeconds: 300,
}
routeParams := generateRouteCreateParamsForUnitTests(title, apiType, vHost, xWso2BasePath, version,
endpoint.Basepath, &resourceWithGet, clusterName, nil, false)

generatedRouteArrayWithXWso2BasePath, err := createRoutes(routeParams)
assert.Nil(t, err, "Error while creating routes WithXWso2BasePath")
Expand All @@ -136,8 +136,14 @@ func TestCreateRouteClusterSpecifier(t *testing.T) {
version := "1.0.0"
apiType := "HTTP"

endpoint := model.Endpoint{
Host: "abc.com",
URLType: "http",
Port: 80,
RawURL: "http://abc.com",
}
resourceWithGet := model.CreateMinimalDummyResourceForTests("/resourcePath", []*model.Operation{model.NewOperation("GET", nil, nil)},
"resource_operation_id", []model.Endpoint{}, false)
"resource_operation_id", []model.Endpoint{endpoint}, false)

route, err := createRoutes(generateRouteCreateParamsForUnitTests(title, apiType, vHost, xWso2BasePath, version, endpointBasePath,
&resourceWithGet, clusterName, nil, false))
Expand All @@ -161,8 +167,14 @@ func TestCreateRouteExtAuthzContext(t *testing.T) {
version := "1.0.0"
apiType := "HTTP"

endpoint := model.Endpoint{
Host: "abc.com",
URLType: "http",
Port: 80,
RawURL: "http://abc.com",
}
resourceWithGet := model.CreateMinimalDummyResourceForTests("/resourcePath", []*model.Operation{model.NewOperation("GET", nil, nil)},
"resource_operation_id", []model.Endpoint{}, false)
"resource_operation_id", []model.Endpoint{endpoint}, false)

route, err := createRoutes(generateRouteCreateParamsForUnitTests(title, apiType, vHost, xWso2BasePath, version,
endpointBasePath, &resourceWithGet, clusterName, nil, false))
Expand Down Expand Up @@ -518,6 +530,12 @@ func TestGetCorsPolicy(t *testing.T) {
AccessControlAllowMethods: []string{"GET"},
AccessControlAllowOrigins: []string{"http://test1.com", "http://test2.com"},
}
endpoint := model.Endpoint{
Host: "abc.com",
URLType: "http",
Port: 80,
RawURL: "http://abc.com",
}

// Test the configuration when cors is disabled.
corsPolicy1 := getCorsPolicy(corsConfigModel1)
Expand Down Expand Up @@ -553,7 +571,7 @@ func TestGetCorsPolicy(t *testing.T) {
assert.Empty(t, corsPolicy3.GetAllowCredentials(), "Allow Credential property should not be assigned.")

resourceWithGet := model.CreateMinimalDummyResourceForTests("/resourcePath", []*model.Operation{model.NewOperation("GET", nil, nil)},
"resource_operation_id", []model.Endpoint{}, false)
"resource_operation_id", []model.Endpoint{endpoint}, false)

// Route without CORS configuration
routeWithoutCors, err := createRoutes(generateRouteCreateParamsForUnitTests("test", "HTTP", "localhost", "/test", "1.0.0", "/test",
Expand Down
2 changes: 1 addition & 1 deletion adapter/internal/oasparser/envoyconf/internal_dtos.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type routeCreateParams struct {
endpointBasePath string
resource *model.Resource
clusterName string
routeConfig *model.EndpointConfig
endpoints *model.EndpointCluster
authHeader string
requestInterceptor map[string]model.InterceptEndpoint
responseInterceptor map[string]model.InterceptEndpoint
Expand Down
15 changes: 11 additions & 4 deletions adapter/internal/oasparser/envoyconf/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,24 @@ func testCreateRoutesForUnitTests(t *testing.T) []*routev3.Route {
AccessControlAllowOrigins: []string{"http://test1.com", "http://test2.com"},
}

endpoint := model.Endpoint{
Host: "abc.com",
URLType: "http",
Port: 80,
RawURL: "http://abc.com",
}

operationGet := model.NewOperation("GET", nil, nil)
operationPost := model.NewOperation("POST", nil, nil)
operationPut := model.NewOperation("PUT", nil, nil)
resourceWithGet := model.CreateMinimalDummyResourceForTests("/resourcePath", []*model.Operation{operationGet},
"resource_operation_id", []model.Endpoint{}, false)
"resource_operation_id", []model.Endpoint{endpoint}, false)
resourceWithPost := model.CreateMinimalDummyResourceForTests("/resourcePath", []*model.Operation{operationPost},
"resource_operation_id", []model.Endpoint{}, false)
"resource_operation_id", []model.Endpoint{endpoint}, false)
resourceWithPut := model.CreateMinimalDummyResourceForTests("/resourcePath", []*model.Operation{operationPut},
"resource_operation_id", []model.Endpoint{}, false)
"resource_operation_id", []model.Endpoint{endpoint}, false)
resourceWithMultipleOperations := model.CreateMinimalDummyResourceForTests("/resourcePath", []*model.Operation{operationGet, operationPut},
"resource_operation_id", []model.Endpoint{}, false)
"resource_operation_id", []model.Endpoint{endpoint}, false)

route1, err := createRoutes(generateRouteCreateParamsForUnitTests("test", "HTTP", "localhost", "/test", "1.0.0", "/test",
&resourceWithGet, "test-cluster", corsConfigModel3, false))
Expand Down
9 changes: 4 additions & 5 deletions adapter/internal/oasparser/envoyconf/routes_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,8 @@ func generateHeaderMatcher(headerName, valueRegex string) *routev3.HeaderMatcher
return headerMatcherArray
}

func generateRegexMatchAndSubstitute(routePath, endpointBasePath,
endpointResourcePath string, pathMatchType gwapiv1b1.PathMatchType) *envoy_type_matcherv3.RegexMatchAndSubstitute {

func generateRegexMatchAndSubstitute(routePath, endpointResourcePath string,
pathMatchType gwapiv1b1.PathMatchType) *envoy_type_matcherv3.RegexMatchAndSubstitute {
substitutionString := generateSubstitutionString(endpointResourcePath, pathMatchType)
return &envoy_type_matcherv3.RegexMatchAndSubstitute{
Pattern: &envoy_type_matcherv3.RegexMatcher{
Expand Down Expand Up @@ -259,8 +258,8 @@ func generateHeaderToRemoveString(policyParams interface{}) (string, error) {
return requestHeaderToRemove, nil
}

func generateRewritePathRouteConfig(routePath, endpointBasepath string,
policyParams interface{}, pathMatchType gwapiv1b1.PathMatchType, isDefaultVersion bool) (*envoy_type_matcherv3.RegexMatchAndSubstitute, error) {
func generateRewritePathRouteConfig(routePath string, policyParams interface{}, pathMatchType gwapiv1b1.PathMatchType,
isDefaultVersion bool) (*envoy_type_matcherv3.RegexMatchAndSubstitute, error) {

var paramsToSetHeader map[string]interface{}
var ok bool
Expand Down
Loading

0 comments on commit b9dac14

Please sign in to comment.