Skip to content

Commit

Permalink
[Feature][Admin]Add global token (DataLinkDC#3832)
Browse files Browse the repository at this point in the history
Co-authored-by: zackyoungh <[email protected]>
  • Loading branch information
zackyoungh and zackyoungh authored Sep 24, 2024
1 parent 1f23c38 commit d9366a9
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -66,7 +67,6 @@
@Api(tags = "UDF & App Jar Controller")
@RequestMapping("/download")
public class DownloadController {
// todo: Controller has injection risk
@GetMapping("downloadDepJar/{taskId}")
@ApiOperation("Download UDF Jar")
public void downloadJavaUDF(@PathVariable Integer taskId, HttpServletResponse resp) {
Expand Down Expand Up @@ -131,12 +131,15 @@ public void downloadFromRs(String path, HttpServletResponse resp) {
ServletUtil.write(resp, inputStream);
}

// todo: There is a risk of injection in this interface
@PostMapping("uploadFromRsByLocal")
@ApiOperation("Upload From Resource By Local")
@SaIgnore
public Result<Void> uploadFromRs(String path, @RequestParam("file") MultipartFile file) {
public Result<Void> uploadFromRs(
String path, @RequestParam("file") MultipartFile file, @RequestHeader("token") String token) {
SystemConfiguration systemConfiguration = SystemConfiguration.getInstances();
if (!systemConfiguration.getDinkyToken().getValue().equals(token)) {
return Result.failed("token is not correct");
}
if (!systemConfiguration.getResourcesEnable().getValue()
|| !systemConfiguration.getResourcesModel().getValue().equals(ResourcesModelEnum.LOCAL)) {
return Result.failed("resources model is not local or resources is not enable");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public void flush() throws IOException {
}

private void sendFile() {
SystemConfiguration systemConfiguration = SystemConfiguration.getInstances();
try (HttpResponse httpResponse = HttpUtil.createPost(
SystemConfiguration.getInstances().getDinkyAddr().getValue() + "/download/uploadFromRsByLocal")
systemConfiguration.getDinkyAddr().getValue() + "/download/uploadFromRsByLocal")
.header("token", systemConfiguration.getDinkyToken().getValue())
.form("file", file)
.form("path", path.toString())
.execute()) {
Expand Down
3 changes: 3 additions & 0 deletions dinky-common/src/main/java/org/dinky/data/enums/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ public enum Status {
SYS_ENV_SETTINGS_DINKYADDR(116, "sys.env.settings.dinkyAddr"),
SYS_ENV_SETTINGS_DINKYADDR_NOTE(117, "sys.env.settings.dinkyAddr.note"),

SYS_ENV_SETTINGS_DINKYTOKEN(116, "sys.env.settings.dinkyToken"),
SYS_ENV_SETTINGS_DINKYTOKEN_NOTE(117, "sys.env.settings.dinkyToken.note"),

SYS_ENV_SETTINGS_JOB_RESEND_DIFF_SECOND(118, "sys.env.settings.jobResendDiffSecond"),
SYS_ENV_SETTINGS_JOB_RESEND_DIFF_SECOND_NOTE(119, "sys.env.settings.jobResendDiffSecond.note"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,14 @@ public static Configuration.OptionBuilder key(Status status) {
.stringType()
.defaultValue("python3")
.note(Status.SYS_ENV_SETTINGS_PYTHONHOME_NOTE);

private final Configuration<String> dinkyAddr = key(Status.SYS_ENV_SETTINGS_DINKYADDR)
.stringType()
.defaultValue(System.getProperty("dinkyAddr"))
.note(Status.SYS_ENV_SETTINGS_DINKYADDR_NOTE);
private final Configuration<String> dinkyToken = key(Status.SYS_ENV_SETTINGS_DINKYTOKEN_NOTE)
.stringType()
.defaultValue("efda1551-7958-4e0f-80a8-dfd107df3e38")
.note(Status.SYS_ENV_SETTINGS_DINKYTOKEN);

private final Configuration<Integer> jobReSendDiffSecond = key(Status.SYS_ENV_SETTINGS_JOB_RESEND_DIFF_SECOND)
.intType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ sys.env.settings.pythonHome=Python Env variables
sys.env.settings.pythonHome.note=Python environment variables, used to submit Python tasks and build Python Udf
sys.env.settings.dinkyAddr=Dinky Address
sys.env.settings.dinkyAddr.note=This address is an accessible Dinky address, such as http://127.0.0.1:8888
sys.env.settings.dinkyToken=Dinky Token
sys.env.settings.dinkyToken.note=This token is used to access some interfaces within Dinky, such as uploading resources
sys.env.settings.jobResendDiffSecond=Alert anti-resend interval
sys.env.settings.jobResendDiffSecond.note=During this interval, when the Alert information sent reaches the configured value of [Maximum number of alarm resend prevention], after reaching the threshold, the Alert information will no longer be sent; unit: seconds
sys.env.settings.diffMinuteMaxSendCount=Maximum number of alarms to prevent resending
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ sys.env.settings.pythonHome=Python 环境变量
sys.env.settings.pythonHome.note=Python 环境变量,用于提交 Python 任务以及构建 Python Udf
sys.env.settings.dinkyAddr=Dinky 地址
sys.env.settings.dinkyAddr.note=该地址为可访问的 Dinky 地址,如 http://127.0.0.1:8888
sys.env.settings.dinkyToken=Dinky Token
sys.env.settings.dinkyToken.note = 此 token 用于访问 Dinky 内的一些接口,如上传资源等
sys.env.settings.jobResendDiffSecond=告警防重发间隔
sys.env.settings.jobResendDiffSecond.note=在此间隔内,发送告警信息达到 [告警防重发最大条数] 配置的值时,达到阈值后,不再发送告警信息; 单位:秒
sys.env.settings.diffMinuteMaxSendCount=告警防重发最大条数
Expand Down
10 changes: 5 additions & 5 deletions dinky-flink/dinky-flink-1.20/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
<artifactId>flink-connector-kafka</artifactId>
<version>3.2.0-1.19</version>
</dependency>
<dependency>
<groupId>org.apache.doris</groupId>
<artifactId>flink-doris-connector-1.20</artifactId>
<version>24.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-shaded-guava</artifactId>
Expand Down Expand Up @@ -138,11 +143,6 @@
<artifactId>commons-cli</artifactId>
<version>${commons.version}</version>
</dependency>
<dependency>
<groupId>org.apache.doris</groupId>
<artifactId>flink-doris-connector-1.19</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime-web</artifactId>
Expand Down

0 comments on commit d9366a9

Please sign in to comment.