Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wso2/apk
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cd1e0189ff6e2870dc88fdcdc572b5e07112f39b
Choose a base ref
..
head repository: wso2/apk
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 98ca8f63dbfa5a28dba70ece7b41366aab9b2d6c
Choose a head ref
Showing with 6,711 additions and 1,564 deletions.
  1. +6 −2 adapter/api/proto/wso2/discovery/api/api.proto
  2. +0 −2 adapter/api/proto/wso2/discovery/config/enforcer/analytics_publisher.proto
  3. +0 −1 adapter/config/default_config.go
  4. +0 −1 adapter/config/types.go
  5. +38 −44 adapter/internal/discovery/xds/server.go
  6. +2 −0 adapter/internal/oasparser/config_generator.go
  7. +7 −1 adapter/internal/oasparser/constants/constants.go
  8. +25 −7 adapter/internal/oasparser/envoyconf/envoyconf_internal_test.go
  9. +1 −1 adapter/internal/oasparser/envoyconf/internal_dtos.go
  10. +11 −4 adapter/internal/oasparser/envoyconf/listener_test.go
  11. +4 −5 adapter/internal/oasparser/envoyconf/routes_configs.go
  12. +58 −25 adapter/internal/oasparser/envoyconf/routes_with_clusters.go
  13. +22 −9 adapter/internal/oasparser/envoyconf/routes_with_clusters_test.go
  14. +590 −94 adapter/internal/oasparser/model/adapter_internal_api.go
  15. +0 −108 adapter/internal/oasparser/model/graphql_api.go
  16. +1 −339 adapter/internal/oasparser/model/http_route.go
  17. +7 −7 adapter/internal/oasparser/model/resource.go
  18. +9 −4 adapter/internal/operator/PROJECT
  19. +3 −2 adapter/internal/operator/config/crd/bases/dp.wso2.com_apis.yaml
  20. +890 −0 adapter/internal/operator/config/crd/bases/dp.wso2.com_gqlroutes.yaml
  21. +3 −0 adapter/internal/operator/config/crd/kustomization.yaml
  22. +7 −0 adapter/internal/operator/config/crd/patches/cainjection_in_dp_gqlroutes.yaml
  23. +16 −0 adapter/internal/operator/config/crd/patches/webhook_in_dp_gqlroutes.yaml
  24. +31 −0 adapter/internal/operator/config/rbac/dp_gqlroute_editor_role.yaml
  25. +27 −0 adapter/internal/operator/config/rbac/dp_gqlroute_viewer_role.yaml
  26. +12 −0 adapter/internal/operator/config/samples/dp_v1alpha2_gqlroute.yaml
  27. +1 −1 adapter/internal/operator/constants/constants.go
  28. +280 −33 adapter/internal/operator/controllers/dp/api_controller.go
  29. +63 −0 adapter/internal/operator/controllers/dp/gqlroute_controller.go
  30. +4 −0 adapter/internal/operator/controllers/dp/suite_test.go
  31. +4 −4 adapter/internal/operator/controllers/dp/tokenissuer_controller.go
  32. +12 −0 adapter/internal/operator/synchronizer/api_state.go
  33. +105 −1 adapter/internal/operator/synchronizer/data_store.go
  34. +180 −0 adapter/internal/operator/synchronizer/gql_api.go
  35. +187 −0 adapter/internal/operator/synchronizer/rest_api.go
  36. +227 −224 adapter/internal/operator/synchronizer/synchronizer.go
  37. +67 −0 adapter/internal/operator/synchronizer/zz_generated.deepcopy.go
  38. +7 −6 adapter/internal/operator/utils/utils.go
  39. +125 −71 adapter/pkg/discovery/api/wso2/discovery/api/api.pb.go
  40. +28 −31 adapter/pkg/discovery/api/wso2/discovery/config/enforcer/analytics_publisher.pb.go
  41. +3 −0 adapter/pkg/logging/logging_constant.go
  42. +10 −0 adapter/pkg/utils/stringutils/string_utils.go
  43. +1 −0 common-controller/internal/operator/config/crd/bases/dp.wso2.com_apis.yaml
  44. +8 −7 common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go
  45. +1 −1 common-go-libs/apis/dp/v1alpha2/api_types.go
  46. +4 −0 common-go-libs/apis/dp/v1alpha2/api_webhook.go
  47. +138 −0 common-go-libs/apis/dp/v1alpha2/gqlroute_types.go
  48. +184 −0 common-go-libs/apis/dp/v1alpha2/zz_generated.deepcopy.go
  49. +1 −0 common-go-libs/config/crd/bases/dp.wso2.com_apis.yaml
  50. +889 −0 common-go-libs/config/crd/bases/dp.wso2.com_gqlroutes.yaml
  51. +2 −0 common-go-libs/go.mod
  52. +11 −0 ...er/org.wso2.apk.enforcer.commons/src/main/java/org/wso2/apk/enforcer/commons/model/APIConfig.java
  53. +14 −13 gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/api/APIFactory.java
  54. +248 −304 gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/api/GraphQLAPI.java
  55. +2 −33 gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/api/RestAPI.java
  56. +1 −1 ...ay/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/APIConstants.java
  57. +1,031 −75 gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/api/Api.java
  58. +79 −1 ...nforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/api/ApiOrBuilder.java
  59. +33 −20 ...ay/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/api/ApiProto.java
  60. +10 −13 ...forcer/src/main/java/org/wso2/apk/enforcer/discovery/config/enforcer/AnalyticsPublisherProto.java
  61. +0 −1 ...rcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/jwt/JWTAuthenticator.java
  62. +19 −0 .../org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/server/swagger/APIDefinitionUtils.java
  63. +1 −24 ...rg.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/server/swagger/SwaggerServerHandler.java
  64. +1 −2 gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/util/EndpointUtils.java
  65. +0 −1 gateway/enforcer/org.wso2.apk.enforcer/src/test/java/org/wso2/apk/enforcer/jwt/JWTValidatorTest.java
  66. +3 −2 helm-charts/crds/dp.wso2.com_apis.yaml
  67. +890 −0 helm-charts/crds/dp.wso2.com_gqlroutes.yaml
  68. +9 −0 helm-charts/templates/serviceAccount/apk-cluster-role.yaml
  69. +21 −15 runtime/config-deployer-service/ballerina/APIClient.bal
  70. +2 −2 runtime/config-deployer-service/ballerina/Dependencies.toml.template
  71. +1 −1 runtime/config-deployer-service/ballerina/tests/APIClientTest.bal
  72. +0 −21 test/cucumber-tests/src/test/resources/tests/api/Interceptor.feature
  73. +34 −0 test/cucumber-tests/src/test/resources/tests/api/resourceInterceptor.feature
8 changes: 6 additions & 2 deletions adapter/api/proto/wso2/discovery/api/api.proto
Original file line number Diff line number Diff line change
@@ -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";
@@ -51,10 +53,12 @@ message Api {
bool applicationSecurity = 16;
bool transportSecurity = 17;
/// 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
@@ -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";
1 change: 0 additions & 1 deletion adapter/config/default_config.go
Original file line number Diff line number Diff line change
@@ -95,7 +95,6 @@ var defaultConfig = &Config{
},
},
PayloadPassingToEnforcer: payloadPassingToEnforcer{
PassRequestPayload: false,
MaxRequestBytes: 102400,
AllowPartialMessage: false,
PackAsBytes: false,
1 change: 0 additions & 1 deletion adapter/config/types.go
Original file line number Diff line number Diff line change
@@ -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
82 changes: 38 additions & 44 deletions adapter/internal/discovery/xds/server.go
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@ var (
listenerToRouteArrayMap map[string][]*routev3.Route // Listener -> Routes map

// Common Enforcer Label as map key
// TODO(amali) This doesn't have a usage yet. It will be used to handle multiple enforcer labels in future.
// This doesn't have a usage yet. It will be used to handle multiple enforcer labels in future.
enforcerLabelMap map[string]*EnforcerInternalAPI // Enforcer Label -> EnforcerInternalAPI struct map

// KeyManagerList to store data
@@ -165,7 +165,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())
@@ -260,26 +260,28 @@ func deleteAPI(apiIdentifier string, environments []string, organizationID strin
existingLabels := orgAPIMap[organizationID][apiIdentifier].envoyLabels
toBeDelEnvs, toBeKeptEnvs := getEnvironmentsToBeDeleted(existingLabels, environments)

var isAllowedToDelete bool
updatedLabelsMap := make(map[string]struct{})
for _, val := range toBeDelEnvs {
isAllowedToDelete := stringutils.StringInSlice(val, existingLabels)
if isAllowedToDelete {
// do not delete from all environments, hence do not clear routes, clusters, endpoints, enforcerAPIs
orgAPIMap[organizationID][apiIdentifier].envoyLabels = toBeKeptEnvs
updateXdsCacheOnAPIChange(toBeDelEnvs, []string{})
if len(toBeKeptEnvs) != 0 {
return nil
}
logger.LoggerXds.Infof("API identifier: %v does not have any gateways. Hence deleting the API from label : %s. API_UUID: %v",
apiIdentifier, val, apiUUID)
cleanMapResources(apiIdentifier, organizationID, toBeDelEnvs)
updatedLabelsMap[val] = struct{}{}
if stringutils.StringInSlice(val, existingLabels) {
isAllowedToDelete = true
}
}
if isAllowedToDelete {
// do not delete from all environments, hence do not clear routes, clusters, endpoints, enforcerAPIs
orgAPIMap[organizationID][apiIdentifier].envoyLabels = toBeKeptEnvs
if len(toBeKeptEnvs) != 0 {
UpdateXdsCacheOnAPIChange(updatedLabelsMap)
return nil
}
}

//clean maps of routes, clusters, endpoints, enforcerAPIs
if len(environments) == 0 {
if len(environments) == 0 || isAllowedToDelete {
cleanMapResources(apiIdentifier, organizationID, toBeDelEnvs)
}
UpdateXdsCacheOnAPIChange(updatedLabelsMap)
return nil
}

@@ -288,11 +290,6 @@ func cleanMapResources(apiIdentifier string, organizationID string, toBeDelEnvs
delete(orgAPIMap[organizationID], apiIdentifier)
}

//updateXdsCacheOnAPIAdd is called after cleaning maps of routes, clusters, endpoints, enforcerAPIs.
//Therefore resources that belongs to the deleting API do not exist. Caches updated only with
//resources that belongs to the remaining APIs
updateXdsCacheOnAPIChange(toBeDelEnvs, []string{})

deleteBasepathForVHost(organizationID, apiIdentifier)
//TODO: (SuKSW) clean any remaining in label wise maps, if this is the last API of that label
logger.LoggerXds.Infof("Deleted API %v of organization %v", apiIdentifier, organizationID)
@@ -310,33 +307,24 @@ func deleteBasepathForVHost(organizationID, apiIdentifier string) {
}
}

// when this method is called, openAPIEnvoy map is updated.
// UpdateXdsCacheOnAPIChange when this method is called, openAPIEnvoy map is updated.
// Old labels refers to the previously assigned labels
// New labels refers to the the updated labels
func updateXdsCacheOnAPIChange(oldLabels []string, newLabels []string) bool {
func UpdateXdsCacheOnAPIChange(labels map[string]struct{}) bool {
revisionStatus := false
// TODO: (VirajSalaka) check possible optimizations, Since the number of labels are low by design it should not be an issue
for _, newLabel := range newLabels {
for newLabel := range labels {
listeners, clusters, routes, endpoints, apis := GenerateEnvoyResoucesForGateway(newLabel)
UpdateEnforcerApis(newLabel, apis, "")
success := UpdateXdsCacheWithLock(newLabel, endpoints, clusters, routes, listeners)
logger.LoggerXds.Debugf("Xds Cache is updated for the newly added label : %v", newLabel)
logger.LoggerXds.Debugf("Xds Cache is updated for the label : %v", newLabel)
if success {
// if even one label was updated with latest revision, we take the revision as deployed.
// (other labels also will get updated successfully)
revisionStatus = success
continue
}
}
for _, oldLabel := range oldLabels {
if !stringutils.StringInSlice(oldLabel, newLabels) {
listeners, clusters, routes, endpoints, apis := GenerateEnvoyResoucesForGateway(oldLabel)
GenerateEnvoyResoucesForGateway(oldLabel)
UpdateEnforcerApis(oldLabel, apis, "")
UpdateXdsCacheWithLock(oldLabel, endpoints, clusters, routes, listeners)
logger.LoggerXds.Debugf("Xds Cache is updated for the already existing label : %v", oldLabel)
}
}
return revisionStatus
}

@@ -684,7 +672,8 @@ func RemoveAPIFromOrgAPIMap(uuid string, orgID string) {
}

// UpdateAPICache updates the xDS cache related to the API Lifecycle event.
func UpdateAPICache(vHosts []string, newLabels []string, listener string, sectionName string, adapterInternalAPI model.AdapterInternalAPI) error {
func UpdateAPICache(vHosts []string, newLabels []string, listener string, sectionName string,
adapterInternalAPI model.AdapterInternalAPI) (map[string]struct{}, error) {
mutexForInternalMapUpdate.Lock()
defer mutexForInternalMapUpdate.Unlock()

@@ -699,37 +688,45 @@ func UpdateAPICache(vHosts []string, newLabels []string, listener string, sectio
orgIDAPIvHostsMap[adapterInternalAPI.GetOrganizationID()] = vHostsMap
}

updatedLabelsMap := make(map[string]struct{}, 0)

// Remove internal mappigs for old vHosts
for _, oldvhost := range oldvHosts {
apiIdentifier := GenerateIdentifierForAPIWithUUID(oldvhost, adapterInternalAPI.UUID)
var oldLabels []string
if orgMap, orgExists := orgAPIMap[adapterInternalAPI.GetOrganizationID()]; orgExists {
if _, apiExists := orgMap[apiIdentifier]; apiExists {
oldLabels = orgMap[apiIdentifier].envoyLabels
for _, oldLabel := range orgMap[apiIdentifier].envoyLabels {
updatedLabelsMap[oldLabel] = struct{}{}
}
delete(orgAPIMap[adapterInternalAPI.GetOrganizationID()], apiIdentifier)
}
}
updateXdsCacheOnAPIChange(oldLabels, newLabels)
}

// Create internal mappigs for new vHosts
// Create internal mappings for new vHosts
for _, vHost := range vHosts {
logger.LoggerAPKOperator.Debugf("Creating internal mapping for vhost: %s", vHost)
apiUUID := adapterInternalAPI.UUID
apiIdentifier := GenerateIdentifierForAPIWithUUID(vHost, apiUUID)
var oldLabels []string
var orgExists bool

// get changing label set
if _, orgExists = orgAPIMap[adapterInternalAPI.GetOrganizationID()]; orgExists {
if _, apiExists := orgAPIMap[adapterInternalAPI.GetOrganizationID()][apiIdentifier]; apiExists {
oldLabels = orgAPIMap[adapterInternalAPI.GetOrganizationID()][apiIdentifier].envoyLabels
for _, oldLabel := range orgAPIMap[adapterInternalAPI.GetOrganizationID()][apiIdentifier].envoyLabels {
updatedLabelsMap[oldLabel] = struct{}{}
}
}
}
for _, newLabel := range newLabels {
updatedLabelsMap[newLabel] = struct{}{}
}

routes, clusters, endpoints, err := oasParser.GetRoutesClustersEndpoints(adapterInternalAPI, nil,
vHost, adapterInternalAPI.GetOrganizationID())

if err != nil {
return fmt.Errorf("error while deploying API. Name: %s Version: %s, OrgID: %s, API_UUID: %v, Error: %s",
return nil, fmt.Errorf("error while deploying API. Name: %s Version: %s, OrgID: %s, API_UUID: %v, Error: %s",
adapterInternalAPI.GetTitle(), adapterInternalAPI.GetVersion(), adapterInternalAPI.GetOrganizationID(),
apiUUID, err.Error())
}
@@ -754,11 +751,8 @@ func UpdateAPICache(vHosts []string, newLabels []string, listener string, sectio
} else {
listenerToRouteArrayMap[listener] = routes
}

revisionStatus := updateXdsCacheOnAPIChange(oldLabels, newLabels)
logger.LoggerXds.Infof("Deployed Revision: %v:%v, API_UUID: %v", apiIdentifier, revisionStatus, apiUUID)
}
return nil
return updatedLabelsMap, nil
}

// UpdateGatewayCache updates the xDS cache related to the Gateway Lifecycle event.
2 changes: 2 additions & 0 deletions adapter/internal/oasparser/config_generator.go
Original file line number Diff line number Diff line change
@@ -210,6 +210,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.GetMutualSSL(),
8 changes: 7 additions & 1 deletion adapter/internal/oasparser/constants/constants.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -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
@@ -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{
@@ -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")
@@ -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))
@@ -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))
@@ -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)
@@ -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",
2 changes: 1 addition & 1 deletion adapter/internal/oasparser/envoyconf/internal_dtos.go
Original file line number Diff line number Diff line change
@@ -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
15 changes: 11 additions & 4 deletions adapter/internal/oasparser/envoyconf/listener_test.go
Original file line number Diff line number Diff line change
@@ -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))
Loading