mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-02 03:00:41 +00:00
added upsert workspace before dumping traffic (#368)
This commit is contained in:
@@ -75,9 +75,6 @@ func getAuthHeader(guestMode bool) string {
|
|||||||
|
|
||||||
func GetTrafficDumpUrl(analyzeDestination string, analyzeModel string) *url.URL {
|
func GetTrafficDumpUrl(analyzeDestination string, analyzeModel string) *url.URL {
|
||||||
strUrl := fmt.Sprintf("https://traffic.%s/dumpTrafficBulk/%s", analyzeDestination, analyzeModel)
|
strUrl := fmt.Sprintf("https://traffic.%s/dumpTrafficBulk/%s", analyzeDestination, analyzeModel)
|
||||||
if strings.HasPrefix(analyzeDestination, "http") {
|
|
||||||
strUrl = fmt.Sprintf("%s/api/workspace/dumpTrafficBulk", analyzeDestination)
|
|
||||||
}
|
|
||||||
postUrl, _ := url.Parse(strUrl)
|
postUrl, _ := url.Parse(strUrl)
|
||||||
return postUrl
|
return postUrl
|
||||||
}
|
}
|
||||||
@@ -132,6 +129,11 @@ func SyncEntries(syncEntriesConfig *shared.SyncEntriesConfig) error {
|
|||||||
token = fmt.Sprintf("bearer %s", syncEntriesConfig.Token)
|
token = fmt.Sprintf("bearer %s", syncEntriesConfig.Token)
|
||||||
model = syncEntriesConfig.Workspace
|
model = syncEntriesConfig.Workspace
|
||||||
guestMode = false
|
guestMode = false
|
||||||
|
|
||||||
|
logger.Log.Infof("Sync entries - upserting model. env %s, model %s\n", syncEntriesConfig.Env, model)
|
||||||
|
if err := upsertModel(token, model, syncEntriesConfig.Env); err != nil {
|
||||||
|
return fmt.Errorf("failed upserting model, err: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
modelRegex, _ := regexp.Compile("[A-Za-z0-9][-A-Za-z0-9_.]*[A-Za-z0-9]+$")
|
modelRegex, _ := regexp.Compile("[A-Za-z0-9][-A-Za-z0-9_.]*[A-Za-z0-9]+$")
|
||||||
@@ -145,6 +147,31 @@ func SyncEntries(syncEntriesConfig *shared.SyncEntriesConfig) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func upsertModel(token string, model string, envPrefix string) error {
|
||||||
|
upsertModelUrl, _ := url.Parse(fmt.Sprintf("https://trcc.%s/models/%s", envPrefix, model))
|
||||||
|
|
||||||
|
authHeader := getAuthHeader(false)
|
||||||
|
req := &http.Request{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
URL: upsertModelUrl,
|
||||||
|
Header: map[string][]string{
|
||||||
|
authHeader: {token},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed request to upsert model, err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case the model is not created (not 201) and doesn't exists (not 409)
|
||||||
|
if response.StatusCode != 201 && response.StatusCode != 409 {
|
||||||
|
return fmt.Errorf("failed request to upsert model, status code: %v", response.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func createAnonymousToken(envPrefix string) (*GuestToken, error) {
|
func createAnonymousToken(envPrefix string) (*GuestToken, error) {
|
||||||
tokenUrl := fmt.Sprintf("https://trcc.%s/anonymous/token", envPrefix)
|
tokenUrl := fmt.Sprintf("https://trcc.%s/anonymous/token", envPrefix)
|
||||||
if strings.HasPrefix(envPrefix, "http") {
|
if strings.HasPrefix(envPrefix, "http") {
|
||||||
|
Reference in New Issue
Block a user