MCPcopy
hub / github.com/wavetermdev/waveterm / makeSwapToken

Function makeSwapToken

pkg/blockcontroller/blockcontroller.go:459–494  ·  view source on GitHub ↗
(ctx context.Context, logCtx context.Context, blockId string, blockMeta waveobj.MetaMapType, remoteName string, shellType string)

Source from the content-addressed store, hash-verified

457}
458
459func makeSwapToken(ctx context.Context, logCtx context.Context, blockId string, blockMeta waveobj.MetaMapType, remoteName string, shellType string) *shellutil.TokenSwapEntry {
460 token := &shellutil.TokenSwapEntry{
461 Token: uuid.New().String(),
462 Env: make(map[string]string),
463 Exp: time.Now().Add(5 * time.Minute),
464 }
465 token.Env["TERM_PROGRAM"] = "waveterm"
466 token.Env["WAVETERM_BLOCKID"] = blockId
467 token.Env["WAVETERM_VERSION"] = wavebase.WaveVersion
468 token.Env["WAVETERM"] = "1"
469 tabId, err := wstore.DBFindTabForBlockId(ctx, blockId)
470 if err != nil {
471 log.Printf("error finding tab for block: %v\n", err)
472 } else {
473 token.Env["WAVETERM_TABID"] = tabId
474 }
475 if tabId != "" {
476 wsId, err := wstore.DBFindWorkspaceForTabId(ctx, tabId)
477 if err != nil {
478 log.Printf("error finding workspace for tab: %v\n", err)
479 } else {
480 token.Env["WAVETERM_WORKSPACEID"] = wsId
481 }
482 }
483 token.Env["WAVETERM_CLIENTID"] = wstore.GetClientId()
484 token.Env["WAVETERM_CONN"] = remoteName
485 envMap, err := resolveEnvMap(blockId, blockMeta, remoteName)
486 if err != nil {
487 log.Printf("error resolving env map: %v\n", err)
488 }
489 for k, v := range envMap {
490 token.Env[k] = v
491 }
492 token.ScriptText = getCustomInitScript(logCtx, blockMeta, remoteName, shellType)
493 return token
494}

Callers 2

startNewJobMethod · 0.85

Calls 6

DBFindTabForBlockIdFunction · 0.92
DBFindWorkspaceForTabIdFunction · 0.92
GetClientIdFunction · 0.92
resolveEnvMapFunction · 0.85
getCustomInitScriptFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected