Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webapp): add go controller for errata endpoint #1230

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading