mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-02 03:00:41 +00:00
small changes
This commit is contained in:
@@ -168,10 +168,10 @@ func uploadEntriesImpl(token string, model string, envPrefix string) {
|
|||||||
_ = w.Close()
|
_ = w.Close()
|
||||||
reqBody := ioutil.NopCloser(bytes.NewReader(in.Bytes()))
|
reqBody := ioutil.NopCloser(bytes.NewReader(in.Bytes()))
|
||||||
|
|
||||||
postUrl, _ := url.Parse("https://traffic." + envPrefix + "/dumpTrafficBulk/" + model)
|
postUrl, _ := url.Parse(fmt.Sprintf("https://traffic.%s/dumpTrafficBulk/%s", envPrefix, model))
|
||||||
fmt.Println(postUrl)
|
fmt.Println(postUrl)
|
||||||
req := &http.Request{
|
req := &http.Request{
|
||||||
Method: "POST",
|
Method: http.MethodPost,
|
||||||
URL: postUrl,
|
URL: postUrl,
|
||||||
Header: map[string][]string{
|
Header: map[string][]string{
|
||||||
"Content-Encoding": {"deflate"},
|
"Content-Encoding": {"deflate"},
|
||||||
@@ -184,7 +184,6 @@ func uploadEntriesImpl(token string, model string, envPrefix string) {
|
|||||||
if postErr != nil {
|
if postErr != nil {
|
||||||
log.Fatal(postErr)
|
log.Fatal(postErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Finish uploading %v entries to %s\n", len(entriesArray), postUrl)
|
fmt.Printf("Finish uploading %v entries to %s\n", len(entriesArray), postUrl)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -82,30 +81,32 @@ func RunMizuTap(podRegexQuery *regexp.Regexp, tappingOptions *MizuTapOptions) {
|
|||||||
waitForFinish(ctx, cancel)
|
waitForFinish(ctx, cancel)
|
||||||
}
|
}
|
||||||
|
|
||||||
type guestToken struct {
|
type GuestToken struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateAnonymousToken(baseUrl string) guestToken {
|
|
||||||
resp, httpErr := http.Get("https://trcc." + baseUrl + "/anonymous/token")
|
func getGuestToken(url string, target *GuestToken) error {
|
||||||
if httpErr != nil {
|
resp, err := http.Get(url)
|
||||||
fmt.Println(httpErr)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
return json.NewDecoder(resp.Body).Decode(target)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateAnonymousToken(envPrefix string) (*GuestToken, error) {
|
||||||
|
tokenUrl := fmt.Sprintf("https://trcc.%v/anonymous/token", envPrefix)
|
||||||
|
token := &GuestToken{}
|
||||||
|
if err := getGuestToken(tokenUrl, token); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
body, ioErr := ioutil.ReadAll(resp.Body)
|
|
||||||
resp.Body.Close()
|
|
||||||
if ioErr != nil {
|
|
||||||
fmt.Println(ioErr)
|
|
||||||
}
|
|
||||||
token := guestToken{}
|
|
||||||
jsonErr := json.Unmarshal(body, &token)
|
|
||||||
if jsonErr != nil {
|
|
||||||
fmt.Println(jsonErr)
|
|
||||||
}
|
|
||||||
fmt.Println("Token:", token.Token, "model:", token.Model)
|
fmt.Println("Token:", token.Token, "model:", token.Model)
|
||||||
|
return token, nil
|
||||||
return token
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createMizuResources(ctx context.Context, kubernetesProvider *kubernetes.Provider, nodeToTappedPodIPMap map[string][]string, tappingOptions *MizuTapOptions, mizuApiFilteringOptions *shared.TrafficFilteringOptions) error {
|
func createMizuResources(ctx context.Context, kubernetesProvider *kubernetes.Provider, nodeToTappedPodIPMap map[string][]string, tappingOptions *MizuTapOptions, mizuApiFilteringOptions *shared.TrafficFilteringOptions) error {
|
||||||
@@ -270,22 +271,21 @@ func portForwardApiPod(ctx context.Context, kubernetesProvider *kubernetes.Provi
|
|||||||
case modifiedPod := <-modified:
|
case modifiedPod := <-modified:
|
||||||
if modifiedPod.Status.Phase == "Running" && !isPodReady {
|
if modifiedPod.Status.Phase == "Running" && !isPodReady {
|
||||||
isPodReady = true
|
isPodReady = true
|
||||||
var err error
|
var portForwardCreateError error
|
||||||
portForward, err = kubernetes.NewPortForward(kubernetesProvider, mizu.ResourcesNamespace, mizu.AggregatorPodName, tappingOptions.GuiPort, tappingOptions.MizuPodPort, cancel)
|
if portForward, portForwardCreateError = kubernetes.NewPortForward(kubernetesProvider, mizu.ResourcesNamespace, mizu.AggregatorPodName, tappingOptions.GuiPort, tappingOptions.MizuPodPort, cancel); portForwardCreateError != nil {
|
||||||
fmt.Printf("Web interface is now available at http://localhost:%d\n", tappingOptions.GuiPort)
|
fmt.Printf("error forwarding port to pod %s\n", portForwardCreateError)
|
||||||
|
|
||||||
if tappingOptions.Analyze {
|
|
||||||
token := CreateAnonymousToken(tappingOptions.AnalyzeDestination)
|
|
||||||
_, err := http.Get(fmt.Sprintf("http://localhost:8899/api/uploadEntries?token=%s&model=%s&dest=%s", token.Token, token.Model, tappingOptions.AnalyzeDestination))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
fmt.Println("https://" + tappingOptions.AnalyzeDestination + "/share/" + token.Token)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("error forwarding port to pod %s\n", err)
|
|
||||||
cancel()
|
cancel()
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Web interface is now available at http://localhost:%d\n", tappingOptions.GuiPort)
|
||||||
|
|
||||||
|
if tappingOptions.Analyze {
|
||||||
|
token, _ := CreateAnonymousToken(tappingOptions.AnalyzeDestination)
|
||||||
|
if _, err := http.Get(fmt.Sprintf("http://localhost:%d/api/uploadEntries?token=%s&model=%s&dest=%s", tappingOptions.GuiPort, token.Token, token.Model, tappingOptions.AnalyzeDestination)); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
} else {
|
||||||
|
fmt.Println("https://" + tappingOptions.AnalyzeDestination + "/share/" + token.Token)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user