Skip to content

Commit

Permalink
[Gepardec/mega#735] Add OIDC config for pubsub (service account)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ollitod committed Sep 24, 2024
1 parent 8afd6b1 commit acbcb75
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 25 deletions.
12 changes: 0 additions & 12 deletions src/main/java/com/gepardec/mega/rest/api/MailResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/gepardec/mega/rest/api/PubSubResource.java
Original file line number Diff line number Diff line change
@@ -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);
}
13 changes: 0 additions & 13 deletions src/main/java/com/gepardec/mega/rest/impl/MailResourceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/gepardec/mega/rest/impl/PubSubResourceImpl.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
6 changes: 6 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit acbcb75

Please sign in to comment.