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 packages endpoint #1233

Merged
merged 2 commits into from
Feb 18, 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 @@ -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: 1 addition & 1 deletion vmaas-go/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ linters:
- lll # Reports long lines [fast: true, auto-fix: false]
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
- prealloc # Finds slice declarations that could potentially be preallocated [fast: true, auto-fix: false]
- exportloopref # checks for pointers to enclosing loop variables [fast: false, auto-fix: false]
- copyloopvar # detects places where loop variables are copied [fast: false, auto-fix: false]
- stylecheck # Stylecheck is a replacement for golint [fast: true, auto-fix: false]
- unconvert # Remove unnecessary type conversions [fast: true, auto-fix: false]
- unparam # Reports unused function parameters [fast: true, auto-fix: false]
Expand Down
4 changes: 2 additions & 2 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 @@ -99,7 +100,6 @@ func initAPI() {

func initEndpoints() {
for _, e := range clowder.LoadedConfig.Endpoints {
e := e // re-assign iteration variable to use a new memory pointer
if e.App == "vmaas" {
switch {
case strings.Contains(e.Name, "reposcan"):
Expand All @@ -110,7 +110,6 @@ func initEndpoints() {
}
}
for _, e := range clowder.LoadedConfig.PrivateEndpoints {
e := e // re-assign iteration variable to use a new memory pointer
if e.App == "vmaas" && strings.Contains(e.Name, "reposcan") {
Cfg.DumpAddress = fmt.Sprintf("%s/vmaas.db", (*PrivateEndpoint)(&e).BuildURL("http"))
}
Expand Down Expand Up @@ -140,6 +139,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("nevra")
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/:nevra", controllers.PackagesHandler)
api.POST("/packages", controllers.PackagesPostHandler)
}
api.GET("/os/vulnerability/report", controllers.OSHandler)
}
Loading