From 0cb18dde8aa04648c3d83c61c170363baeb6bc7a Mon Sep 17 00:00:00 2001 From: Bichitra Kumar Sahoo <32828151+bichitra95@users.noreply.github.com> Date: Mon, 5 Aug 2024 22:05:06 +0530 Subject: [PATCH 1/2] DQ-165: Prevent user YAML override --- .../v2/preprocessor/contract/ContractPreProcessor.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java index ac3df2535f..5bddc4c0da 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java @@ -110,7 +110,9 @@ private void processCreateContract(AtlasEntity entity, EntityMutationContext con boolean contractSync = syncContractCertificateStatus(entity, contract); contractString = DataContract.serialize(contract); - entity.setAttribute(ATTR_CONTRACT, contractString); + if (!isContractYaml(entity)) { + entity.setAttribute(ATTR_CONTRACT, contractString); + } String contractStringJSON = DataContract.serializeJSON(contract); entity.setAttribute(ATTR_CONTRACT_JSON, contractStringJSON); @@ -298,4 +300,8 @@ private static String getContractString(AtlasEntity entity) { } return contractString; } + + private static boolean isContractYaml(AtlasEntity entity) { + return !StringUtils.isEmpty((String) entity.getAttribute(ATTR_CONTRACT)); + } } From 3853127c8a61d0e1bdf73245e098700f08fdb8c2 Mon Sep 17 00:00:00 2001 From: Bichitra Kumar Sahoo <32828151+bichitra95@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:45:53 +0530 Subject: [PATCH 2/2] Serialize to YAML moved to if condition --- .../graph/v2/preprocessor/contract/ContractPreProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java index 5bddc4c0da..abe1c46170 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java @@ -109,8 +109,8 @@ private void processCreateContract(AtlasEntity entity, EntityMutationContext con authorizeContractCreateOrUpdate(entity, associatedAsset); boolean contractSync = syncContractCertificateStatus(entity, contract); - contractString = DataContract.serialize(contract); if (!isContractYaml(entity)) { + contractString = DataContract.serialize(contract); entity.setAttribute(ATTR_CONTRACT, contractString); } String contractStringJSON = DataContract.serializeJSON(contract);