Skip to content

Commit f319351

Browse files
authored
[TB] Update respond data of joinLink2 (#20133)
1 parent cdab2fe commit f319351

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

components/ide-service/pkg/server/server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,11 @@ func (s *IDEServiceServer) ResolveWorkspaceConfig(ctx context.Context, req *api.
456456
Name: "GITPOD_PREFER_TOOLBOX",
457457
Value: "true",
458458
}
459-
resp.Envvars = append(resp.Envvars, &preferToolboxEnv)
459+
debuggingEnv := api.EnvironmentVariable{
460+
Name: "GITPOD_TOOLBOX_DEBUGGING",
461+
Value: s.experimentsClient.GetStringValue(ctx, "enable_experimental_jbtb_debugging", "", experiments.Attributes{UserID: req.User.Id}),
462+
}
463+
resp.Envvars = append(resp.Envvars, &preferToolboxEnv, &debuggingEnv)
460464
}
461465

462466
if userIdeName != "" {

components/ide/jetbrains/launcher/main.go

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ type LaunchContext struct {
8181
shouldWaitBackendPlugin bool
8282
}
8383

84+
func (c *LaunchContext) getCommonJoinLinkResponse(appPid int, joinLink string) *JoinLinkResponse {
85+
return &JoinLinkResponse{
86+
AppPid: appPid,
87+
JoinLink: joinLink,
88+
IDEVersion: fmt.Sprintf("%s-%s", c.info.ProductCode, c.info.BuildNumber),
89+
ProjectPath: c.projectContextDir,
90+
}
91+
}
92+
8493
// JB startup entrypoint
8594
func main() {
8695
if len(os.Args) == 3 && os.Args[1] == "env" && os.Args[2] != "" {
@@ -267,7 +276,7 @@ func serve(launchCtx *LaunchContext) {
267276
if backendPort == "" {
268277
backendPort = defaultBackendPort
269278
}
270-
jsonResp, err := resolveJsonLink2(backendPort)
279+
jsonResp, err := resolveJsonLink2(launchCtx, backendPort)
271280
if err != nil {
272281
log.WithError(err).Error("cannot resolve join link")
273282
http.Error(w, err.Error(), http.StatusServiceUnavailable)
@@ -385,6 +394,11 @@ type Response struct {
385394
type JoinLinkResponse struct {
386395
AppPid int `json:"appPid"`
387396
JoinLink string `json:"joinLink"`
397+
398+
// IDEVersion is the ideVersionHint that required by Toolbox to `setAutoConnectOnEnvironmentReady`
399+
IDEVersion string `json:"ideVersion"`
400+
// ProjectPath is the projectPathHint that required by Toolbox to `setAutoConnectOnEnvironmentReady`
401+
ProjectPath string `json:"projectPath"`
388402
}
389403

390404
func resolveToolboxLink(wsInfo *supervisor.WorkspaceInfoResponse) (string, error) {
@@ -426,7 +440,7 @@ func resolveJsonLink(backendPort string) (string, error) {
426440
return "", err
427441
}
428442
defer resp.Body.Close()
429-
bodyBytes, err := ioutil.ReadAll(resp.Body)
443+
bodyBytes, err := io.ReadAll(resp.Body)
430444
if err != nil {
431445
return "", err
432446
}
@@ -438,13 +452,13 @@ func resolveJsonLink(backendPort string) (string, error) {
438452
if err != nil {
439453
return "", err
440454
}
441-
if len(jsonResp.Projects) != 1 {
442-
return "", xerrors.Errorf("project is not found")
455+
if len(jsonResp.Projects) > 0 {
456+
return jsonResp.Projects[0].JoinLink, nil
443457
}
444-
return jsonResp.Projects[0].JoinLink, nil
458+
return jsonResp.JoinLink, nil
445459
}
446460

447-
func resolveJsonLink2(backendPort string) (*JoinLinkResponse, error) {
461+
func resolveJsonLink2(launchCtx *LaunchContext, backendPort string) (*JoinLinkResponse, error) {
448462
var (
449463
hostStatusUrl = "http://localhost:" + backendPort + "/codeWithMe/unattendedHostStatus?token=gitpod"
450464
client = http.Client{Timeout: 1 * time.Second}
@@ -467,11 +481,10 @@ func resolveJsonLink2(backendPort string) (*JoinLinkResponse, error) {
467481
return nil, err
468482
}
469483
if len(jsonResp.Projects) > 0 {
470-
return &JoinLinkResponse{AppPid: jsonResp.AppPid, JoinLink: jsonResp.Projects[0].JoinLink}, nil
471-
484+
return launchCtx.getCommonJoinLinkResponse(jsonResp.AppPid, jsonResp.Projects[0].JoinLink), nil
472485
}
473486
if len(jsonResp.JoinLink) > 0 {
474-
return &JoinLinkResponse{AppPid: jsonResp.AppPid, JoinLink: jsonResp.JoinLink}, nil
487+
return launchCtx.getCommonJoinLinkResponse(jsonResp.AppPid, jsonResp.JoinLink), nil
475488
}
476489
log.Error("failed to resolve JetBrains JoinLink")
477490
return nil, xerrors.Errorf("failed to resolve JoinLink")
@@ -889,6 +902,7 @@ func updateVMOptions(
889902
}
890903
*/
891904
type ProductInfo struct {
905+
BuildNumber string `json:"buildNumber"`
892906
Version string `json:"version"`
893907
ProductCode string `json:"productCode"`
894908
}
@@ -1255,19 +1269,22 @@ func configureToolboxCliProperties(backendDir string) error {
12551269

12561270
toolboxCliPropertiesFilePath := fmt.Sprintf("%s/environment.json", toolboxCliPropertiesDir)
12571271

1272+
debuggingToolbox := os.Getenv("GITPOD_TOOLBOX_DEBUGGING")
1273+
allowInstallation := strconv.FormatBool(strings.Contains(debuggingToolbox, "allowInstallation"))
1274+
12581275
// TODO(hw): restrict IDE installation
12591276
content := fmt.Sprintf(`{
12601277
"tools": {
1261-
"allowInstallation": true,
1278+
"allowInstallation": %s,
12621279
"allowUpdate": false,
1263-
"allowUninstallation": true,
1280+
"allowUninstallation": %s,
12641281
"location": [
12651282
{
12661283
"path": "%s"
12671284
}
12681285
]
12691286
}
1270-
}`, backendDir)
1287+
}`, allowInstallation, allowInstallation, backendDir)
12711288

12721289
return os.WriteFile(toolboxCliPropertiesFilePath, []byte(content), 0o644)
12731290
}

0 commit comments

Comments
 (0)