From f3193519fdae872d64a2a708f5338eeaabb3b6b7 Mon Sep 17 00:00:00 2001 From: mustard Date: Tue, 20 Aug 2024 14:32:19 +0800 Subject: [PATCH] [TB] Update respond data of joinLink2 (#20133) --- components/ide-service/pkg/server/server.go | 6 ++- components/ide/jetbrains/launcher/main.go | 41 +++++++++++++++------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/components/ide-service/pkg/server/server.go b/components/ide-service/pkg/server/server.go index f47a6958aaba4c..de64ce5c5fb28e 100644 --- a/components/ide-service/pkg/server/server.go +++ b/components/ide-service/pkg/server/server.go @@ -456,7 +456,11 @@ func (s *IDEServiceServer) ResolveWorkspaceConfig(ctx context.Context, req *api. Name: "GITPOD_PREFER_TOOLBOX", Value: "true", } - resp.Envvars = append(resp.Envvars, &preferToolboxEnv) + debuggingEnv := api.EnvironmentVariable{ + Name: "GITPOD_TOOLBOX_DEBUGGING", + Value: s.experimentsClient.GetStringValue(ctx, "enable_experimental_jbtb_debugging", "", experiments.Attributes{UserID: req.User.Id}), + } + resp.Envvars = append(resp.Envvars, &preferToolboxEnv, &debuggingEnv) } if userIdeName != "" { diff --git a/components/ide/jetbrains/launcher/main.go b/components/ide/jetbrains/launcher/main.go index 3d5686d2bcb694..cd6074558badc5 100644 --- a/components/ide/jetbrains/launcher/main.go +++ b/components/ide/jetbrains/launcher/main.go @@ -81,6 +81,15 @@ type LaunchContext struct { shouldWaitBackendPlugin bool } +func (c *LaunchContext) getCommonJoinLinkResponse(appPid int, joinLink string) *JoinLinkResponse { + return &JoinLinkResponse{ + AppPid: appPid, + JoinLink: joinLink, + IDEVersion: fmt.Sprintf("%s-%s", c.info.ProductCode, c.info.BuildNumber), + ProjectPath: c.projectContextDir, + } +} + // JB startup entrypoint func main() { if len(os.Args) == 3 && os.Args[1] == "env" && os.Args[2] != "" { @@ -267,7 +276,7 @@ func serve(launchCtx *LaunchContext) { if backendPort == "" { backendPort = defaultBackendPort } - jsonResp, err := resolveJsonLink2(backendPort) + jsonResp, err := resolveJsonLink2(launchCtx, backendPort) if err != nil { log.WithError(err).Error("cannot resolve join link") http.Error(w, err.Error(), http.StatusServiceUnavailable) @@ -385,6 +394,11 @@ type Response struct { type JoinLinkResponse struct { AppPid int `json:"appPid"` JoinLink string `json:"joinLink"` + + // IDEVersion is the ideVersionHint that required by Toolbox to `setAutoConnectOnEnvironmentReady` + IDEVersion string `json:"ideVersion"` + // ProjectPath is the projectPathHint that required by Toolbox to `setAutoConnectOnEnvironmentReady` + ProjectPath string `json:"projectPath"` } func resolveToolboxLink(wsInfo *supervisor.WorkspaceInfoResponse) (string, error) { @@ -426,7 +440,7 @@ func resolveJsonLink(backendPort string) (string, error) { return "", err } defer resp.Body.Close() - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { return "", err } @@ -438,13 +452,13 @@ func resolveJsonLink(backendPort string) (string, error) { if err != nil { return "", err } - if len(jsonResp.Projects) != 1 { - return "", xerrors.Errorf("project is not found") + if len(jsonResp.Projects) > 0 { + return jsonResp.Projects[0].JoinLink, nil } - return jsonResp.Projects[0].JoinLink, nil + return jsonResp.JoinLink, nil } -func resolveJsonLink2(backendPort string) (*JoinLinkResponse, error) { +func resolveJsonLink2(launchCtx *LaunchContext, backendPort string) (*JoinLinkResponse, error) { var ( hostStatusUrl = "http://localhost:" + backendPort + "/codeWithMe/unattendedHostStatus?token=gitpod" client = http.Client{Timeout: 1 * time.Second} @@ -467,11 +481,10 @@ func resolveJsonLink2(backendPort string) (*JoinLinkResponse, error) { return nil, err } if len(jsonResp.Projects) > 0 { - return &JoinLinkResponse{AppPid: jsonResp.AppPid, JoinLink: jsonResp.Projects[0].JoinLink}, nil - + return launchCtx.getCommonJoinLinkResponse(jsonResp.AppPid, jsonResp.Projects[0].JoinLink), nil } if len(jsonResp.JoinLink) > 0 { - return &JoinLinkResponse{AppPid: jsonResp.AppPid, JoinLink: jsonResp.JoinLink}, nil + return launchCtx.getCommonJoinLinkResponse(jsonResp.AppPid, jsonResp.JoinLink), nil } log.Error("failed to resolve JetBrains JoinLink") return nil, xerrors.Errorf("failed to resolve JoinLink") @@ -889,6 +902,7 @@ func updateVMOptions( } */ type ProductInfo struct { + BuildNumber string `json:"buildNumber"` Version string `json:"version"` ProductCode string `json:"productCode"` } @@ -1255,19 +1269,22 @@ func configureToolboxCliProperties(backendDir string) error { toolboxCliPropertiesFilePath := fmt.Sprintf("%s/environment.json", toolboxCliPropertiesDir) + debuggingToolbox := os.Getenv("GITPOD_TOOLBOX_DEBUGGING") + allowInstallation := strconv.FormatBool(strings.Contains(debuggingToolbox, "allowInstallation")) + // TODO(hw): restrict IDE installation content := fmt.Sprintf(`{ "tools": { - "allowInstallation": true, + "allowInstallation": %s, "allowUpdate": false, - "allowUninstallation": true, + "allowUninstallation": %s, "location": [ { "path": "%s" } ] } -}`, backendDir) +}`, allowInstallation, allowInstallation, backendDir) return os.WriteFile(toolboxCliPropertiesFilePath, []byte(content), 0o644) }