in services/library/src/main/java/com/google/cloud/pso/bq_pii_classifier/functions/inspector/Inspector.java [136:219]
private InspectJobConfig createJob(
TableSpec targetTableSpec,
TableScanLimitsConfig rowsLimitConfig,
Integer tableNumRows,
String inspectionTemplateId){
// 1. Specify which table to inspect
BigQueryTable bqTable = BigQueryTable.newBuilder()
.setProjectId(targetTableSpec.getProject())
.setDatasetId(targetTableSpec.getDataset())
.setTableId(targetTableSpec.getTable())
.build();
BigQueryOptions.Builder bqOptionsBuilder = BigQueryOptions.newBuilder()
.setTableReference(bqTable)
.setSampleMethod(BigQueryOptions.SampleMethod.forNumber(config.getSamplingMethod()));
Integer limitValue = rowsLimitConfig.getTableScanLimitBasedOnNumRows(tableNumRows);
switch (rowsLimitConfig.getScanLimitsType()){
case NUMBER_OF_ROWS: bqOptionsBuilder.setRowsLimit(limitValue); break;
case PERCENTAGE_OF_ROWS: bqOptionsBuilder.setRowsLimitPercent(limitValue); break;
}
BigQueryOptions bqOptions = bqOptionsBuilder.build();
StorageConfig storageConfig =
StorageConfig.newBuilder()
.setBigQueryOptions(bqOptions)
.build();
// The minimum likelihood required before returning a match:
// See: https://cloud.google.com/dlp/docs/likelihood
Likelihood minLikelihood = Likelihood.valueOf(config.getMinLikelihood());
// The maximum number of findings to report (0 = server maximum)
InspectConfig.FindingLimits findingLimits =
InspectConfig.FindingLimits.newBuilder()
.setMaxFindingsPerItem(config.getMaxFindings())
.build();
InspectConfig inspectConfig =
InspectConfig.newBuilder()
.setIncludeQuote(false) // don't store identified PII in the table
.setMinLikelihood(minLikelihood)
.setLimits(findingLimits)
.build();
// 2. Specify saving detailed results to BigQuery.
// Save detailed findings to BigQuery
BigQueryTable outputBqTable = BigQueryTable.newBuilder()
.setProjectId(config.getProjectId())
.setDatasetId(config.getBqResultsDataset())
.setTableId(config.getBqResultsTable())
.build();
OutputStorageConfig outputStorageConfig = OutputStorageConfig.newBuilder()
.setTable(outputBqTable)
.build();
Action.SaveFindings saveFindingsActions = Action.SaveFindings.newBuilder()
.setOutputConfig(outputStorageConfig)
.build();
Action bqAction = Action.newBuilder()
.setSaveFindings(saveFindingsActions)
.build();
// 3. Specify sending PubSub notification on completion.
Action.PublishToPubSub publishToPubSub = Action.PublishToPubSub.newBuilder()
.setTopic(config.getDlpNotificationTopic())
.build();
Action pubSubAction = Action.newBuilder()
.setPubSub(publishToPubSub)
.build();
// Configure the inspection job we want the service to perform.
return InspectJobConfig.newBuilder()
.setInspectTemplateName(inspectionTemplateId)
.setInspectConfig(inspectConfig)
.setStorageConfig(storageConfig)
.addActions(bqAction)
.addActions(pubSubAction)
.build();
}