Skip to content

Commit

Permalink
feat(webapp): add go controller for packages endpoint
Browse files Browse the repository at this point in the history
RHINENG-13557
  • Loading branch information
Dugowitch committed Feb 12, 2025
1 parent f2b1530 commit 84d7e68
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
5 changes: 5 additions & 0 deletions deploy/clowdapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ objects:
value: ${ENABLE_GO_ERRATA}
- name: ENABLE_GO_REPOS
value: ${ENABLE_GO_REPOS}
- name: ENABLE_GO_PACKAGES
value: ${ENABLE_GO_PACKAGES}
resources:
limits:
cpu: ${CPU_LIMIT_WEBAPP_GO}
Expand Down Expand Up @@ -509,3 +511,6 @@ parameters:
- name: ENABLE_GO_REPOS
description: Enable go implementation of the repos endpoint
value: "false"
- name: ENABLE_GO_PACKAGES
description: Enable go implementation of the packages 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 @@ -48,6 +48,7 @@ type Config struct {
EnableGoCves bool
EnableGoErrata bool
EnableGoRepos bool
EnableGoPackages bool

// lib
UnfixedEvalEnabled bool
Expand Down Expand Up @@ -140,6 +141,7 @@ func initEnv() {
Cfg.EnableGoCves = GetBoolEnvOrDefault("ENABLE_GO_CVES", false)
Cfg.EnableGoErrata = GetBoolEnvOrDefault("ENABLE_GO_ERRATA", false)
Cfg.EnableGoRepos = GetBoolEnvOrDefault("ENABLE_GO_REPOS", false)
Cfg.EnableGoPackages = GetBoolEnvOrDefault("ENABLE_GO_PACKAGES", 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.17.0
github.com/redhatinsights/vmaas-lib v1.18.0
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
4 changes: 2 additions & 2 deletions vmaas-go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ github.com/redhatinsights/app-common-go v1.6.8 h1:hyExMp6WHprlGkHKElQvSFF2ZPX8XT
github.com/redhatinsights/app-common-go v1.6.8/go.mod h1:KW0BK+bnhp3kXU8BFwebQXqCqjdkcRewZsDlXCSNMyo=
github.com/redhatinsights/platform-go-middlewares v1.0.0 h1:OxyiYt+VmNo+UucK/ey0b6UDFnpCni6JoGPeisGmmNI=
github.com/redhatinsights/platform-go-middlewares v1.0.0/go.mod h1:dRH6XOjiZDbw8STvk6NNC7mMwqhTaV7X+1tn1oXOs24=
github.com/redhatinsights/vmaas-lib v1.17.0 h1:sc+4i9FazjSNFKuSHQ0tfPDW+qzQ3GX4kPAcmBR7IuY=
github.com/redhatinsights/vmaas-lib v1.17.0/go.mod h1:3jRU3URLLzBTdBfdN2Dn0eK+sCoAW4MJvD40rD2xKkk=
github.com/redhatinsights/vmaas-lib v1.18.0 h1:dwGbSWVP/bXdptbL07XxW4J1DETD/5b7l2j/A+fANo8=
github.com/redhatinsights/vmaas-lib v1.18.0/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/packages.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 PackagesHandler(c *gin.Context) {
if !isCacheLoaded(c) {
return
}
pkg := c.Param("package")
req := vmaas.PackagesRequest{Packages: []string{pkg}}

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

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

res, err := core.VmaasAPI.Packages(&req)
if err != nil {
utils.LogAndRespError(c, err)
return
}
c.JSON(http.StatusOK, res)
}
4 changes: 4 additions & 0 deletions vmaas-go/webapp/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ func InitAPI(api *gin.RouterGroup) {
api.GET("/repos/:repo", controllers.ReposHandler)
api.POST("/repos", controllers.ReposPostHandler)
}
if utils.Cfg.EnableGoPackages {
api.GET("/packages/:package", controllers.PackagesHandler)
api.POST("/packages", controllers.PackagesPostHandler)
}
api.GET("/os/vulnerability/report", controllers.OSHandler)
}

0 comments on commit 84d7e68

Please sign in to comment.