From 2c84442e396de401078a46a6c2bdf0230275958f Mon Sep 17 00:00:00 2001 From: Ayush Shah Date: Mon, 7 Oct 2024 10:10:57 +0530 Subject: [PATCH] fix: Empty Connection Overwrite Logic (#18122) --- .../jdbi3/ServiceEntityRepository.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java index df2a2827190..c5444a9bfdb 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java @@ -124,20 +124,31 @@ public abstract class ServiceEntityRepository< private void updateConnection() { ServiceConnectionEntityInterface origConn = original.getConnection(); ServiceConnectionEntityInterface updatedConn = updated.getConnection(); - if (!CommonUtil.nullOrEmpty(origConn) && !CommonUtil.nullOrEmpty(updatedConn)) { + if (!CommonUtil.nullOrEmpty(updatedConn)) { + // We check if the updatedConn is null or empty String origJson = JsonUtils.pojoToJson(origConn); String updatedJson = JsonUtils.pojoToJson(updatedConn); S decryptedOrigConn = JsonUtils.readValue(origJson, serviceConnectionClass); S decryptedUpdatedConn = JsonUtils.readValue(updatedJson, serviceConnectionClass); SecretsManager secretsManager = SecretsManagerFactory.getSecretsManager(); - decryptedOrigConn.setConfig( - secretsManager.decryptServiceConnectionConfig( - decryptedOrigConn.getConfig(), original.getServiceType().value(), serviceType)); + if (!CommonUtil.nullOrEmpty(decryptedOrigConn)) { + // Only decrypt the original connection if it is not null or empty + decryptedOrigConn.setConfig( + secretsManager.decryptServiceConnectionConfig( + decryptedOrigConn.getConfig(), original.getServiceType().value(), serviceType)); + } + decryptedUpdatedConn.setConfig( secretsManager.decryptServiceConnectionConfig( decryptedUpdatedConn.getConfig(), updated.getServiceType().value(), serviceType)); - if (!objectMatch.test(decryptedOrigConn, decryptedUpdatedConn)) { - // we don't want save connection config details in our database + // we don't want save connection config details in our database + if (CommonUtil.nullOrEmpty(decryptedOrigConn) + && !CommonUtil.nullOrEmpty(decryptedUpdatedConn) + || !objectMatch.test(decryptedOrigConn, decryptedUpdatedConn)) { + + // if Original connection is null or empty and updated connection is not null or empty + // or if the connection details are different + recordChange("connection", "old-encrypted-value", "new-encrypted-value", true); } }