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 repos endpoint #1229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -55,6 +55,8 @@ objects:
value: ${ENABLE_GO_CVES}
- name: ENABLE_GO_ERRATA
value: ${ENABLE_GO_ERRATA}
- name: ENABLE_GO_REPOS
value: ${ENABLE_GO_REPOS}
resources:
limits:
cpu: ${CPU_LIMIT_WEBAPP_GO}
Expand Down Expand Up @@ -504,3 +506,6 @@ parameters:
- name: ENABLE_GO_ERRATA
description: Enable go implementation of the errata endpoint
value: "false"
- name: ENABLE_GO_REPOS
description: Enable go implementation of the repos 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 @@ -47,6 +47,7 @@ type Config struct {
EnableProfiler bool
EnableGoCves bool
EnableGoErrata bool
EnableGoRepos bool

// lib
UnfixedEvalEnabled bool
Expand Down Expand Up @@ -138,6 +139,7 @@ func initEnv() {
Cfg.NewerReleaseverCsaf = GetBoolEnvOrDefault("NEWER_RELEASEVER_CSAF", true)
Cfg.EnableGoCves = GetBoolEnvOrDefault("ENABLE_GO_CVES", false)
Cfg.EnableGoErrata = GetBoolEnvOrDefault("ENABLE_GO_ERRATA", false)
Cfg.EnableGoRepos = GetBoolEnvOrDefault("ENABLE_GO_REPOS", 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.16.0
github.com/redhatinsights/vmaas-lib v1.17.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.16.0 h1:T0oJxQBdd8gUoA3cg4/xiUDPbxiHluE8/WlMOUiqr2A=
github.com/redhatinsights/vmaas-lib v1.16.0/go.mod h1:3jRU3URLLzBTdBfdN2Dn0eK+sCoAW4MJvD40rD2xKkk=
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/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/repos.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 ReposHandler(c *gin.Context) {
if !isCacheLoaded(c) {
return
}
repo := c.Param("repo")
req := vmaas.ReposRequest{Repos: []string{repo}}

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

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

res, err := core.VmaasAPI.Repos(&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 @@ -22,5 +22,9 @@ func InitAPI(api *gin.RouterGroup) {
api.GET("/errata/:erratum", controllers.ErrataHandler)
api.POST("/errata", controllers.ErrataPostHandler)
}
if utils.Cfg.EnableGoRepos {
api.GET("/repos/:repo", controllers.ReposHandler)
api.POST("/repos", controllers.ReposPostHandler)
}
api.GET("/os/vulnerability/report", controllers.OSHandler)
}
Loading