-
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.
[Gepardec/mega#735] Add OIDC config for pubsub (service account)
- Loading branch information
Showing
5 changed files
with
74 additions
and
25 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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/gepardec/mega/rest/api/PubSubResource.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,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); | ||
} |
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/gepardec/mega/rest/impl/PubSubResourceImpl.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,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(); | ||
} | ||
} |
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