mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-07-28 09:43:59 +00:00
no message
This commit is contained in:
@@ -2,13 +2,11 @@ package controllers
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/up9inc/mizu/shared"
|
||||
"mizuserver/pkg/version"
|
||||
)
|
||||
|
||||
type VersionResponse struct {
|
||||
SemVer string `json:"semver"`
|
||||
}
|
||||
|
||||
func GetVersion(c *fiber.Ctx) error {
|
||||
resp := VersionResponse{SemVer: "1.2.3"}
|
||||
resp := shared.VersionResponse{SemVer: version.SemVer}
|
||||
return c.Status(fiber.StatusOK).JSON(resp)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/up9inc/mizu/cli/mizu"
|
||||
)
|
||||
|
||||
type MizuFetchOptions struct {
|
||||
@@ -17,6 +18,9 @@ var fetchCmd = &cobra.Command{
|
||||
Use: "fetch",
|
||||
Short: "Download recorded traffic to files",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !mizu.CheckVersionCompatibility(mizuFetchOptions.MizuPort) {
|
||||
return nil
|
||||
}
|
||||
RunMizuFetch(&mizuFetchOptions)
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/up9inc/mizu/cli/mizu"
|
||||
)
|
||||
|
||||
type MizuViewOptions struct {
|
||||
@@ -14,9 +15,14 @@ var viewCmd = &cobra.Command{
|
||||
Use: "view",
|
||||
Short: "Open GUI in browser",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if !mizu.CheckVersionCompatibility(mizuFetchOptions.MizuPort) {
|
||||
return nil
|
||||
}
|
||||
runMizuView(mizuViewOptions)
|
||||
return nil
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
40
cli/mizu/versionCheck.go
Normal file
40
cli/mizu/versionCheck.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package mizu
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/up9inc/mizu/shared"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
|
||||
func getApiVersion(port uint16) (string, error) {
|
||||
versionUrl, _ := url.Parse(fmt.Sprintf("http://localhost:%d/mizu/metadata/version", port))
|
||||
req := &http.Request{
|
||||
Method: http.MethodGet,
|
||||
URL: versionUrl,
|
||||
}
|
||||
statusResp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer statusResp.Body.Close()
|
||||
|
||||
versionResponse := &shared.VersionResponse{}
|
||||
_ = json.NewDecoder(statusResp.Body).Decode(&versionResponse)
|
||||
|
||||
return versionResponse.SemVer, nil
|
||||
}
|
||||
|
||||
func CheckVersionCompatibility(port uint16) bool {
|
||||
apiSemVer, err := getApiVersion(port)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
if apiSemVer == SemVer {
|
||||
return true
|
||||
}
|
||||
fmt.Printf(Red, fmt.Sprintf("cli version (%s) is not compatible with api version (%s)\n", SemVer, apiSemVer))
|
||||
return false
|
||||
}
|
||||
@@ -61,3 +61,8 @@ type TrafficFilteringOptions struct {
|
||||
PlainTextMaskingRegexes []*SerializableRegexp
|
||||
HideHealthChecks bool
|
||||
}
|
||||
|
||||
type VersionResponse struct {
|
||||
SemVer string `json:"semver"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user