mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-07-07 07:30:12 +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"
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/kubeshark/kubeshark/agent/pkg/dependency"
|
|
"github.com/kubeshark/kubeshark/agent/pkg/entries"
|
|
"github.com/kubeshark/kubeshark/agent/pkg/models"
|
|
"github.com/kubeshark/kubeshark/agent/pkg/validation"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/kubeshark/kubeshark/logger"
|
|
)
|
|
|
|
func HandleEntriesError(c *gin.Context, err error) bool {
|
|
if err != nil {
|
|
logger.Log.Errorf("Error getting entry: %v", err)
|
|
_ = c.Error(err)
|
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
|
|
"error": true,
|
|
"type": "error",
|
|
"autoClose": "5000",
|
|
"msg": err.Error(),
|
|
})
|
|
return true // signal that there was an error and the caller should return
|
|
}
|
|
return false // no error, can continue
|
|
}
|
|
|
|
func GetEntries(c *gin.Context) {
|
|
entriesRequest := &models.EntriesRequest{}
|
|
|
|
if err := c.BindQuery(entriesRequest); err != nil {
|
|
c.JSON(http.StatusBadRequest, err)
|
|
}
|
|
validationError := validation.Validate(entriesRequest)
|
|
if validationError != nil {
|
|
c.JSON(http.StatusBadRequest, validationError)
|
|
}
|
|
|
|
if entriesRequest.TimeoutMs == 0 {
|
|
entriesRequest.TimeoutMs = 3000
|
|
}
|
|
|
|
entriesProvider := dependency.GetInstance(dependency.EntriesProvider).(entries.EntriesProvider)
|
|
entryWrappers, metadata, err := entriesProvider.GetEntries(entriesRequest)
|
|
if !HandleEntriesError(c, err) {
|
|
baseEntries := make([]interface{}, 0)
|
|
for _, entry := range entryWrappers {
|
|
baseEntries = append(baseEntries, entry.Base)
|
|
}
|
|
c.JSON(http.StatusOK, models.EntriesResponse{
|
|
Data: baseEntries,
|
|
Meta: metadata,
|
|
})
|
|
}
|
|
}
|
|
|
|
func GetEntry(c *gin.Context) {
|
|
singleEntryRequest := &models.SingleEntryRequest{}
|
|
|
|
if err := c.BindQuery(singleEntryRequest); err != nil {
|
|
c.JSON(http.StatusBadRequest, err)
|
|
}
|
|
validationError := validation.Validate(singleEntryRequest)
|
|
if validationError != nil {
|
|
c.JSON(http.StatusBadRequest, validationError)
|
|
}
|
|
|
|
id := c.Param("id")
|
|
|
|
entriesProvider := dependency.GetInstance(dependency.EntriesProvider).(entries.EntriesProvider)
|
|
entry, err := entriesProvider.GetEntry(singleEntryRequest, id)
|
|
|
|
if !HandleEntriesError(c, err) {
|
|
c.JSON(http.StatusOK, entry)
|
|
}
|
|
}
|