Search code examples
google-cloud-platformgoogle-cloud-dlp

How to run API for DLP scan and save to Bigquery?


I am trying to write a Java CF HTTP trigger, which accepts dataset/table as parameter and runs a predefined DLP template to provide inspection output which needs to be stored in Bigquery.
Currently none of the sample instructions are using Bigquery as Action ouput. From what I could gather OutputStorageConfig or StorageConfig needs to be used to set the output action to Bigquery, but I am looking for some code examples.
Thanks in advance.


Solution

  • Something like this?

       static Action createSaveFindingsAction(String datasetId, String tableId, String projectId) {
            return Action.newBuilder()
                .setSaveFindings(
                    Action.SaveFindings.newBuilder()
                        .setOutputConfig(
                            OutputStorageConfig.newBuilder()
                                .setTable(
                                    BigQueryTable.newBuilder()
                                        .setProjectId(projectId)
                                        .setDatasetId(datasetId)
                                        .setTableId(tableId))))
                .build();
          }
    
      CreateDlpJobRequest createCloudStorageReq(
          String templateName, CloudStorageOptions cloudStorageOptions) {
        return CreateDlpJobRequest.newBuilder()
            .setParent(PARENT)
            .setInspectJob(
                InspectJobConfig.newBuilder()
                    .setInspectTemplateName(templateName)
                    .setStorageConfig(
                        StorageConfig.newBuilder().setCloudStorageOptions(cloudStorageOptions))
                    .addActions(createSaveFindingsAction(INSPECT_OUTPUT_DATASET, TABLE_ID, PROJECT_ID)))
            .build();
      }