Skip to content

Commit

Permalink
feat(webapp): add go controller for errata endpoint
Browse files Browse the repository at this point in the history
RHINENG-13555
  • Loading branch information
Dugowitch committed Jan 17, 2025
1 parent 0dcf918 commit 7eb1e20
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions deploy/clowdapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ objects:
value: ${NEWER_RELEASEVER_CSAF}
- name: ENABLE_GO_CVES
value: ${ENABLE_GO_CVES}
- name: ENABLE_GO_ERRATA
value: ${ENABLE_GO_ERRATA}
resources:
limits:
cpu: ${CPU_LIMIT_WEBAPP_GO}
Expand Down Expand Up @@ -499,3 +501,6 @@ parameters:
- name: ENABLE_GO_CVES
description: Enable go implementation of the cves endpoint
value: "false"
- name: ENABLE_GO_ERRATA
description: Enable go implementation of the errata endpoint
value: "false"
2 changes: 2 additions & 0 deletions vmaas-go/base/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Config struct {
CacheRefreshInterval time.Duration
EnableProfiler bool
EnableGoCves bool
EnableGoErrata bool

// lib
UnfixedEvalEnabled bool
Expand Down Expand Up @@ -136,6 +137,7 @@ func initEnv() {
Cfg.NewerReleaseverRepos = GetBoolEnvOrDefault("NEWER_RELEASEVER_REPOS", true)
Cfg.NewerReleaseverCsaf = GetBoolEnvOrDefault("NEWER_RELEASEVER_CSAF", true)
Cfg.EnableGoCves = GetBoolEnvOrDefault("ENABLE_GO_CVES", false)
Cfg.EnableGoErrata = GetBoolEnvOrDefault("ENABLE_GO_ERRATA", false)
}

func (e *Endpoint) BuildURL(scheme string) string {
Expand Down
44 changes: 44 additions & 0 deletions vmaas-go/webapp/controllers/errata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 ErrataHandler(c *gin.Context) {
if !isCacheLoaded(c) {
return
}
erratum := c.Param("erratum")
req := vmaas.ErrataRequest{Errata: []string{erratum}}

res, err := core.VmaasAPI.Errata(&req)
if err != nil {
utils.LogAndRespError(c, err)
return
}
c.JSON(http.StatusOK, res)
}

func ErrataPostHandler(c *gin.Context) {
if !isCacheLoaded(c) {
return
}
req := vmaas.ErrataRequest{}
err := bindValidateJSON(c, &req)
if err != nil {
utils.LogAndRespBadRequest(c, err)
return
}

errata, err := core.VmaasAPI.Errata(&req)
if err != nil {
utils.LogAndRespError(c, err)
return
}
c.JSON(http.StatusOK, errata)
}
4 changes: 4 additions & 0 deletions vmaas-go/webapp/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ func InitAPI(api *gin.RouterGroup) {
api.GET("/cves/:cve", controllers.CvesHandler)
api.POST("/cves", controllers.CvesPostHandler)
}
if utils.Cfg.EnableGoErrata {
api.GET("/errata/:erratum", controllers.ErrataHandler)
api.POST("/errata", controllers.ErrataPostHandler)
}
}

0 comments on commit 7eb1e20

Please sign in to comment.