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 Jan 20, 2025
1 parent fa8b021 commit 85d5578
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
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_PACKAGES
value: ${ENABLE_GO_PACKAGES}
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_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 @@ -46,6 +46,7 @@ type Config struct {
CacheRefreshInterval time.Duration
EnableProfiler bool
EnableGoCves bool
EnableGoPackages 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.EnableGoPackages = GetBoolEnvOrDefault("ENABLE_GO_PACKAGES", false)
}

func (e *Endpoint) BuildURL(scheme string) string {
Expand Down
46 changes: 46 additions & 0 deletions vmaas-go/webapp/controllers/packages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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)

// TODO: bump up vmaas-lib version after it's merged:
}

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

pkgs, err := core.VmaasAPI.Packages(&req)
if err != nil {
utils.LogAndRespError(c, err)
return
}
c.JSON(http.StatusOK, pkgs)
}
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.EnableGoPackages {
api.GET("/packages/:package", controllers.PackagesHandler)
api.POST("/packages", controllers.PackagesPostHandler)
}
}

0 comments on commit 85d5578

Please sign in to comment.