Skip to content

Commit

Permalink
feat: extract Desensitization Provider to arex-common
Browse files Browse the repository at this point in the history
  • Loading branch information
rchen9 committed Oct 9, 2024
1 parent a20cd91 commit 1091877
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.arextest.schedule.beans;

import com.arextest.common.desensitization.DesensitizationProvider;
import com.arextest.config.model.dao.config.SystemConfigurationCollection;
import com.arextest.config.model.dao.config.SystemConfigurationCollection.KeySummary;
import com.arextest.extension.desensitization.DataDesensitization;
import com.arextest.schedule.serialization.DesensitizationProvider;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Filters;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -16,7 +23,9 @@ public class DataDesensitizationConfiguration {
@Bean
@ConditionalOnMissingBean(DesensitizationProvider.class)
DesensitizationProvider desensitizationProvider(MongoDatabaseFactory factory) {
return new DesensitizationProvider(factory.getMongoDatabase());
String desensitizationJarUrl = DataDesensitizationUtils.getDesensitizationJarUrl(
factory.getMongoDatabase());
return new DesensitizationProvider(desensitizationJarUrl);
}

@Bean
Expand All @@ -25,4 +34,21 @@ DataDesensitization dataDesensitization(DesensitizationProvider desensitizationP
}


private static class DataDesensitizationUtils {

private static final String SYSTEM_CONFIGURATION = "SystemConfiguration";
private static final String DESENSITIZATION_JAR = "desensitizationJar";
private static final String JAR_URL = "jarUrl";

private static String getDesensitizationJarUrl(MongoDatabase database) {
MongoCollection<Document> collection = database.getCollection(SYSTEM_CONFIGURATION);
Bson filter = Filters.eq(SystemConfigurationCollection.Fields.key,
KeySummary.DESERIALIZATION_JAR);
Document document = collection.find(filter).first();
if (document != null && document.get(DESENSITIZATION_JAR) != null) {
return document.get(DESENSITIZATION_JAR, Document.class).getString(JAR_URL);
}
return null;
}
}
}

This file was deleted.

0 comments on commit 1091877

Please sign in to comment.