generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PAGOPA-1446] feat: subscription validation event handling
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/it/gov/pagopa/gpd/upload/BlobEventFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package it.gov.pagopa.gpd.upload; | ||
|
||
import com.azure.core.util.BinaryData; | ||
import com.azure.messaging.eventgrid.EventGridEvent; | ||
import com.azure.messaging.eventgrid.systemevents.SubscriptionValidationEventData; | ||
import com.microsoft.azure.functions.*; | ||
import com.microsoft.azure.functions.annotation.AuthorizationLevel; | ||
import com.microsoft.azure.functions.annotation.FunctionName; | ||
import com.microsoft.azure.functions.annotation.HttpTrigger; | ||
|
||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class BlobEventFunction { | ||
|
||
@FunctionName("BlobCreatedSubscriber") | ||
public HttpResponseMessage run ( | ||
@HttpTrigger(name = "BlobCreatedSubscriber", | ||
methods = {HttpMethod.POST, HttpMethod.GET}, | ||
route = "upload", | ||
authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage request, | ||
final ExecutionContext context) { | ||
BinaryData events = BinaryData.fromString(String.valueOf(request.getBody())); | ||
Logger logger = context.getLogger(); | ||
logger.log(Level.INFO, () -> "Request body: " + request.getBody()); | ||
logger.log(Level.INFO, () -> "Events: " + events); | ||
|
||
List<EventGridEvent> eventGridEvents = EventGridEvent.fromString(events.toString()); | ||
|
||
for (EventGridEvent eventGridEvent : eventGridEvents) { | ||
if(eventGridEvent.getEventType().equals("SubscriptionValidationEventData")){ | ||
SubscriptionValidationEventData s = SubscriptionValidationEventData.class.cast(eventGridEvent); | ||
return request.createResponseBuilder(HttpStatus.OK) | ||
.header("Content-Type", "application/json") | ||
.body(s.getValidationCode()) | ||
.build(); | ||
} | ||
} | ||
return request.createResponseBuilder(HttpStatus.NOT_FOUND) | ||
.build(); | ||
} | ||
} |