Search in sources :

Example 1 with DlpServiceImpl

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

the class InspectorController method receiveMessage.

@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity receiveMessage(@RequestBody PubSubEvent requestBody) {
    String trackingId = "0000000000000-z";
    DlpService dlpService = null;
    BigQueryService bqService = null;
    try {
        if (requestBody == null || requestBody.getMessage() == null) {
            String msg = "Bad Request: invalid message format";
            logger.logSevereWithTracker(trackingId, msg);
            throw new NonRetryableApplicationException("Request body or message is Null.");
        }
        String requestJsonString = requestBody.getMessage().dataToUtf8String();
        // remove any escape characters (e.g. from Terraform
        requestJsonString = requestJsonString.replace("\\", "");
        logger.logInfoWithTracker(trackingId, String.format("Received payload: %s", requestJsonString));
        Operation operation = gson.fromJson(requestJsonString, Operation.class);
        trackingId = operation.getTrackingId();
        logger.logInfoWithTracker(trackingId, String.format("Parsed Request: %s", operation.toString()));
        dlpService = new DlpServiceImpl();
        bqService = new BigQueryServiceImpl();
        Inspector inspector = new Inspector(environment.toConfig(), dlpService, bqService, new GCSPersistentSetImpl(environment.getGcsFlagsBucket()), "inspector-flags");
        inspector.execute(operation, trackingId, requestBody.getMessage().getMessageId());
        return new ResponseEntity("Process completed successfully.", HttpStatus.OK);
    } catch (Exception e) {
        return ControllerExceptionHelper.handleException(e, logger, trackingId);
    } finally {
        if (dlpService != null) {
            dlpService.shutDown();
        }
    }
}
Also used : DlpServiceImpl(com.google.cloud.pso.bq_pii_classifier.services.dlp.DlpServiceImpl) 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) NonRetryableApplicationException(com.google.cloud.pso.bq_pii_classifier.entities.NonRetryableApplicationException) Inspector(com.google.cloud.pso.bq_pii_classifier.functions.inspector.Inspector) Operation(com.google.cloud.pso.bq_pii_classifier.entities.Operation) GCSPersistentSetImpl(com.google.cloud.pso.bq_pii_classifier.services.set.GCSPersistentSetImpl) DlpService(com.google.cloud.pso.bq_pii_classifier.services.dlp.DlpService) 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 Inspector (com.google.cloud.pso.bq_pii_classifier.functions.inspector.Inspector)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 DlpService (com.google.cloud.pso.bq_pii_classifier.services.dlp.DlpService)1 DlpServiceImpl (com.google.cloud.pso.bq_pii_classifier.services.dlp.DlpServiceImpl)1 GCSPersistentSetImpl (com.google.cloud.pso.bq_pii_classifier.services.set.GCSPersistentSetImpl)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1