Skip to content

Commit

Permalink
Fixes a bug with the policy service being hard coded to "local" (#178)
Browse files Browse the repository at this point in the history
* Fixes a bug with the policy service being hard coded to "local"

* Fix init of the fuzzy filter policy loader
  • Loading branch information
JessieAMorris authored Dec 18, 2024
1 parent ab0c806 commit 756553a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
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());
}
}

0 comments on commit 756553a

Please sign in to comment.