Skip to content

Commit

Permalink
[TB] Update respond data of joinLink2 (#20133)
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh authored Aug 20, 2024
1 parent cdab2fe commit f319351
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
6 changes: 5 additions & 1 deletion components/ide-service/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
41 changes: 29 additions & 12 deletions components/ide/jetbrains/launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] != "" {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand All @@ -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}
Expand All @@ -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")
Expand Down Expand Up @@ -889,6 +902,7 @@ func updateVMOptions(
}
*/
type ProductInfo struct {
BuildNumber string `json:"buildNumber"`
Version string `json:"version"`
ProductCode string `json:"productCode"`
}
Expand Down Expand Up @@ -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)
}

0 comments on commit f319351

Please sign in to comment.