mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48:04 +00:00
* List supported resources for scanners * Don't warn on scanner discovery commands * Use scanner-to-resource map * Save changes * Scan result tabs * Own table render for Checkov * Scannable manifest flag for scanners
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package handlers
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/komodorio/helm-dashboard/pkg/dashboard/subproc"
|
|
"github.com/komodorio/helm-dashboard/pkg/dashboard/utils"
|
|
"net/http"
|
|
)
|
|
|
|
type ScannersHandler struct {
|
|
Data *subproc.DataLayer
|
|
}
|
|
|
|
func (h *ScannersHandler) List(c *gin.Context) {
|
|
type ScannerInfo struct {
|
|
SupportedResourceKinds []string
|
|
ManifestScannable bool
|
|
}
|
|
res := map[string]ScannerInfo{}
|
|
for _, scanner := range h.Data.Scanners {
|
|
res[scanner.Name()] = ScannerInfo{
|
|
SupportedResourceKinds: scanner.SupportedResourceKinds(),
|
|
ManifestScannable: scanner.ManifestIsScannable(),
|
|
}
|
|
}
|
|
c.IndentedJSON(http.StatusOK, res)
|
|
}
|
|
|
|
func (h *ScannersHandler) ScanDraftManifest(c *gin.Context) {
|
|
qp, err := utils.GetQueryProps(c, false)
|
|
if err != nil {
|
|
_ = c.AbortWithError(http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
|
|
reuseVals := c.Query("initial") != "true"
|
|
mnf, err := h.Data.ChartInstall(qp.Namespace, qp.Name, c.Query("chart"), c.Query("version"), true, c.PostForm("values"), reuseVals)
|
|
if err != nil {
|
|
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
|
|
reps := map[string]*subproc.ScanResults{}
|
|
for _, scanner := range h.Data.Scanners {
|
|
sr, err := scanner.ScanManifests(mnf)
|
|
if err != nil {
|
|
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
|
|
reps[scanner.Name()] = sr
|
|
}
|
|
|
|
c.IndentedJSON(http.StatusOK, reps)
|
|
}
|
|
|
|
func (h *ScannersHandler) ScanResource(c *gin.Context) {
|
|
qp, err := utils.GetQueryProps(c, false)
|
|
if err != nil {
|
|
_ = c.AbortWithError(http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
|
|
reps := map[string]*subproc.ScanResults{}
|
|
for _, scanner := range h.Data.Scanners {
|
|
sr, err := scanner.ScanResource(qp.Namespace, c.Param("kind"), qp.Name)
|
|
if err != nil {
|
|
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
|
|
reps[scanner.Name()] = sr
|
|
}
|
|
|
|
c.IndentedJSON(http.StatusOK, reps)
|
|
}
|