Skip to content

Commit

Permalink
feat: add support for disabling specific file transfer methods
Browse files Browse the repository at this point in the history
  • Loading branch information
D-D-H committed Jan 31, 2024
1 parent 0c02db7 commit 67cda3a
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ cloud/
bin

.test-temp

.java-version
23 changes: 16 additions & 7 deletions frontend/src/components/forms/FileTransferForm.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2023 Contributors to the Eclipse Foundation
Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation

See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.
Expand Down Expand Up @@ -261,6 +261,15 @@ function close(done: any) {
}
done();
}

function isEnabled(method: string) {
for (let m of env.disabledFileTransferMethods) {
if (m === method) {
return false
}
}
return true
}
</script>
<template>
<el-dialog
Expand All @@ -282,39 +291,39 @@ function close(done: any) {
>
<el-form-item :label="_t('transferMethod')" prop="method">
<el-radio-group v-model="params.method">
<el-radio-button label="UPLOAD">
<el-radio-button label="UPLOAD" v-if="isEnabled('UPLOAD')">
<div class="ej-file-transfer-method-button">
<el-icon style="margin-right: 8px" size="14">
<Upload />
</el-icon>
{{ _t('upload') }}
</div>
</el-radio-button>
<el-radio-button label="OSS">
<el-radio-button label="OSS" v-if="isEnabled('OSS')">
<div class="ej-file-transfer-method-button">
<el-icon style="margin-right: 8px" size="14">
<UploadFilled />
</el-icon>
OSS
</div>
</el-radio-button>
<el-radio-button label="S3">
<el-radio-button label="S3" v-if="isEnabled('S3')">
<div class="ej-file-transfer-method-button">
<el-icon style="margin-right: 8px" size="14">
<UploadFilled />
</el-icon>
S3
</div>
</el-radio-button>
<el-radio-button label="SCP">
<el-radio-button label="SCP" v-if="isEnabled('SCP')">
<div class="ej-file-transfer-method-button">
<el-icon style="margin-right: 8px" size="14">
<Connection />
</el-icon>
SCP
</div>
</el-radio-button>
<el-radio-button label="URL">
<el-radio-button label="URL" v-if="isEnabled('URL')">
<div class="ej-file-transfer-method-button">
<el-icon style="margin-right: 8px" size="14">
<Link />
Expand All @@ -323,7 +332,7 @@ function close(done: any) {
</div>
</el-radio-button>

<el-radio-button label="TEXT" :disabled="(params.type as String) === 'HEAP_DUMP'">
<el-radio-button label="TEXT" :disabled="(params.type as String) === 'HEAP_DUMP'" v-if="isEnabled('TEXT')">
<div class="ej-file-transfer-method-button">
<el-icon style="margin-right: 8px" size="14">
<Document />
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/i18n/zh.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -99,7 +99,7 @@ export default {
filename: '文件名',
text: '文本',

dragOrClickToUpload: '将文件拖拽到此处 或 点击进行文件选择',
dragOrClickToUpload: '拖拽文件至此处或点击进行上传',

host: '主机',
user: '用户',
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/stores/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -34,6 +34,7 @@ export interface HandshakeResponse {
publicKey: PublicKey;
oauth2LoginLinks: object;
user?: User;
disabledFileTransferMethods: [],
}

const tokenKey = 'jifa-token';
Expand All @@ -57,7 +58,9 @@ export const useEnv = defineStore('env', {

user: null as User | null,
publicKey: null as PublicKey | null,
uploadHeader: {} // used by upload
uploadHeader: {}, // used by upload

disabledFileTransferMethods: []
}),

getters: {
Expand Down Expand Up @@ -88,6 +91,8 @@ export const useEnv = defineStore('env', {
} else if (!this.allowAnonymousAccess) {
this.loginFormVisible = true;
}

this.disabledFileTransferMethods = data.disabledFileTransferMethods
},

logout() {
Expand Down
11 changes: 10 additions & 1 deletion server/src/main/java/org/eclipse/jifa/server/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -20,13 +20,16 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jifa.common.util.Validate;
import org.eclipse.jifa.server.enums.FileTransferMethod;
import org.eclipse.jifa.server.enums.Role;
import org.eclipse.jifa.server.enums.SchedulingStrategy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Set;

import static org.eclipse.jifa.server.Constant.DEFAULT_PORT;

Expand Down Expand Up @@ -147,6 +150,12 @@ public class Configuration {
*/
private boolean openBrowserWhenReady;


/**
* The disabled file transfer methods.
*/
private Set<FileTransferMethod> disabledFileTransferMethods = Collections.emptySet();

@PostConstruct
private void init() {
if (role == Role.MASTER) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -65,6 +65,7 @@ public HandshakeResponse handshake() {
config.isAllowRegistration(),
cipherService.getPublicKeyString(),
oauth2LoginLinks,
config.getDisabledFileTransferMethods(),
user);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -169,6 +169,11 @@ public boolean isValid(FileTransferRequest request, ConstraintValidatorContext c
return false;
}

if (request.method == FileTransferMethod.UPLOAD) {
context.disableDefaultConstraintViolation();
return false;
}

switch (request.method) {
case OSS -> {
valid &= checkNotBlank(request.ossEndpoint, "ossEndpoint", context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -12,14 +12,17 @@
********************************************************************************/
package org.eclipse.jifa.server.domain.dto;

import org.eclipse.jifa.server.enums.FileTransferMethod;
import org.eclipse.jifa.server.enums.Role;

import java.util.Map;
import java.util.Set;

public record HandshakeResponse(Role serverRole,
boolean allowAnonymousAccess,
boolean allowRegistration,
PublicKey publicKey,
Map<String, String> oauth2LoginLinks,
Set<FileTransferMethod> disabledFileTransferMethods,
User user) {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -16,5 +16,5 @@
* File Transfer Method
*/
public enum FileTransferMethod {
OSS, S3, SCP, URL, TEXT
OSS, S3, SCP, URL, TEXT, UPLOAD
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -26,8 +26,8 @@ public enum ServerErrorCode implements ErrorCode {
UNSUPPORTED_API("Unsupported API"),
FILE_TRANSFER_INCOMPLETE("File transfer incomplete"),
FILE_TYPE_MISMATCH("File type mismatch"),
FILE_TRANSFER_METHOD_DISABLED("File transfer method disabled"),
STATIC_WORKER_UNAVAILABLE("Static worker Unavailable"),

ELASTIC_WORKER_NOT_READY("Elastic worker not ready"),
ELASTIC_WORKER_STARTUP_FAILURE("Elastic worker startup failure");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -31,6 +31,7 @@
import org.eclipse.jifa.server.domain.entity.shared.user.UserEntity;
import org.eclipse.jifa.server.domain.entity.static_cluster.FileStaticWorkerBind;
import org.eclipse.jifa.server.domain.entity.static_cluster.StaticWorkerEntity;
import org.eclipse.jifa.server.enums.FileTransferMethod;
import org.eclipse.jifa.server.enums.FileTransferState;
import org.eclipse.jifa.server.enums.FileType;
import org.eclipse.jifa.server.enums.SchedulingStrategy;
Expand Down Expand Up @@ -72,6 +73,7 @@
import static org.eclipse.jifa.server.enums.Role.STANDALONE_WORKER;
import static org.eclipse.jifa.server.enums.ServerErrorCode.ACCESS_DENIED;
import static org.eclipse.jifa.server.enums.ServerErrorCode.FILE_NOT_FOUND;
import static org.eclipse.jifa.server.enums.ServerErrorCode.FILE_TRANSFER_METHOD_DISABLED;
import static org.eclipse.jifa.server.enums.ServerErrorCode.FILE_TYPE_MISMATCH;
import static org.eclipse.jifa.server.enums.ServerErrorCode.UNAVAILABLE;

Expand Down Expand Up @@ -177,6 +179,8 @@ public FileEntity getFileByUniqueName(String uniqueName, FileType expectedFileTy
public long handleTransferRequest(FileTransferRequest request) {
mustNotBe(ELASTIC_WORKER);

Validate.isFalse(config.getDisabledFileTransferMethods().contains(request.getMethod()), FILE_TRANSFER_METHOD_DISABLED);

if (isMaster() && getSchedulingStrategy() == SchedulingStrategy.STATIC) {
StaticWorkerEntity worker = workerService.asStaticWorkerService().selectForFileTransferRequest(request);
return workerService.sendRequestAndBlock(worker,
Expand Down Expand Up @@ -216,6 +220,8 @@ public FileTransferProgress getTransferProgress(long transferringFileId) {
public long handleUploadRequest(FileType type, MultipartFile file) throws Throwable {
mustNotBe(ELASTIC_WORKER);

Validate.isFalse(config.getDisabledFileTransferMethods().contains(FileTransferMethod.UPLOAD), FILE_TRANSFER_METHOD_DISABLED);

if (isMaster() && getSchedulingStrategy() == SchedulingStrategy.STATIC) {
StaticWorkerEntity worker = workerService.asStaticWorkerService().selectForFileUpload(type, file);
return workerService.asStaticWorkerService().handleUploadRequest(worker, type, file);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -12,6 +12,7 @@
********************************************************************************/
package org.eclipse.jifa.server.util;

import org.eclipse.jifa.common.domain.exception.ShouldNotReachHereException;
import org.eclipse.jifa.server.domain.dto.FileTransferRequest;
import org.eclipse.jifa.server.enums.FileTransferMethod;

Expand All @@ -25,6 +26,7 @@ public static String extractOriginalName(FileTransferRequest request) {
case SCP -> request.getScpSourcePath();
case URL -> request.getUrl();
case TEXT -> request.getFilename();
case UPLOAD -> throw new ShouldNotReachHereException();
};

String name = source.substring(source.lastIndexOf(java.io.File.separatorChar) + 1);
Expand Down

0 comments on commit 67cda3a

Please sign in to comment.