diff --git a/adapter/internal/discovery/xds/server.go b/adapter/internal/discovery/xds/server.go index 79988d841c..9b80cb10bc 100644 --- a/adapter/internal/discovery/xds/server.go +++ b/adapter/internal/discovery/xds/server.go @@ -839,6 +839,17 @@ func GenerateEnvoyResoucesForLabel(label string) ([]types.Resource, []types.Reso vhostToRouteArrayMap[fmt.Sprintf("%s-%s", organizationID, vhost)] = append(vhostToRouteArrayMap[fmt.Sprintf("%s-%s", organizationID, vhost)], orgIDOpenAPIRoutesMap[organizationID][apiKey]...) + if strings.HasPrefix(vhost, "sandbox.") { + duplicatedVhostProd := strings.Replace(vhost, strings.Split(vhost, ".")[0], "prod-sandbox", 1) + vhostToRouteArrayMap[fmt.Sprintf("%s-%s", organizationID, duplicatedVhostProd)] = + append(vhostToRouteArrayMap[fmt.Sprintf("%s-%s", organizationID, duplicatedVhostProd)], + orgIDOpenAPIRoutesMap[organizationID][apiKey]...) + } else if strings.HasPrefix(vhost, "sandbox_dev.") { + duplicatedVhostDev := strings.Replace(vhost, strings.Split(vhost, ".")[0], "dev-sandbox", 1) + vhostToRouteArrayMap[fmt.Sprintf("%s-%s", organizationID, duplicatedVhostDev)] = + append(vhostToRouteArrayMap[fmt.Sprintf("%s-%s", organizationID, duplicatedVhostDev)], + orgIDOpenAPIRoutesMap[organizationID][apiKey]...) + } } endpointArray = append(endpointArray, orgIDOpenAPIEndpointsMap[organizationID][apiKey]...) enfocerAPI, ok := orgIDOpenAPIEnforcerApisMap[organizationID][apiKey] diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/api/APIFactory.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/api/APIFactory.java index ccc307629b..6057d916bc 100644 --- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/api/APIFactory.java +++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/api/APIFactory.java @@ -84,6 +84,15 @@ public void addApis(List apis) { KNOWN_VHOST_PREFIXES.contains(api.getVhost().split("\\.")[0])) || (EnvVarConfig.getInstance().isDuplicateVhostEnabledPdp())) { newApis.put(getApiKeyWithOrgId(enforcerApi), enforcerApi); + if (api.getVhost().startsWith("sandbox.")) { + String duplicatedVhostProd = + api.getVhost().replaceFirst("sandbox\\.", "prod-sandbox."); + newApis.put(getApiKeyWithOrgId(enforcerApi, duplicatedVhostProd), enforcerApi); + } else if (api.getVhost().startsWith("sandbox_dev.")) { + String duplicatedVhostDev = + api.getVhost().replaceFirst("sandbox_dev\\.", "dev-sandbox."); + newApis.put(getApiKeyWithOrgId(enforcerApi, duplicatedVhostDev), enforcerApi); + } } } @@ -155,6 +164,12 @@ private String getApiKeyWithOrgId(API api) { apiConfig.getVhost(), apiConfig.getBasePath(), apiConfig.getVersion()); } + private String getApiKeyWithOrgId(API api, String vhost) { + APIConfig apiConfig = api.getAPIConfig(); + return String.format("%s-%s:%s:%s", apiConfig.getOrganizationId(), + vhost, apiConfig.getBasePath(), apiConfig.getVersion()); + } + private String getApiKey(String vhost, String basePath, String version) { return String.format("%s:%s:%s", vhost, basePath, version); }