mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-07-27 01:03:34 +00:00
* Rename `mizu` to `kubeshark` * Rename `up9inc` to `kubeshark` * Change the logo, title, motto and the main color * Replace the favicon * Update the docs link * Change the copyright text in C files * Remove a comment * Rewrite the `README.md` and update the logo and screenshots used in it * Add a `TODO` * Fix the grammar * Fix the bottom text in the filtering guide * Change the Docker Hub username of cross-compilation intermediate images * Add an install script * Fix `docker/login-action` in the CI * Delete `build-custom-branch.yml` GitHub workflow * Update `README.md` * Remove `install.sh` * Change the motto back to "Traffic viewer for Kubernetes"
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/chanced/openapi"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/kubeshark/kubeshark/agent/pkg/dependency"
|
|
"github.com/kubeshark/kubeshark/agent/pkg/oas"
|
|
"github.com/kubeshark/kubeshark/logger"
|
|
)
|
|
|
|
func GetOASServers(c *gin.Context) {
|
|
m := make([]string, 0)
|
|
oasGenerator := dependency.GetInstance(dependency.OasGeneratorDependency).(oas.OasGenerator)
|
|
oasGenerator.GetServiceSpecs().Range(func(key, value interface{}) bool {
|
|
m = append(m, key.(string))
|
|
return true
|
|
})
|
|
|
|
c.JSON(http.StatusOK, m)
|
|
}
|
|
|
|
func GetOASSpec(c *gin.Context) {
|
|
oasGenerator := dependency.GetInstance(dependency.OasGeneratorDependency).(oas.OasGenerator)
|
|
res, ok := oasGenerator.GetServiceSpecs().Load(c.Param("id"))
|
|
if !ok {
|
|
c.JSON(http.StatusNotFound, gin.H{
|
|
"error": true,
|
|
"type": "error",
|
|
"autoClose": "5000",
|
|
"msg": "Service not found among specs",
|
|
})
|
|
return // exit
|
|
}
|
|
|
|
gen := res.(*oas.SpecGen)
|
|
spec, err := gen.GetSpec()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"error": true,
|
|
"type": "error",
|
|
"autoClose": "5000",
|
|
"msg": err,
|
|
})
|
|
return // exit
|
|
}
|
|
|
|
c.JSON(http.StatusOK, spec)
|
|
}
|
|
|
|
func GetOASAllSpecs(c *gin.Context) {
|
|
res := map[string]*openapi.OpenAPI{}
|
|
|
|
oasGenerator := dependency.GetInstance(dependency.OasGeneratorDependency).(oas.OasGenerator)
|
|
oasGenerator.GetServiceSpecs().Range(func(key, value interface{}) bool {
|
|
svc := key.(string)
|
|
gen := value.(*oas.SpecGen)
|
|
spec, err := gen.GetSpec()
|
|
if err != nil {
|
|
logger.Log.Warningf("Failed to obtain spec for service %s: %s", svc, err)
|
|
return true
|
|
}
|
|
res[svc] = spec
|
|
return true
|
|
})
|
|
c.JSON(http.StatusOK, res)
|
|
}
|