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 23, 2025
1 parent 6f6c216 commit ea1011c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion vmaas-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/prometheus/client_golang v1.20.5
github.com/redhatinsights/app-common-go v1.6.8
github.com/redhatinsights/platform-go-middlewares v1.0.0
github.com/redhatinsights/vmaas-lib v1.14.7-0.20250110172305-47fcde3ab5ec
github.com/redhatinsights/vmaas-lib v1.14.7
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.10.0
github.com/zsais/go-gin-prometheus v0.1.0
Expand Down
2 changes: 2 additions & 0 deletions vmaas-go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ github.com/redhatinsights/platform-go-middlewares v1.0.0 h1:OxyiYt+VmNo+UucK/ey0
github.com/redhatinsights/platform-go-middlewares v1.0.0/go.mod h1:dRH6XOjiZDbw8STvk6NNC7mMwqhTaV7X+1tn1oXOs24=
github.com/redhatinsights/vmaas-lib v1.14.7-0.20250110172305-47fcde3ab5ec h1:zPmL4fay1/v7Vv3BP3r/qmhiMZn+2ThfKDElJ1nQdRY=
github.com/redhatinsights/vmaas-lib v1.14.7-0.20250110172305-47fcde3ab5ec/go.mod h1:3jRU3URLLzBTdBfdN2Dn0eK+sCoAW4MJvD40rD2xKkk=
github.com/redhatinsights/vmaas-lib v1.14.7 h1:EwFa6M+sNjRQ/SD48wEkvMZnXiMdzvQnIoG8kYo3h9E=
github.com/redhatinsights/vmaas-lib v1.14.7/go.mod h1:3jRU3URLLzBTdBfdN2Dn0eK+sCoAW4MJvD40rD2xKkk=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
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 ea1011c

Please sign in to comment.