Search in sources :

Example 1 with AnonymizationRule

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;
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) Features(com.sequenceiq.common.api.telemetry.model.Features) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) PatternSyntaxException(jregex.PatternSyntaxException) Pattern(jregex.Pattern) Logger(org.slf4j.Logger) AccountTelemetryConfig(com.sequenceiq.environment.configuration.telemetry.AccountTelemetryConfig) AccountTelemetryRepository(com.sequenceiq.environment.telemetry.repository.AccountTelemetryRepository) LoggerFactory(org.slf4j.LoggerFactory) RegionAwareCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator) AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CrnResourceDescriptor(com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor) Base64(java.util.Base64) List(java.util.List) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) Replacer(jregex.Replacer) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) Features(com.sequenceiq.common.api.telemetry.model.Features)

Example 2 with AnonymizationRule

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;
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule)

Example 3 with AnonymizationRule

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]");
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 4 with AnonymizationRule

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);
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 5 with AnonymizationRule

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");
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

AnonymizationRule (com.sequenceiq.common.api.telemetry.model.AnonymizationRule)11 ArrayList (java.util.ArrayList)8 Test (org.junit.jupiter.api.Test)6 AccountTelemetry (com.sequenceiq.environment.telemetry.domain.AccountTelemetry)4 AccountTelemetryConfig (com.sequenceiq.environment.configuration.telemetry.AccountTelemetryConfig)2 Pattern (jregex.Pattern)2 Replacer (jregex.Replacer)2 CrnResourceDescriptor (com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor)1 RegionAwareCrnGenerator (com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Features (com.sequenceiq.common.api.telemetry.model.Features)1 AccountTelemetryRepository (com.sequenceiq.environment.telemetry.repository.AccountTelemetryRepository)1 Base64 (java.util.Base64)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 PatternSyntaxException (jregex.PatternSyntaxException)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1