mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 03:19:14 +00:00
feat(core): 增加对环境变量的支持
This commit is contained in:
@@ -290,19 +290,23 @@ public class AlistHost implements ResourcePackHost {
|
||||
|
||||
@Override
|
||||
public ResourcePackHost create(Map<String, Object> arguments) {
|
||||
boolean useEnv = (boolean) arguments.getOrDefault("use-env", false);
|
||||
String apiUrl = (String) arguments.get("api-url");
|
||||
if (apiUrl == null || apiUrl.isEmpty()) {
|
||||
throw new IllegalArgumentException("'api-url' cannot be empty for Alist host");
|
||||
}
|
||||
String userName = (String) arguments.get("username");
|
||||
if (useEnv) userName = System.getenv("CE_ALIST_USERNAME");
|
||||
if (userName == null || userName.isEmpty()) {
|
||||
throw new IllegalArgumentException("'username' cannot be empty for Alist host");
|
||||
}
|
||||
String password = (String) arguments.get("password");
|
||||
if (useEnv) password = System.getenv("CE_ALIST_PASSWORD");
|
||||
if (password == null || password.isEmpty()) {
|
||||
throw new IllegalArgumentException("'password' cannot be empty for Alist host");
|
||||
}
|
||||
String filePassword = (String) arguments.getOrDefault("file-password", "");
|
||||
if (useEnv) filePassword = System.getenv("CE_ALIST_FILE_PASSWORD");
|
||||
String otpCode = (String) arguments.get("otp-code");
|
||||
Duration jwtTokenExpiration = Duration.ofHours((int) arguments.getOrDefault("jwt-token-expiration", 48));
|
||||
String uploadPath = (String) arguments.get("upload-path");
|
||||
|
||||
@@ -250,15 +250,19 @@ public class DropboxHost implements ResourcePackHost {
|
||||
public static class Factory implements ResourcePackHostFactory {
|
||||
@Override
|
||||
public ResourcePackHost create(Map<String, Object> arguments) {
|
||||
boolean useEnv = (boolean) arguments.getOrDefault("use-env", false);
|
||||
String appKey = (String) arguments.get("app-key");
|
||||
if (useEnv) appKey = System.getenv("CE_DROPBOX_APP_KEY");
|
||||
if (appKey == null || appKey.isEmpty()) {
|
||||
throw new IllegalArgumentException("Missing required 'app-key' configuration");
|
||||
}
|
||||
String appSecret = (String) arguments.get("app-secret");
|
||||
if (useEnv) appSecret = System.getenv("CE_DROPBOX_APP_SECRET");
|
||||
if (appSecret == null || appSecret.isEmpty()) {
|
||||
throw new IllegalArgumentException("Missing required 'app-secret' configuration");
|
||||
}
|
||||
String refreshToken = (String) arguments.get("refresh-token");
|
||||
if (useEnv) refreshToken = System.getenv("CE_DROPBOX_REFRESH_TOKEN");
|
||||
if (refreshToken == null || refreshToken.isEmpty()) {
|
||||
throw new IllegalArgumentException("Missing required 'refresh-token' configuration");
|
||||
}
|
||||
|
||||
@@ -270,7 +270,9 @@ public class LobFileHost implements ResourcePackHost {
|
||||
|
||||
@Override
|
||||
public ResourcePackHost create(Map<String, Object> arguments) {
|
||||
boolean useEnv = (boolean) arguments.getOrDefault("use-env", false);
|
||||
String apiKey = (String) arguments.get("api-key");
|
||||
if (useEnv) apiKey = System.getenv("CE_LOBFILE_API_KEY");
|
||||
if (apiKey == null || apiKey.isEmpty()) {
|
||||
throw new RuntimeException("Missing 'api-key' for LobFileHost");
|
||||
}
|
||||
|
||||
@@ -230,15 +230,19 @@ public class OneDriveHost implements ResourcePackHost {
|
||||
|
||||
@Override
|
||||
public ResourcePackHost create(Map<String, Object> arguments) {
|
||||
boolean useEnv = (boolean) arguments.getOrDefault("use-env", false);
|
||||
String clientId = (String) arguments.get("client-id");
|
||||
if (useEnv) clientId = System.getenv("CE_ONEDRIVE_CLIENT_ID");
|
||||
if (clientId == null || clientId.isEmpty()) {
|
||||
throw new IllegalArgumentException("Missing required 'client-id' configuration");
|
||||
}
|
||||
String clientSecret = (String) arguments.get("client-secret");
|
||||
if (useEnv) clientSecret = System.getenv("CE_ONEDRIVE_CLIENT_SECRET");
|
||||
if (clientSecret == null || clientSecret.isEmpty()) {
|
||||
throw new IllegalArgumentException("Missing required 'client-secret' configuration");
|
||||
}
|
||||
String refreshToken = (String) arguments.get("refresh-token");
|
||||
if (useEnv) refreshToken = System.getenv("CE_ONEDRIVE_REFRESH_TOKEN");
|
||||
if (refreshToken == null || refreshToken.isEmpty()) {
|
||||
throw new IllegalArgumentException("Missing required 'refresh-token' configuration");
|
||||
}
|
||||
|
||||
@@ -156,6 +156,7 @@ public class S3Host implements ResourcePackHost {
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public ResourcePackHost create(Map<String, Object> arguments) {
|
||||
boolean useEnv = (boolean) arguments.getOrDefault("use-env", false);
|
||||
String endpoint = (String) arguments.get("endpoint");
|
||||
if (endpoint == null || endpoint.isEmpty()) {
|
||||
throw new IllegalArgumentException("'endpoint' cannot be empty for S3 host");
|
||||
@@ -168,10 +169,12 @@ public class S3Host implements ResourcePackHost {
|
||||
}
|
||||
String region = (String) arguments.getOrDefault("region", "auto");
|
||||
String accessKeyId = (String) arguments.get("access-key-id");
|
||||
if (useEnv) accessKeyId = System.getenv("CE_S3_ACCESS_KEY_ID");
|
||||
if (accessKeyId == null || accessKeyId.isEmpty()) {
|
||||
throw new IllegalArgumentException("'access-key-id' cannot be empty for S3 host");
|
||||
}
|
||||
String accessKeySecret = (String) arguments.get("access-key-secret");
|
||||
if (useEnv) accessKeySecret = System.getenv("CE_S3_ACCESS_KEY_SECRET");
|
||||
if (accessKeySecret == null || accessKeySecret.isEmpty()) {
|
||||
throw new IllegalArgumentException("'access-key-secret' cannot be empty for S3 host");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user