From 702123d4c87afe1767ffbcc4f6a6663e241f1e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Dugovi=C4=8D?= Date: Tue, 26 Nov 2024 12:40:30 +0100 Subject: [PATCH] feat(webapp): add go controller for repos endpoint RHINENG-13556 --- deploy/clowdapp.yaml | 5 +++ vmaas-go/base/utils/config.go | 2 ++ vmaas-go/webapp/controllers/repos.go | 46 ++++++++++++++++++++++++++++ vmaas-go/webapp/routes/routes.go | 4 +++ 4 files changed, 57 insertions(+) create mode 100644 vmaas-go/webapp/controllers/repos.go diff --git a/deploy/clowdapp.yaml b/deploy/clowdapp.yaml index 92a998d6..4ce148e6 100644 --- a/deploy/clowdapp.yaml +++ b/deploy/clowdapp.yaml @@ -55,6 +55,8 @@ objects: value: ${ENABLE_GO_CVES} - name: ENABLE_GO_ERRATA value: ${ENABLE_GO_ERRATA} + - name: ENABLE_GO_REPOS + value: ${ENABLE_GO_REPOS} resources: limits: cpu: ${CPU_LIMIT_WEBAPP_GO} @@ -504,3 +506,6 @@ parameters: - name: ENABLE_GO_ERRATA description: Enable go implementation of the errata endpoint value: "false" +- name: ENABLE_GO_REPOS + description: Enable go implementation of the repos endpoint + value: "false" diff --git a/vmaas-go/base/utils/config.go b/vmaas-go/base/utils/config.go index ff4be7f1..9969c2ab 100644 --- a/vmaas-go/base/utils/config.go +++ b/vmaas-go/base/utils/config.go @@ -47,6 +47,7 @@ type Config struct { EnableProfiler bool EnableGoCves bool EnableGoErrata bool + EnableGoRepos bool // lib UnfixedEvalEnabled bool @@ -138,6 +139,7 @@ func initEnv() { Cfg.NewerReleaseverCsaf = GetBoolEnvOrDefault("NEWER_RELEASEVER_CSAF", true) Cfg.EnableGoCves = GetBoolEnvOrDefault("ENABLE_GO_CVES", false) Cfg.EnableGoErrata = GetBoolEnvOrDefault("ENABLE_GO_ERRATA", false) + Cfg.EnableGoRepos = GetBoolEnvOrDefault("ENABLE_GO_REPOS", false) } func (e *Endpoint) BuildURL(scheme string) string { diff --git a/vmaas-go/webapp/controllers/repos.go b/vmaas-go/webapp/controllers/repos.go new file mode 100644 index 00000000..e7a279a4 --- /dev/null +++ b/vmaas-go/webapp/controllers/repos.go @@ -0,0 +1,46 @@ +package controllers + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/redhatinsights/vmaas-lib/vmaas" + "github.com/redhatinsights/vmaas/base/core" + "github.com/redhatinsights/vmaas/base/utils" +) + +func ReposHandler(c *gin.Context) { + if !isCacheLoaded(c) { + return + } + repo := c.Param("repo") + req := vmaas.ReposRequest{Repos: []string{repo}} + + res, err := core.VmaasAPI.Repos(&req) + if err != nil { + utils.LogAndRespError(c, err) + return + } + c.JSON(http.StatusOK, res) + + // TODO: up vmaas-lib version after it's merged +} + +func ReposPostHandler(c *gin.Context) { + if !isCacheLoaded(c) { + return + } + req := vmaas.ReposRequest{} + err := bindValidateJSON(c, &req) + if err != nil { + utils.LogAndRespBadRequest(c, err) + return + } + + repos, err := core.VmaasAPI.Repos(&req) + if err != nil { + utils.LogAndRespError(c, err) + return + } + c.JSON(http.StatusOK, repos) +} diff --git a/vmaas-go/webapp/routes/routes.go b/vmaas-go/webapp/routes/routes.go index c4a8473a..c512d04a 100644 --- a/vmaas-go/webapp/routes/routes.go +++ b/vmaas-go/webapp/routes/routes.go @@ -22,4 +22,8 @@ func InitAPI(api *gin.RouterGroup) { api.GET("/errata/:erratum", controllers.ErrataHandler) api.POST("/errata", controllers.ErrataPostHandler) } + if utils.Cfg.EnableGoRepos { + api.GET("/repos/:repo", controllers.ReposHandler) + api.POST("/repos", controllers.ReposPostHandler) + } }