use of com.sequenceiq.common.api.telemetry.model.AnonymizationRule in project cloudbreak by hortonworks.
the class AccountTelemetryService method createDefaultAccuontTelemetry.
public AccountTelemetry createDefaultAccuontTelemetry() {
AccountTelemetry defaultTelemetry = new AccountTelemetry();
List<AnonymizationRule> defaultEncodedRules = defaultRules.stream().map(rule -> {
AnonymizationRule encodedRule = new AnonymizationRule();
encodedRule.setValue(Base64.getEncoder().encodeToString(rule.getValue().getBytes()));
encodedRule.setReplacement(rule.getReplacement());
return encodedRule;
}).collect(Collectors.toList());
Features defaultFeatures = new Features();
defaultFeatures.addClusterLogsCollection(false);
defaultFeatures.addCloudStorageLogging(true);
defaultTelemetry.setRules(defaultEncodedRules);
defaultTelemetry.setFeatures(defaultFeatures);
return defaultTelemetry;
}
use of com.sequenceiq.common.api.telemetry.model.AnonymizationRule in project cloudbreak by hortonworks.
the class AccountTelemetryServiceTest method createRule.
private AnonymizationRule createRule(String pattern, String replacement) {
AnonymizationRule rule = new AnonymizationRule();
rule.setValue(pattern);
rule.setReplacement(replacement);
return rule;
}
use of com.sequenceiq.common.api.telemetry.model.AnonymizationRule in project cloudbreak by hortonworks.
the class AccountTelemetryServiceTest method testRulePattern.
@Test
public void testRulePattern() {
// GIVEN
String input = "My email card number is: 1111-2222-3333-4444 and 55555-11111";
List<AnonymizationRule> rules = new ArrayList<>();
AnonymizationRule rule1 = new AnonymizationRule();
rule1.setReplacement("[REDACTED]");
String pattern1 = "\\d{4}[^\\w]\\d{4}[^\\w]\\d{4}[^\\w]\\d{4}";
String encodedPattern1 = new String(Base64.getEncoder().encode(pattern1.getBytes()));
rule1.setValue(encodedPattern1);
AnonymizationRule rule2 = new AnonymizationRule();
rule2.setReplacement("[REDACTED]");
String pattern2 = "\\d{5}[^\\w]\\d{5}";
String encodedPattern2 = new String(Base64.getEncoder().encode(pattern2.getBytes()));
rule2.setValue(encodedPattern2);
rules.add(rule1);
rules.add(rule2);
// WHEN
String output = underTest.testRulePatterns(rules, input);
// THEN
assertThat(output).isEqualTo("My email card number is: [REDACTED] and [REDACTED]");
}
use of com.sequenceiq.common.api.telemetry.model.AnonymizationRule in project cloudbreak by hortonworks.
the class AccountTelemetryServiceTest method testValidateRules.
@Test
public void testValidateRules() {
// GIVEN
AccountTelemetry telemetry = new AccountTelemetry();
List<AnonymizationRule> rules = new ArrayList<>();
AnonymizationRule rule = new AnonymizationRule();
rule.setReplacement("[REDACTED]");
String pattern = "\\d{4}[^\\w]\\d{4}[^\\w]\\d{4}[^\\w]\\d{4}";
String encodedPattern = new String(Base64.getEncoder().encode(pattern.getBytes()));
rule.setValue(encodedPattern);
rules.add(rule);
telemetry.setRules(rules);
// WHEN
underTest.validateAnonymizationRules(telemetry);
}
use of com.sequenceiq.common.api.telemetry.model.AnonymizationRule in project cloudbreak by hortonworks.
the class AnonymizationRuleResolverTest method testDecodeRules.
@Test
public void testDecodeRules() {
// GIVEN
List<AnonymizationRule> rules = new ArrayList<>();
AnonymizationRule rule1 = new AnonymizationRule();
rule1.setReplacement("replace1");
AnonymizationRule rule2 = new AnonymizationRule();
rule2.setReplacement("replace2");
rule2.setValue(Base64.getEncoder().encodeToString("value2".getBytes()));
rules.add(rule1);
rules.add(rule2);
// WHEN
List<AnonymizationRule> finalRules = underTest.decodeRules(rules);
// THEN
assertEquals(finalRules.size(), 1);
assertEquals(finalRules.get(0).getValue(), "value2");
}
Aggregations