Search in sources :

Example 1 with FindingsReader

use of com.google.cloud.pso.bq_pii_classifier.services.findings.FindingsReader in project bq-pii-classifier by GoogleCloudPlatform.

the class TaggerController method receiveMessage.

@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity receiveMessage(@RequestBody PubSubEvent requestBody) {
    String defaultTrackingId = "0000000000000-z";
    Operation taggerRequest = null;
    try {
        if (requestBody == null || requestBody.getMessage() == null) {
            String msg = "Bad Request: invalid message format";
            logger.logSevereWithTracker(defaultTrackingId, msg);
            throw new NonRetryableApplicationException("Request body or message is Null.");
        }
        // The pubsub message could come from different sources with different formats
        // 1. From the Dispatcher as JSON encoded "Operation" object (in standard and auto-dlp modes)
        // 2. From Standard DLP inspection job notifications (PubSub Actions) as a string message with the DLP job name
        // 3. From Auto DLP notifications (PubSub Actions) as Protobuf encoded "DataProfilePubSubMessage" (in AutoDLP mode only)
        // Here we try and parse it directly as an "Operation" object or indirectly via the "DataProfilePubSubMessage" proto
        taggerRequest = parseEvent(requestBody);
        BigQueryService bigQueryService = new BigQueryServiceImpl();
        // determine the Type of DLP FindingsReader based on env
        FindingsReader findingsReader = FindingsReaderFactory.getNewReader(FindingsReaderFactory.findReader(environment.getIsAutoDlpMode(), environment.getPromoteMixedTypes()), bigQueryService, environment.getProjectId(), environment.getDlpDataset(), environment.getIsAutoDlpMode() ? environment.getDlpTableAuto() : environment.getDlpTableStandard(), environment.getConfigViewDatasetDomainMap(), environment.getConfigViewProjectDomainMap(), environment.getConfigViewInfoTypePolicyTagsMap());
        Tagger tagger = new Tagger(environment.toConfig(), bigQueryService, findingsReader, new GCSPersistentSetImpl(environment.getGcsFlagsBucket()), "tagger-flags");
        tagger.execute(taggerRequest, requestBody.getMessage().getMessageId());
        return new ResponseEntity("Process completed successfully.", HttpStatus.OK);
    } catch (Exception e) {
        String trackingId = taggerRequest == null ? defaultTrackingId : taggerRequest.getTrackingId();
        return ControllerExceptionHelper.handleException(e, logger, trackingId);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) BigQueryServiceImpl(com.google.cloud.pso.bq_pii_classifier.services.bq.BigQueryServiceImpl) BigQueryService(com.google.cloud.pso.bq_pii_classifier.services.bq.BigQueryService) Tagger(com.google.cloud.pso.bq_pii_classifier.functions.tagger.Tagger) NonRetryableApplicationException(com.google.cloud.pso.bq_pii_classifier.entities.NonRetryableApplicationException) FindingsReader(com.google.cloud.pso.bq_pii_classifier.services.findings.FindingsReader) Operation(com.google.cloud.pso.bq_pii_classifier.entities.Operation) GCSPersistentSetImpl(com.google.cloud.pso.bq_pii_classifier.services.set.GCSPersistentSetImpl) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) NonRetryableApplicationException(com.google.cloud.pso.bq_pii_classifier.entities.NonRetryableApplicationException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NonRetryableApplicationException (com.google.cloud.pso.bq_pii_classifier.entities.NonRetryableApplicationException)1 Operation (com.google.cloud.pso.bq_pii_classifier.entities.Operation)1 Tagger (com.google.cloud.pso.bq_pii_classifier.functions.tagger.Tagger)1 BigQueryService (com.google.cloud.pso.bq_pii_classifier.services.bq.BigQueryService)1 BigQueryServiceImpl (com.google.cloud.pso.bq_pii_classifier.services.bq.BigQueryServiceImpl)1 FindingsReader (com.google.cloud.pso.bq_pii_classifier.services.findings.FindingsReader)1 GCSPersistentSetImpl (com.google.cloud.pso.bq_pii_classifier.services.set.GCSPersistentSetImpl)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1