Skip to content

Commit

Permalink
feat: Spring cloud gateway routing (#3031)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Jareš <pavel.jares@broadcom.com>
Signed-off-by: Elena Kubantseva <elena.kubantseva@broadcom.com>
Co-authored-by: Elena Kubantseva <elena.kubantseva@broadcom.com>
  • Loading branch information
pj892031 and arxioly authored Aug 22, 2023
1 parent ce2f280 commit a1dd492
Show file tree
Hide file tree
Showing 38 changed files with 1,282 additions and 318 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ jobs:
image: ghcr.io/balhar-jakub/gateway-service:${{ github.run_id }}-${{ github.run_number }}
cloud-gateway-service:
image: ghcr.io/balhar-jakub/cloud-gateway-service:${{ github.run_id }}-${{ github.run_number }}
env:
APIML_SERVICE_GATEWAY_PROXY_ENABLED: false
discoverable-client:
image: ghcr.io/balhar-jakub/discoverable-client:${{ github.run_id }}-${{ github.run_number }}
mock-services:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@
package org.zowe.apiml.cloudgatewayservice.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
import org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties;
import org.springframework.cloud.gateway.filter.FilterDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.zowe.apiml.cloudgatewayservice.service.ProxyRouteLocator;
import org.zowe.apiml.cloudgatewayservice.service.RouteLocator;
import org.zowe.apiml.util.CorsUtils;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -33,20 +26,6 @@ public class RoutingConfig {
@Value("${apiml.service.ignoredHeadersWhenCorsEnabled:-}")
private String ignoredHeadersWhenCorsEnabled;

@Bean
@ConditionalOnProperty(name = "apiml.service.gateway.proxy.enabled", havingValue = "false")
public RouteLocator apimlDiscoveryRouteDefLocator(
ReactiveDiscoveryClient discoveryClient, DiscoveryLocatorProperties properties, List<FilterDefinition> filters, ApplicationContext context, CorsUtils corsUtils) {
return new RouteLocator(discoveryClient, properties, filters, context, corsUtils);
}

@Bean
@ConditionalOnProperty(name = "apiml.service.gateway.proxy.enabled", havingValue = "true")
public RouteLocator proxyRouteDefLocator(
ReactiveDiscoveryClient discoveryClient, DiscoveryLocatorProperties properties, List<FilterDefinition> filters, ApplicationContext context, CorsUtils corsUtils) {
return new ProxyRouteLocator(discoveryClient, properties, filters, context, corsUtils);
}

@Bean
public List<FilterDefinition> filters() {
FilterDefinition circuitBreakerFilter = new FilterDefinition();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.cloudgatewayservice.filters;

import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Service;

/**
* This filter is responsible to update request header during the routing. The header contain a locator to which server
* route. It could contain also multiple steps separated by /.
*
* In the case header contain multiple steps the filter remove just the first part, otherwise it remove header at all.
*
* Examples:
* "step1/step2/step3" > "step2/step3"
* "node" > null (removed)
*/
@Service
public class HeaderRouteStepFilterFactory extends AbstractGatewayFilterFactory<HeaderRouteStepFilterFactory.Config> {

public HeaderRouteStepFilterFactory() {
super(Config.class);
}

@Override
public GatewayFilter apply(Config config) {
String header = config.getHeader();
return (exchange, chain) -> {
if (exchange.getRequest().getHeaders().containsKey(header)) {
exchange.mutate().request(request -> exchange.getRequest().mutate().headers(headers -> {
String headerValue = headers.getFirst(header);
int index = headerValue.indexOf("/");
if ((index >= 0) && (index + 1 < headerValue.length())) {
headers.set(header, headerValue.substring(index + 1));
} else {
headers.remove(header);
}
}));
}

return chain.filter(exchange);
};
}

@Data
public static class Config {

private String header;

}

}

This file was deleted.

Loading

0 comments on commit a1dd492

Please sign in to comment.