Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a bug with the policy service being hard coded to "local" #178

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -783,21 +783,21 @@ public List<Filter> getFiltersForPolicy(final Policy policy, final Map<String, M
}
}

final FilterConfiguration filterConfiguration = new FilterConfiguration.FilterConfigurationBuilder()
.withStrategies(customDictionary.getCustomDictionaryFilterStrategies())
.withAnonymizationService(new ZipCodeAnonymizationService(anonymizationCacheService))
.withAlertService(alertService)
.withIgnored(customDictionary.getIgnored())
.withIgnoredFiles(customDictionary.getIgnoredFiles())
.withIgnoredPatterns(customDictionary.getIgnoredPatterns())
.withCrypto(policy.getCrypto())
.withWindowSize(phileasConfiguration.spanWindowSize())
.build();

if(customDictionary.isFuzzy()) {

LOGGER.info("Custom fuzzy dictionary contains {} terms.", terms.size());

final FilterConfiguration filterConfiguration = new FilterConfiguration.FilterConfigurationBuilder()
.withStrategies(customDictionary.getCustomDictionaryFilterStrategies())
.withAnonymizationService(new ZipCodeAnonymizationService(anonymizationCacheService))
.withAlertService(alertService)
.withIgnored(policy.getIdentifiers().getZipCode().getIgnored())
.withIgnoredFiles(policy.getIdentifiers().getZipCode().getIgnoredFiles())
.withIgnoredPatterns(policy.getIdentifiers().getZipCode().getIgnoredPatterns())
.withCrypto(policy.getCrypto())
.withWindowSize(phileasConfiguration.spanWindowSize())
.build();

final SensitivityLevel sensitivityLevel = SensitivityLevel.fromName(customDictionary.getSensitivity());
final String classification = customDictionary.getClassification();
final boolean capitalized = false;
Expand All @@ -813,17 +813,6 @@ public List<Filter> getFiltersForPolicy(final Policy policy, final Map<String, M
// TODO: #112 Don't use a bloom filter for a small number of terms.
if(!terms.isEmpty()) {

final FilterConfiguration filterConfiguration = new FilterConfiguration.FilterConfigurationBuilder()
.withStrategies(customDictionary.getCustomDictionaryFilterStrategies())
.withAnonymizationService(new ZipCodeAnonymizationService(anonymizationCacheService))
.withAlertService(alertService)
.withIgnored(customDictionary.getIgnored())
.withIgnoredFiles(customDictionary.getIgnoredFiles())
.withIgnoredPatterns(customDictionary.getIgnoredPatterns())
.withCrypto(policy.getCrypto())
.withWindowSize(phileasConfiguration.spanWindowSize())
.build();

final String classification = customDictionary.getClassification();

enabledFilters.add(new BloomFilterDictionaryFilter(FilterType.CUSTOM_DICTIONARY, filterConfiguration, terms, classification));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public PhileasFilterService(final PhileasConfiguration phileasConfiguration, fin
final Gson gson = new GsonBuilder().registerTypeAdapter(String.class, new PlaceholderDeserializer()).create();

// Set the policy services.
this.policyService = new LocalPolicyService(phileasConfiguration);
this.policyService = buildPolicyService(phileasConfiguration);
this.policyUtils = new PolicyUtils(policyService, gson);

// Set the anonymization cache service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import ai.philterd.phileas.model.responses.BinaryDocumentFilterResponse;
import ai.philterd.phileas.model.serializers.PlaceholderDeserializer;
import ai.philterd.phileas.services.PhileasFilterService;
import ai.philterd.phileas.services.policies.InMemoryPolicyService;
import ai.philterd.phileas.services.policies.LocalPolicyService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.collections.CollectionUtils;
Expand Down Expand Up @@ -182,4 +184,23 @@ private void showSpans(List<Span> spans) {

}

@Test
void buildPolicyServiceMemory() throws IOException {
final var properties = new Properties();
properties.setProperty("filter.policies.service", "memory");
final var config = new PhileasConfiguration(properties);
final var service = new PhileasFilterService(config);

Assertions.assertInstanceOf(InMemoryPolicyService.class, service.getPolicyService());
}

@Test
void buildPolicyServiceLocal() throws IOException {
final var properties = new Properties();
properties.setProperty("filter.policies.service", "local");
final var config = new PhileasConfiguration(properties);
final var service = new PhileasFilterService(config);

Assertions.assertInstanceOf(LocalPolicyService.class, service.getPolicyService());
}
}
Loading