From 86f1656d9bb08b47bb971d27aaccee104d655ee0 Mon Sep 17 00:00:00 2001 From: Graza Date: Wed, 21 Feb 2024 21:19:54 +0000 Subject: [PATCH] fix: remediated integration url generation & GET handling (#696) --- internal/service/api/webhook.go | 6 +++++- internal/service/manager/manager.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/service/api/webhook.go b/internal/service/api/webhook.go index 860258ae..344cc384 100644 --- a/internal/service/api/webhook.go +++ b/internal/service/api/webhook.go @@ -39,7 +39,7 @@ import ( func (api *APIService) WebhookRegisterAPI(router *gin.RouterGroup) { router.POST("/hook/:hook/:hash", api.passHookToProcessor) - router.GET("/hook/:hook/:hash", api.runTriggerHook) + router.GET("/hook/:hook/:hash", api.passHookToProcessor) } type JSONPayload struct { @@ -101,6 +101,10 @@ func (api *APIService) passHookToProcessor(c *gin.Context) { case len(nameParts) >= 2 && (nameParts[0] == "trigger" || nameParts[1] == "trigger"): api.runTriggerHook(c) case len(nameParts) >= 2 && nameParts[0] == "integration": + if c.Request.Method != http.MethodPost { + common.AbortWithError(c, perr.MethodNotAllowed()) + return + } api.runIntegrationHook(c) default: common.AbortWithError(c, perr.NotFoundWithMessage(fmt.Sprintf("Not Found %s", webhookUri.Hook))) diff --git a/internal/service/manager/manager.go b/internal/service/manager/manager.go index b91ac8f9..f1f97a32 100644 --- a/internal/service/manager/manager.go +++ b/internal/service/manager/manager.go @@ -529,7 +529,7 @@ func integrationUrlProcessor(integration modconfig.Integration) error { integrationName := fmt.Sprintf("integration.%s", integration.GetHclResourceImpl().FullName) hashString := util.CalculateHash(integrationName, salt) - integrationUrl := fmt.Sprintf("%s/hook/%s/%s", util.GetBaseUrl(), integrationName, hashString) + integrationUrl := fmt.Sprintf("%s/api/latest/hook/%s/%s", util.GetBaseUrl(), integrationName, hashString) integration.SetUrl(integrationUrl) } return nil