diff --git a/src/main/java/com/gepardec/mega/rest/api/MailResource.java b/src/main/java/com/gepardec/mega/rest/api/MailResource.java index 6b061c36..84ff2bb7 100644 --- a/src/main/java/com/gepardec/mega/rest/api/MailResource.java +++ b/src/main/java/com/gepardec/mega/rest/api/MailResource.java @@ -2,7 +2,6 @@ import io.quarkus.oidc.Tenant; import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; @@ -49,17 +48,6 @@ public interface MailResource { @Path("/retrieve-zep-mails") Response retrieveZepEmailsFromInbox(); - /** - * This endpoint serves as a webhook for new emails from ZEP to trigger comment creation. - * A Google Cloud Pub/Sub subscription is set up to call this endpoint when a new email is received. - * - * @return - */ - @Operation(operationId = "gmailMessageReceivedWebhook", description = "Webhook for new emails from ZEP to trigger comment creation.") - @POST - @Path("/message-received") - Response gmailMessageReceivedWebhook(String payload); - @Path("/ping") @GET LocalDateTime ping(); diff --git a/src/main/java/com/gepardec/mega/rest/api/PubSubResource.java b/src/main/java/com/gepardec/mega/rest/api/PubSubResource.java new file mode 100644 index 00000000..e6f5936f --- /dev/null +++ b/src/main/java/com/gepardec/mega/rest/api/PubSubResource.java @@ -0,0 +1,29 @@ +package com.gepardec.mega.rest.api; + +import io.quarkus.oidc.Tenant; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Response; +import org.eclipse.microprofile.openapi.annotations.Operation; + +import java.time.LocalDateTime; + +@Tenant("pubsub") +@Path("/pubsub") +public interface PubSubResource { + + /** + * This endpoint serves as a webhook for new emails from ZEP to trigger comment creation. + * A Google Cloud Pub/Sub subscription is set up to call this endpoint when a new email is received. + * + * @return + */ + @Operation(operationId = "gmailMessageReceivedWebhook", description = "Webhook for new emails from ZEP to trigger comment creation.") + @POST + @Path("/message-received") + Response gmailMessageReceivedWebhook(String payload); + + @Path("/ping") + @POST + LocalDateTime ping(String payload); +} diff --git a/src/main/java/com/gepardec/mega/rest/impl/MailResourceImpl.java b/src/main/java/com/gepardec/mega/rest/impl/MailResourceImpl.java index 99b09f9b..fa2f3144 100644 --- a/src/main/java/com/gepardec/mega/rest/impl/MailResourceImpl.java +++ b/src/main/java/com/gepardec/mega/rest/impl/MailResourceImpl.java @@ -48,19 +48,6 @@ public Response retrieveZepEmailsFromInbox() { return Response.ok().build(); } - @Override - public Response gmailMessageReceivedWebhook(String payload) { - try { - logger.info("Received payload: {}", payload); - mailReceiver.retrieveZepEmailsFromInbox(); - } catch (Exception e) { - logger.error(e.getMessage()); - return Response.serverError().entity(e.getMessage()).build(); - } - - return Response.ok().build(); - } - @Override public LocalDateTime ping() { return LocalDateTime.now(); diff --git a/src/main/java/com/gepardec/mega/rest/impl/PubSubResourceImpl.java b/src/main/java/com/gepardec/mega/rest/impl/PubSubResourceImpl.java new file mode 100644 index 00000000..dcaecb9d --- /dev/null +++ b/src/main/java/com/gepardec/mega/rest/impl/PubSubResourceImpl.java @@ -0,0 +1,39 @@ +package com.gepardec.mega.rest.impl; + +import com.gepardec.mega.notification.mail.receiver.MailReceiver; +import com.gepardec.mega.rest.api.PubSubResource; +import io.quarkus.security.Authenticated; +import jakarta.inject.Inject; +import jakarta.ws.rs.core.Response; +import org.slf4j.Logger; + +import java.time.LocalDateTime; + +@Authenticated +public class PubSubResourceImpl implements PubSubResource { + + @Inject + Logger logger; + + @Inject + MailReceiver mailReceiver; + + @Override + public Response gmailMessageReceivedWebhook(String payload) { + try { + logger.info("Received notification from Pub/Sub: {}", payload); + mailReceiver.retrieveZepEmailsFromInbox(); + } catch (Exception e) { + logger.error(e.getMessage()); + return Response.serverError().entity(e.getMessage()).build(); + } + + return Response.ok().build(); + } + + @Override + public LocalDateTime ping(String payload) { + logger.info("Received notification from Pub/Sub: {}", payload); + return LocalDateTime.now(); + } +} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index fb7375fd..f18aa263 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -102,6 +102,12 @@ quarkus: roles: source: accesstoken role-claim-path: "resource_access/mega-cron/roles" + pubsub: + provider: google + application-type: "service" + token: + verify-access-token-with-user-info: false + mp: openapi: filter: com.gepardec.mega.application.filter.MegaCronSecuritySchemaOASFilter