-
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] temp commit authentication
- Loading branch information
Showing
5 changed files
with
90 additions
and
68 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
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
package com.gepardec.mega.rest.api; | ||
|
||
import io.quarkus.oidc.Tenant; | ||
import io.quarkus.security.Authenticated; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
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 postPing(@Context HttpHeaders headers); | ||
} |
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
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
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.HttpHeaders; | ||
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 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 postPing(HttpHeaders httpHeaders) { | ||
logger.info("Received POST request"); | ||
logger.info("Headers: {}", httpHeaders.getRequestHeaders()); | ||
|
||
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