use of com.google.cloud.solutions.autotokenize.testing.stubs.dlp.StubbingDlpClientFactory in project auto-data-tokenize by GoogleCloudPlatform.
the class EncryptionPipelineTest method makeDlpStub.
public void makeDlpStub() {
if (pipelineOptions.getDlpEncryptConfigJson() == null) {
return;
}
var dlpEncryptConfig = TestResourceLoader.classPath().forProto(DlpEncryptConfig.class).loadJson(configParameters.get("dlpEncryptConfigFile"));
var encryptSchemaColumns = DeidentifyColumns.columnNamesIn(dlpEncryptConfig);
expectedSchema = makeExpectedSchema(inputSchema.toString(), encryptSchemaColumns);
var encryptColumns = encryptSchemaColumns.stream().map(name -> Pattern.compile("^(\\$\\.)?([^\\.]+\\.)(.*)$").matcher(name).replaceAll("$1$3")).collect(toImmutableList());
dlpClientFactory = new StubbingDlpClientFactory(new Base64EncodingDlpStub(PartialBatchAccumulator.RECORD_ID_COLUMN_NAME, encryptColumns, PROJECT_ID, pipelineOptions.getDlpRegion()));
}
use of com.google.cloud.solutions.autotokenize.testing.stubs.dlp.StubbingDlpClientFactory in project auto-data-tokenize by GoogleCloudPlatform.
the class BatchAndDlpDeIdRecordsTest method expand_valid.
@Test
public void expand_valid() {
ImmutableList<FlatRecord> expectedBase64EncodedContacts = TestResourceLoader.classPath().forProto(FlatRecord.class).loadAllTextFiles(ImmutableList.of("avro_records/contacts_schema/jane_doe_contact_number_base64_avro_record.textpb", "avro_records/contacts_schema/john_doe_contact_number_base64_avro_record.textpb"));
PCollection<FlatRecord> tokenizedRecords = testPipeline.apply(Create.of(CONTACT_RECORDS)).apply(BatchAndDlpDeIdRecords.withEncryptConfig(NUMBER_TOKENIZE_CONFIG).withDlpProjectId("dlp-test-project").withDlpRegion(testDlpRegion).withDlpClientFactory(new StubbingDlpClientFactory(new Base64EncodingDlpStub(PartialBatchAccumulator.RECORD_ID_COLUMN_NAME, ImmutableList.of("$.contacts.[\"contact\"].number"), "dlp-test-project", testDlpRegion))));
PAssert.that(tokenizedRecords).satisfies(new FlatRecordCheckerWithoutRecordIds(expectedBase64EncodedContacts));
testPipeline.run().waitUntilFinish();
}
Aggregations