use of com.google.cloud.pso.bq_pii_classifier.entities.TablePolicyTags in project bq-pii-classifier by GoogleCloudPlatform.
the class FindingsReaderAutoDlp method getFieldsToPolicyTagsMap.
/**
* Look for DLP results by a tableSpec. Returns a map of fields to policy tags or null if DLP
* doesn't have findings
*
* @param inspectedTableSpec: "project.dataset.table"
* @return
* @throws InterruptedException
* @throws NonRetryableApplicationException
* @throws IOException
*/
public TablePolicyTags getFieldsToPolicyTagsMap(String inspectedTableSpec) throws InterruptedException, NonRetryableApplicationException, IOException {
String formattedQuery = generateQuery(inspectedTableSpec);
// Create a job ID so that we can safely retry.
Job queryJob = bqService.submitJob(formattedQuery);
TableResult result = bqService.waitAndGetJobResults(queryJob);
// Construct a mapping between field names and DLP infotypes
Map<String, String> fieldsToPolicyTagMap = new HashMap<>();
for (FieldValueList row : result.iterateAll()) {
if (row.get("field_name").isNull()) {
throw new NonRetryableApplicationException("getFieldsToPolicyTagsMap query returned rows with null field_name");
}
String column_name = row.get("field_name").getStringValue();
if (row.get("info_type").isNull()) {
throw new NonRetryableApplicationException(String.format("getFieldsToPolicyTagsMap query returned rows with null info_type for column '%s'", column_name));
}
String info_type = row.get("info_type").getStringValue();
if (row.get("policy_tag").isNull()) {
throw new NonRetryableApplicationException(String.format("getFieldsToPolicyTagsMap query returned rows with null policy_tag for column '%s' of info_type '%s'. Checkout the classification taxonomy configuration and the DLP inspection template. All InfoTypes defined in the inspection template must have corresponding entries in the classification taxonomies.", column_name, info_type));
}
String policy_tag = row.get("policy_tag").getStringValue();
fieldsToPolicyTagMap.put(column_name, policy_tag);
}
if (fieldsToPolicyTagMap.isEmpty())
return null;
else
return new TablePolicyTags(TableSpec.fromSqlString(inspectedTableSpec), fieldsToPolicyTagMap);
}
use of com.google.cloud.pso.bq_pii_classifier.entities.TablePolicyTags in project bq-pii-classifier by GoogleCloudPlatform.
the class FindingsReaderStandardDlp method getFieldsToPolicyTagsMap.
/**
* Look for DLP results by a tableSpec. Returns a map of fields to policy tags or null if DLP
* doesn't have findings
*
* @param dlpJobName: "projects/<PROJECT>/locations/<GCP REGION>/dlpJobs/<JOB ID>"
* @return
* @throws InterruptedException
* @throws NonRetryableApplicationException
* @throws IOException
*/
public TablePolicyTags getFieldsToPolicyTagsMap(String dlpJobName) throws InterruptedException, NonRetryableApplicationException, IOException {
String formattedQuery = generateQuery(dlpJobName);
// Create a job ID so that we can safely retry.
Job queryJob = bqService.submitJob(formattedQuery);
TableResult result = bqService.waitAndGetJobResults(queryJob);
// Construct a mapping between field names and DLP infotypes
Map<String, String> fieldsToPolicyTagMap = new HashMap<>();
String tableSpecStr = "";
for (FieldValueList row : result.iterateAll()) {
if (row.get("field_name").isNull()) {
throw new NonRetryableApplicationException("getFieldsToPolicyTagsMap query returned rows with null field_name");
}
String column_name = row.get("field_name").getStringValue();
if (row.get("info_type").isNull()) {
throw new NonRetryableApplicationException(String.format("getFieldsToPolicyTagsMap query returned rows with null info_type for column '%s'", column_name));
}
String info_type = row.get("info_type").getStringValue();
if (row.get("policy_tag").isNull()) {
throw new NonRetryableApplicationException(String.format("getFieldsToPolicyTagsMap query returned rows with null policy_tag for column '%s' of info_type '%s'. Checkout the classification taxonomy configuration and the DLP inspection template. All InfoTypes defined in the inspection template must have corresponding entries in the classification taxonomies.", column_name, info_type));
}
String policy_tag = row.get("policy_tag").getStringValue();
if (row.get("table_spec").isNull()) {
throw new NonRetryableApplicationException("getFieldsToPolicyTagsMap query returned rows with null table_spec");
}
tableSpecStr = row.get("table_spec").getStringValue();
fieldsToPolicyTagMap.put(column_name, policy_tag);
}
if (fieldsToPolicyTagMap.isEmpty())
return null;
else
return new TablePolicyTags(TableSpec.fromSqlString(tableSpecStr), fieldsToPolicyTagMap);
}
Aggregations