You've already forked DataMate
@@ -13,34 +13,38 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>api-gateway</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>API Gateway</name>
|
||||
<description>API网关服务</description>
|
||||
|
||||
<properties>
|
||||
<spring-boot.version>3.5.6</spring-boot.version>
|
||||
<spring-cloud.version>2025.0.0</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
|
||||
<groupId>com.terrabase</groupId>
|
||||
<artifactId>enterprise-impl-commercial</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<groupId>org.springframework</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -49,6 +53,18 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<configuration>
|
||||
<finalName>gateway</finalName>
|
||||
<mainClass>com.datamate.gateway.ApiGatewayApplication</mainClass>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.gateway.route.RouteLocator;
|
||||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
* API Gateway & Auth Service Application
|
||||
@@ -13,10 +12,6 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
* 提供路由、鉴权、限流等功能
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {
|
||||
"com.datamate.gateway",
|
||||
"com.datamate.shared"
|
||||
})
|
||||
public class ApiGatewayApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -26,51 +21,21 @@ public class ApiGatewayApplication {
|
||||
@Bean
|
||||
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
|
||||
return builder.routes()
|
||||
// 数据归集服务路由
|
||||
.route("data-collection", r -> r.path("/api/data-collection/**")
|
||||
.uri("lb://data-collection-service"))
|
||||
|
||||
// 数据管理服务路由
|
||||
.route("data-management", r -> r.path("/api/data-management/**")
|
||||
.uri("lb://data-management-service"))
|
||||
|
||||
// 算子市场服务路由
|
||||
.route("operator-market", r -> r.path("/api/operators/**")
|
||||
.uri("lb://operator-market-service"))
|
||||
|
||||
// 数据清洗服务路由
|
||||
.route("data-cleaning", r -> r.path("/api/cleaning/**")
|
||||
.uri("lb://data-cleaning-service"))
|
||||
|
||||
// 数据合成服务路由
|
||||
.route("data-synthesis", r -> r.path("/api/synthesis/**")
|
||||
.uri("lb://data-synthesis-service"))
|
||||
.uri("http://datamate-backend-python:18000"))
|
||||
|
||||
// 数据标注服务路由
|
||||
.route("data-annotation", r -> r.path("/api/annotation/**")
|
||||
.uri("lb://data-annotation-service"))
|
||||
.uri("http://datamate-backend-python:18000"))
|
||||
|
||||
// 数据评估服务路由
|
||||
.route("data-evaluation", r -> r.path("/api/evaluation/**")
|
||||
.uri("lb://data-evaluation-service"))
|
||||
.uri("http://datamate-backend-python:18000"))
|
||||
|
||||
// 流程编排服务路由
|
||||
.route("pipeline-orchestration", r -> r.path("/api/pipelines/**")
|
||||
.uri("lb://pipeline-orchestration-service"))
|
||||
|
||||
// 执行引擎服务路由
|
||||
.route("execution-engine", r -> r.path("/api/execution/**")
|
||||
.uri("lb://execution-engine-service"))
|
||||
|
||||
// 认证服务路由
|
||||
.route("auth-service", r -> r.path("/api/auth/**")
|
||||
.uri("lb://auth-service"))
|
||||
|
||||
// RAG服务路由
|
||||
.route("rag-indexer", r -> r.path("/api/rag/indexer/**")
|
||||
.uri("lb://rag-indexer-service"))
|
||||
.route("rag-query", r -> r.path("/api/rag/query/**")
|
||||
.uri("lb://rag-query-service"))
|
||||
// 其他后端服务
|
||||
.route("default", r -> r.path("/api/**")
|
||||
.uri("http://datamate-backend:8080"))
|
||||
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.datamate.gateway.filter;
|
||||
|
||||
import com.terrabase.enterprise.api.dto.LoginUserDto;
|
||||
import com.terrabase.enterprise.api.sdk.TerrabaseSDK;
|
||||
import com.terrabase.enterprise.api.sdk.TerrabaseSDKConfig;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 用户信息过滤器
|
||||
*
|
||||
* @since 2025/12/22
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class UserContextFilter implements GlobalFilter {
|
||||
@Value("${terrabase.jar.path:/opt/terrabase}")
|
||||
private String jarPath;
|
||||
|
||||
@Value("${commercial.switch:false}")
|
||||
private boolean isCommercial;
|
||||
|
||||
private TerrabaseSDK terrabaseSDK;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
TerrabaseSDKConfig sdkConfig = TerrabaseSDKConfig.createDefault();
|
||||
sdkConfig.setJarPath(jarPath);
|
||||
terrabaseSDK = TerrabaseSDK.init(sdkConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
if (!isCommercial) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
try {
|
||||
LoginUserDto loginUserDto = terrabaseSDK.userManagement().getCurrentUserInfo().getData().getFirst();
|
||||
} catch (Exception e) {
|
||||
log.error("get current user info error", e);
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user