mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-04-07 11:17:36 +00:00
* Implemented validation rules, based on: https://up9.atlassian.net/browse/TRA-3349 * Color on Entry based on rules * Background red/green based on rules * Change flag --validation-rules to --test-rules * rules tab UI updated * rules tab font and background-color is changed for objects * Merged with develop * Fixed compilation issues. * Renamed fullEntry -> harEntry where appropriate. * Change green/red logic * Update models.go * Fix latency bug and alignment * Merge Conflicts fix * Working after merge * Working on Nimrod comments * Resolving conflicts * Resolving conflicts * Resolving conflicts * Nimrod Comments pt.3 * Log Error on configmap creation if the user doesn't have permission. * Checking configmap permission to ignore --test-rules * Revert time for mizu to get ready * Nimrod comments pt 4 && merge develop pt3 * Nimrod comments pt 4 && merge develop pt3 * Const rulePolicyPath and filename Co-authored-by: Neim <elezin9@gmail.com> Co-authored-by: nimrod-up9 <nimrod@up9.com>
94 lines
2.4 KiB
Go
94 lines
2.4 KiB
Go
package mizu
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/url"
|
|
"time"
|
|
|
|
"github.com/google/go-github/v37/github"
|
|
"github.com/up9inc/mizu/cli/uiUtils"
|
|
"github.com/up9inc/mizu/shared"
|
|
"github.com/up9inc/mizu/shared/semver"
|
|
)
|
|
|
|
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{}
|
|
if err := json.NewDecoder(statusResp.Body).Decode(&versionResponse); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return versionResponse.SemVer, nil
|
|
}
|
|
|
|
func CheckVersionCompatibility(port uint16) (bool, error) {
|
|
apiSemVer, err := getApiVersion(port)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
if semver.SemVersion(apiSemVer).Major() == semver.SemVersion(SemVer).Major() &&
|
|
semver.SemVersion(apiSemVer).Minor() == semver.SemVersion(SemVer).Minor() {
|
|
return true, nil
|
|
}
|
|
|
|
Log.Infof(uiUtils.Red, fmt.Sprintf("cli version (%s) is not compatible with api version (%s)", SemVer, apiSemVer))
|
|
return false, nil
|
|
}
|
|
|
|
func CheckNewerVersion() {
|
|
Log.Debugf("Checking for newer version...")
|
|
start := time.Now()
|
|
client := github.NewClient(nil)
|
|
latestRelease, _, err := client.Repositories.GetLatestRelease(context.Background(), "up9inc", "mizu")
|
|
if err != nil {
|
|
Log.Debugf("[ERROR] Failed to get latest release")
|
|
return
|
|
}
|
|
|
|
versionFileUrl := ""
|
|
for _, asset := range latestRelease.Assets {
|
|
if *asset.Name == "version.txt" {
|
|
versionFileUrl = *asset.BrowserDownloadURL
|
|
break
|
|
}
|
|
}
|
|
if versionFileUrl == "" {
|
|
Log.Debugf("[ERROR] Version file not found in the latest release")
|
|
return
|
|
}
|
|
|
|
res, err := http.Get(versionFileUrl)
|
|
if err != nil {
|
|
Log.Debugf("[ERROR] Failed to get the version file %v", err)
|
|
return
|
|
}
|
|
|
|
data, err := ioutil.ReadAll(res.Body)
|
|
res.Body.Close()
|
|
if err != nil {
|
|
Log.Debugf("[ERROR] Failed to read the version file -> %v", err)
|
|
return
|
|
}
|
|
gitHubVersion := string(data)
|
|
gitHubVersion = gitHubVersion[:len(gitHubVersion)-1]
|
|
Log.Debugf("Finished version validation, took %v", time.Since(start))
|
|
if SemVer < gitHubVersion {
|
|
Log.Infof(uiUtils.Yellow, fmt.Sprintf("Update available! %v -> %v (%v)", SemVer, gitHubVersion, *latestRelease.HTMLURL))
|
|
}
|
|
}
|