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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
46 changes: 46 additions & 0 deletions vmaas-go/webapp/controllers/repos.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 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)

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

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

repos, err := core.VmaasAPI.Repos(&req)
if err != nil {
utils.LogAndRespError(c, err)
return
}
c.JSON(http.StatusOK, repos)
}
4 changes: 4 additions & 0 deletions vmaas-go/webapp/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"github.com/redhatinsights/vmaas/base/utils"
"github.com/redhatinsights/vmaas/webapp/controllers"

Check failure on line 7 in vmaas-go/webapp/routes/routes.go

View workflow job for this annotation

GitHub Actions / lint (1.22.x, ubuntu-latest)

could not import github.com/redhatinsights/vmaas/webapp/controllers (-: # github.com/redhatinsights/vmaas/webapp/controllers
)

func InitAPI(api *gin.RouterGroup) {
Expand All @@ -22,4 +22,8 @@
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)
}
}
Loading