mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-27 09:55:36 +00:00
MigrationFix for duplicate ViewAll in OrganizationPolicy (#23524)
This commit is contained in:
parent
f1afe8f5f1
commit
e058c5393e
@ -0,0 +1,19 @@
|
|||||||
|
package org.openmetadata.service.migration.mysql.v1910;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.openmetadata.service.migration.api.MigrationProcessImpl;
|
||||||
|
import org.openmetadata.service.migration.utils.MigrationFile;
|
||||||
|
import org.openmetadata.service.migration.utils.v1910.MigrationUtil;
|
||||||
|
|
||||||
|
public class Migration extends MigrationProcessImpl {
|
||||||
|
|
||||||
|
public Migration(MigrationFile migrationFile) {
|
||||||
|
super(migrationFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public void runDataMigration() {
|
||||||
|
MigrationUtil.removeDuplicateViewAllRules(collectionDAO);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.openmetadata.service.migration.postgres.v1910;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.openmetadata.service.migration.api.MigrationProcessImpl;
|
||||||
|
import org.openmetadata.service.migration.utils.MigrationFile;
|
||||||
|
import org.openmetadata.service.migration.utils.v1910.MigrationUtil;
|
||||||
|
|
||||||
|
public class Migration extends MigrationProcessImpl {
|
||||||
|
|
||||||
|
public Migration(MigrationFile migrationFile) {
|
||||||
|
super(migrationFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public void runDataMigration() {
|
||||||
|
MigrationUtil.removeDuplicateViewAllRules(collectionDAO);
|
||||||
|
}
|
||||||
|
}
|
@ -37,7 +37,7 @@ public class MigrationUtil {
|
|||||||
Policy organizationPolicy = repository.findByName("OrganizationPolicy", Include.NON_DELETED);
|
Policy organizationPolicy = repository.findByName("OrganizationPolicy", Include.NON_DELETED);
|
||||||
boolean noViewAllRule = true;
|
boolean noViewAllRule = true;
|
||||||
for (Rule rule : organizationPolicy.getRules()) {
|
for (Rule rule : organizationPolicy.getRules()) {
|
||||||
if (rule.getName().equals("OrganizationPolicy-View-All-Rule")) {
|
if (rule.getName().equals("OrganizationPolicy-ViewAll-Rule")) {
|
||||||
noViewAllRule = false;
|
noViewAllRule = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package org.openmetadata.service.migration.utils.v1910;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.openmetadata.schema.entity.policies.Policy;
|
||||||
|
import org.openmetadata.schema.entity.policies.accessControl.Rule;
|
||||||
|
import org.openmetadata.schema.type.Include;
|
||||||
|
import org.openmetadata.schema.utils.JsonUtils;
|
||||||
|
import org.openmetadata.service.Entity;
|
||||||
|
import org.openmetadata.service.exception.EntityNotFoundException;
|
||||||
|
import org.openmetadata.service.jdbi3.CollectionDAO;
|
||||||
|
import org.openmetadata.service.jdbi3.PolicyRepository;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class MigrationUtil {
|
||||||
|
|
||||||
|
public static void removeDuplicateViewAllRules(CollectionDAO collectionDAO) {
|
||||||
|
PolicyRepository repository = (PolicyRepository) Entity.getEntityRepository(Entity.POLICY);
|
||||||
|
try {
|
||||||
|
Policy organizationPolicy = repository.findByName("OrganizationPolicy", Include.NON_DELETED);
|
||||||
|
List<Rule> rules = organizationPolicy.getRules();
|
||||||
|
if (rules == null) {
|
||||||
|
LOG.info("OrganizationPolicy has no rules defined, skipping duplicate removal");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Rule> viewAllRules = new ArrayList<>();
|
||||||
|
List<Rule> otherRules = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Rule rule : rules) {
|
||||||
|
if (rule.getName() != null && rule.getName().equals("OrganizationPolicy-ViewAll-Rule")) {
|
||||||
|
viewAllRules.add(rule);
|
||||||
|
} else {
|
||||||
|
otherRules.add(rule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewAllRules.size() <= 1) {
|
||||||
|
LOG.info("No duplicate ViewAll rules found, skipping removal");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Found {} duplicate ViewAll rules, keeping the first one", viewAllRules.size());
|
||||||
|
|
||||||
|
// Keep only the first ViewAll rule and all other rules
|
||||||
|
List<Rule> updatedRules = new ArrayList<>(otherRules);
|
||||||
|
updatedRules.add(viewAllRules.get(0));
|
||||||
|
|
||||||
|
organizationPolicy.setRules(updatedRules);
|
||||||
|
|
||||||
|
collectionDAO
|
||||||
|
.policyDAO()
|
||||||
|
.update(
|
||||||
|
organizationPolicy.getId(),
|
||||||
|
organizationPolicy.getFullyQualifiedName(),
|
||||||
|
JsonUtils.pojoToJson(organizationPolicy));
|
||||||
|
|
||||||
|
LOG.info(
|
||||||
|
"Successfully removed {} duplicate ViewAll rules from OrganizationPolicy",
|
||||||
|
viewAllRules.size() - 1);
|
||||||
|
} catch (EntityNotFoundException ex) {
|
||||||
|
LOG.warn("OrganizationPolicy not found, skipping duplicate ViewAll rule removal");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.error(
|
||||||
|
"Error removing duplicate ViewAll rules from OrganizationPolicy: {}", ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user