修改 bug--20261202
这个提交包含在:
+1
@@ -222,6 +222,7 @@ class SchedulingService {
|
||||
String requestHash = policy.requestHash(normalized);
|
||||
RunView replay = repository.replayRun(actor, RunAction.SUBMIT, idempotencyKey, requestHash);
|
||||
if (replay != null) return replay;
|
||||
reconcileAutomaticPrevious(actor, scheduleId);
|
||||
validateReferences(actor, toDefinition(definition), scheduleId);
|
||||
requireExecutionDependencies(actor, scheduleId, toDefinition(definition));
|
||||
requireExecutable(toDefinition(definition));
|
||||
|
||||
+13
@@ -31,6 +31,8 @@ public class DataSourceService {
|
||||
private final SeaTunnelAdapter seaTunnelAdapter;
|
||||
private final SecretProvisioner secretProvisioner;
|
||||
private final ManagedCredentialReferenceFactory referenceFactory;
|
||||
@org.springframework.beans.factory.annotation.Autowired
|
||||
private TransientConnectionReceipts receipts;
|
||||
|
||||
public List<DataSourcePublicView> list(String dataDomainCode) {
|
||||
DataSourceAccessScope scope = accessContext.current();
|
||||
@@ -69,6 +71,17 @@ public class DataSourceService {
|
||||
} else {
|
||||
committed = true;
|
||||
}
|
||||
var tested = receipts == null ? null : receipts.find(receipts.fingerprint(scope, command));
|
||||
if (result.created() && tested != null) {
|
||||
String reason = "复用新增表单已通过的连接测试";
|
||||
var start = registry.beginConnectionTest(scope, dataSourceId, "form-test-" + dataSourceId,
|
||||
reason, DataSourcePolicy.testHash(dataSourceId, reason));
|
||||
registry.completeConnectionTest(scope, start.view().testId(), result.view().version(),
|
||||
new SeaTunnelAdapter.ConnectionTestResult(null, "SUCCEEDED", tested.connectivityStatus(),
|
||||
tested.accountPermissionStatus(), "UNKNOWN", "UNKNOWN", NormalizedExternalStatus.SUCCEEDED,
|
||||
null, "已复用保存前五分钟内同账号、同配置及同凭据的连接测试"));
|
||||
return publicView(registry.find(scope, dataSourceId));
|
||||
}
|
||||
return publicView(result.view());
|
||||
} catch (RuntimeException exception) {
|
||||
if (provisioned && !committed) {
|
||||
|
||||
+9
@@ -29,6 +29,8 @@ public class DataSourceTransientConnectionTester {
|
||||
private final DataSourceAccessContext accessContext;
|
||||
private final ConnectionProvider connections;
|
||||
private final HiveProbe hiveProbe;
|
||||
@Autowired
|
||||
private TransientConnectionReceipts receipts;
|
||||
|
||||
@Autowired
|
||||
public DataSourceTransientConnectionTester(DataSourceAccessContext accessContext, HiveJdbcRuntime hiveRuntime) {
|
||||
@@ -55,6 +57,13 @@ public class DataSourceTransientConnectionTester {
|
||||
}
|
||||
|
||||
public DataSourceTransientConnectionTestView test(DataSourceCreateCommand command) {
|
||||
String fingerprint = receipts == null ? null : receipts.fingerprint(accessContext.current(), command);
|
||||
DataSourceTransientConnectionTestView result = performTest(command);
|
||||
if (fingerprint != null) receipts.remember(fingerprint, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private DataSourceTransientConnectionTestView performTest(DataSourceCreateCommand command) {
|
||||
DataSourceAccessScope scope = accessContext.current();
|
||||
char[] password = DataSourcePolicy.requireCreatePassword(command);
|
||||
try {
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package cn.aixunkeji.datagov.integration.datasource;
|
||||
|
||||
import cn.aixunkeji.datagov.integration.api.datasource.DataSourceCreateCommand;
|
||||
import cn.aixunkeji.datagov.integration.api.datasource.DataSourceTransientConnectionTestView;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.HexFormat;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/** Short-lived, process-local proof; no plaintext credential or client-supplied success is retained. */
|
||||
@Component
|
||||
public class TransientConnectionReceipts {
|
||||
private final byte[] secret = new byte[32];
|
||||
private final LinkedHashMap<String, Receipt> receipts = new LinkedHashMap<>();
|
||||
private record Receipt(long expiresAt, DataSourceTransientConnectionTestView result) {}
|
||||
public TransientConnectionReceipts() { new SecureRandom().nextBytes(secret); }
|
||||
|
||||
String fingerprint(DataSourceAccessScope scope, DataSourceCreateCommand command) {
|
||||
char[] password = DataSourcePolicy.requireCreatePassword(command);
|
||||
byte[] bytes = null;
|
||||
try {
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
mac.init(new SecretKeySpec(secret, "HmacSHA256"));
|
||||
mac.update((scope.actorId() + ":" + scope.orgScopeId() + ":" + DataSourcePolicy.createHash(command, scope)).getBytes(StandardCharsets.UTF_8));
|
||||
var encoded = StandardCharsets.UTF_8.encode(java.nio.CharBuffer.wrap(password));
|
||||
bytes = new byte[encoded.remaining()]; encoded.get(bytes);
|
||||
if (encoded.hasArray()) Arrays.fill(encoded.array(), (byte) 0);
|
||||
return HexFormat.of().formatHex(mac.doFinal(bytes));
|
||||
} catch (java.security.GeneralSecurityException exception) {
|
||||
throw new IllegalStateException("Connection receipt unavailable", exception);
|
||||
} finally {
|
||||
Arrays.fill(password, '\0');
|
||||
if (bytes != null) Arrays.fill(bytes, (byte) 0);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void remember(String key, DataSourceTransientConnectionTestView result) {
|
||||
receipts.remove(key);
|
||||
receipts.entrySet().removeIf(entry -> entry.getValue().expiresAt() < System.currentTimeMillis());
|
||||
if (!"SUCCEEDED".equals(result.status())) return;
|
||||
while (receipts.size() >= 256) receipts.remove(receipts.keySet().iterator().next());
|
||||
receipts.put(key, new Receipt(System.currentTimeMillis() + 300_000, result));
|
||||
}
|
||||
|
||||
synchronized DataSourceTransientConnectionTestView find(String key) {
|
||||
Receipt receipt = receipts.get(key);
|
||||
return receipt != null && receipt.expiresAt() >= System.currentTimeMillis() ? receipt.result() : null;
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -58,6 +58,8 @@ class TransformationCleaningSqlCompiler {
|
||||
? null : new Expression(quoted(source.name()), quoted(source.name())));
|
||||
}
|
||||
|
||||
Map<String, String> mappedSources = new LinkedHashMap<>();
|
||||
Set<String> maskedTargets = new java.util.HashSet<>();
|
||||
for (StandardizationRule rule : safe(rules.standardizationRules())) {
|
||||
if (rule == null || rule.operation() == null) throw invalid("TRANSFORMATION_RULE_INVALID");
|
||||
Column source = requireColumn(sourceColumns, rule.sourceField());
|
||||
@@ -73,8 +75,14 @@ class TransformationCleaningSqlCompiler {
|
||||
&& (!text(source) || !text(target))) {
|
||||
throw invalid("TRANSFORMATION_FIELD_TYPE_INCOMPATIBLE");
|
||||
}
|
||||
String value = quoted(source.name());
|
||||
String previousSource = mappedSources.putIfAbsent(key(target.name()), key(source.name()));
|
||||
if (previousSource != null && !previousSource.equals(key(source.name())))
|
||||
throw invalid("TRANSFORMATION_TARGET_SOURCE_CONFLICT");
|
||||
if (maskedTargets.contains(key(target.name()))) throw invalid("TRANSFORMATION_MASKING_CHAIN_UNSUPPORTED");
|
||||
Expression previous = previousSource == null ? null : expressions.get(key(target.name()));
|
||||
String value = previous == null ? quoted(source.name()) : previous.afterSql();
|
||||
if (rule.operation() == StandardizationOperation.TEXT_MASK || rule.operation() == StandardizationOperation.TEXT_REPLACE || rule.operation() == StandardizationOperation.TEXT_FORMAT_MASK) {
|
||||
maskedTargets.add(key(target.name()));
|
||||
expressions.put(key(target.name()), masking(value, rule, target, validated.hive()));
|
||||
continue;
|
||||
}
|
||||
@@ -84,7 +92,7 @@ class TransformationCleaningSqlCompiler {
|
||||
case TEXT_CASE -> textCase(value, rule.parameters());
|
||||
default -> throw unsupported("TRANSFORMATION_RULE_UNSUPPORTED");
|
||||
};
|
||||
expressions.put(key(target.name()), new Expression(value, expression));
|
||||
expressions.put(key(target.name()), new Expression(quoted(source.name()), expression));
|
||||
}
|
||||
|
||||
if (safe(rules.completionRules()).stream().anyMatch(rule -> rule != null
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package cn.aixunkeji.datagov.integration.datasource;
|
||||
|
||||
import cn.aixunkeji.datagov.integration.api.datasource.DataSourceCreateCommand;
|
||||
import cn.aixunkeji.datagov.integration.api.datasource.DataSourceTransientConnectionTestView;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TransientConnectionReceiptsTest {
|
||||
@Test void successIsBoundToActorOrganizationConfigurationAndCredential() {
|
||||
var cache = new TransientConnectionReceipts();
|
||||
var scope = new DataSourceAccessScope(7, 91);
|
||||
try (var command = command("first", "example.test")) {
|
||||
var fingerprint = cache.fingerprint(scope, command);
|
||||
var result = result("SUCCEEDED");
|
||||
cache.remember(fingerprint, result);
|
||||
assertThat(cache.find(cache.fingerprint(scope, command))).isEqualTo(result);
|
||||
assertThat(cache.find(cache.fingerprint(new DataSourceAccessScope(8, 91), command))).isNull();
|
||||
assertThat(cache.find(cache.fingerprint(new DataSourceAccessScope(7, 92), command))).isNull();
|
||||
try (var changedPassword = command("second", "example.test"); var changedHost = command("first", "other.test")) {
|
||||
assertThat(cache.find(cache.fingerprint(scope, changedPassword))).isNull();
|
||||
assertThat(cache.find(cache.fingerprint(scope, changedHost))).isNull();
|
||||
}
|
||||
cache.remember(fingerprint, result("FAILED"));
|
||||
assertThat(cache.find(fingerprint)).isNull();
|
||||
assertThat(command.password()).isEqualTo("first".toCharArray());
|
||||
}
|
||||
}
|
||||
private DataSourceCreateCommand command(String password, String host) {
|
||||
return new DataSourceCreateCommand("source", "MYSQL", host, 3306, "example", "user", password.toCharArray(),
|
||||
"owner", null, "domain", "JDBC", "PASSWORD", Map.of());
|
||||
}
|
||||
private DataSourceTransientConnectionTestView result(String status) {
|
||||
return new DataSourceTransientConnectionTestView(status, "VERIFIED", "VERIFIED", null, "test", LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
+9
@@ -9,6 +9,15 @@ import static org.assertj.core.api.Assertions.*;
|
||||
class TransformationCleaningSqlCompilerTest {
|
||||
private final TransformationCleaningSqlCompiler compiler = new TransformationCleaningSqlCompiler();
|
||||
|
||||
@Test void multipleRulesForOneFieldComposeInConfiguredOrder() {
|
||||
var rules = new RuleSnapshot(List.of(
|
||||
new StandardizationRule("trim", "value", "value", StandardizationOperation.TEXT_TRIM, Map.of("trimMode", "BOTH")),
|
||||
new StandardizationRule("upper", "value", "value", StandardizationOperation.TEXT_CASE, Map.of("caseMode", "UPPER"))
|
||||
), List.of(), List.of(), List.of());
|
||||
assertThat(compiler.compile(context(new Column("value", "STRING", true)), rules, 10).writeSql())
|
||||
.contains("UPPER(TRIM(`value`))");
|
||||
}
|
||||
|
||||
@Test void maskingUsesCharacterCountsHidesOriginalAndFullyMasksShortValues() {
|
||||
var parameters = new java.util.HashMap<>(Map.of("policySha256", "a".repeat(64), "bindingSha256", "b".repeat(64),
|
||||
"prefixKeep", "2", "suffixKeep", "2", "maskCharacter", "*"));
|
||||
|
||||
在新工单中引用
屏蔽一个用户