Skip to content

Commit 92be0f7

Browse files
committed
unity subscriptions
1 parent 3f513bb commit 92be0f7

File tree

9 files changed

+390
-1210
lines changed

9 files changed

+390
-1210
lines changed

components/gitpod-cli/cmd/open.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,24 @@ var openCmd = &cobra.Command{
4545
paths = append(paths, path)
4646
}
4747

48-
_, err := client.Notification.NotifyActive(ctx, &api.NotifyActiveRequest{
49-
ActionData: &api.NotifyActiveRequest_Open{
50-
Open: &api.NotifyActiveRequest_OpenData{
51-
Paths: paths,
52-
Await: wait,
53-
},
48+
resp, err := client.Notification.Notify(ctx, &api.NotifyRequest{
49+
Open: &api.NotifyRequest_Open{
50+
Paths: paths,
51+
Await: wait,
5452
},
53+
Active: true,
5554
})
56-
if err != nil && ctx.Err() == nil {
57-
return xerrors.Errorf("failed to open: %w", err)
55+
if err != nil {
56+
return err
5857
}
59-
return nil
58+
if resp.Command == nil {
59+
return nil
60+
}
61+
c := exec.CommandContext(cmd.Context(), resp.Command.Cmd, resp.Command.Args...)
62+
c.Stdin = os.Stdin
63+
c.Stdout = os.Stdout
64+
c.Stderr = os.Stderr
65+
return c.Run()
6066
}
6167
// TODO: backward compatibilty, remove when all IDEs are updated
6268
pargs, err := shlex.Split(pcmd)

components/gitpod-cli/cmd/preview.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,24 @@ func openPreview(ctx context.Context, url string, external bool) error {
5353
}
5454
pcmd := os.Getenv(gpBrowserEnvVar)
5555
if pcmd == "" {
56-
_, err := client.Notification.NotifyActive(ctx, &api.NotifyActiveRequest{
57-
ActionData: &api.NotifyActiveRequest_Preview{
58-
Preview: &api.NotifyActiveRequest_PreviewData{
59-
Url: url,
60-
External: external,
61-
},
56+
resp, err := client.Notification.Notify(ctx, &api.NotifyRequest{
57+
Preview: &api.NotifyRequest_Preview{
58+
Url: url,
59+
External: external,
6260
},
61+
Active: true,
6362
})
64-
return err
63+
if err != nil {
64+
return err
65+
}
66+
if resp.Command == nil {
67+
return nil
68+
}
69+
c := exec.CommandContext(ctx, resp.Command.Cmd, resp.Command.Args...)
70+
c.Stdin = os.Stdin
71+
c.Stdout = os.Stdout
72+
c.Stderr = os.Stderr
73+
return c.Run()
6574
}
6675
// TODO: backward compatibilty, remove when all IDEs are updated
6776
if pcmd == "" {

components/gitpod-cli/hot-swap.sh

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,45 @@
66
set -Eeuo pipefail
77

88
component=${PWD##*/}
9-
workspaceUrl=$(echo "${1}" |sed -e "s/\/$//")
10-
echo "URL: $workspaceUrl"
9+
workspaceURL=$(echo "${1}" |sed -e "s/\/$//")
10+
echo "Workspace URL: $workspaceURL"
1111

12-
workspaceDesc=$(gpctl workspaces describe "$workspaceUrl" -o=json)
12+
workspaceHost=${workspaceURL//https:\/\//}
13+
echo "Workspace Host: $workspaceHost"
1314

14-
podName=$(echo "$workspaceDesc" | jq .runtime.pod_name -r)
15-
echo "Pod: $podName"
15+
workspaceID=$(echo "${workspaceHost}" | cut -d. -f1)
16+
echo "Workspace ID: $workspaceID"
1617

17-
workspaceId=$(echo "$workspaceDesc" | jq .metadata.meta_id -r)
18-
echo "ID: $workspaceId"
19-
20-
clusterHost=$(kubectl exec -it "$podName" -- printenv GITPOD_WORKSPACE_CLUSTER_HOST |sed -e "s/\s//g")
18+
clusterHost=${workspaceHost//$workspaceID./}
2119
echo "Cluster Host: $clusterHost"
2220

23-
# prepare ssh
24-
ownerToken=$(kubectl get pod "$podName" -o=json | jq ".metadata.annotations.\"gitpod\/ownerToken\"" -r)
21+
devClusterHost=$(gp info --json |jq .cluster_host -r)
22+
echo "Dev Cluster Host: $devClusterHost"
23+
24+
preview=true
25+
if [[ $clusterHost = "$devClusterHost" ]]
26+
then
27+
preview=false
28+
fi
29+
echo "Preview Env: $preview"
30+
31+
# prepare ssh config
2532
sshConfig=$(mktemp)
26-
echo "Host $workspaceId" > "$sshConfig"
27-
echo " Hostname \"$workspaceId.ssh.$clusterHost\"" >> "$sshConfig"
28-
echo " User \"$workspaceId#$ownerToken\"" >> "$sshConfig"
33+
echo "Host $workspaceID" > "$sshConfig"
34+
echo " Hostname \"$workspaceID.ssh.$clusterHost\"" >> "$sshConfig"
35+
if [ $preview = "true" ]
36+
then
37+
workspaceDesc=$(gpctl workspaces describe "$workspaceURL" -o=json)
38+
39+
podName=$(echo "$workspaceDesc" | jq .runtime.pod_name -r)
40+
echo "Workspace Pod: $podName"
41+
42+
ownerToken=$(kubectl get pod "$podName" -o=json | jq ".metadata.annotations.\"gitpod\/ownerToken\"" -r)
43+
echo " User \"$workspaceID#$ownerToken\"" >> "$sshConfig"
44+
else
45+
# assume SSH keys configured via .dotfiles
46+
echo " User \"$workspaceID\"" >> "$sshConfig"
47+
fi
2948

3049
# build
3150
go build .
@@ -34,7 +53,7 @@ echo "$component built"
3453
# upload
3554
uploadDest="/.supervisor/$component"
3655
echo "Upload Dest: $uploadDest"
37-
ssh -F "$sshConfig" "$workspaceId" "sudo chown -R gitpod:gitpod /.supervisor && rm $uploadDest 2> /dev/null"
56+
ssh -F "$sshConfig" "$workspaceID" "sudo chown -R gitpod:gitpod /.supervisor && rm $uploadDest 2> /dev/null"
3857
echo "Permissions granted"
39-
scp -F "$sshConfig" -r "./$component" "$workspaceId":"$uploadDest"
58+
scp -F "$sshConfig" -r "./$component" "$workspaceID":"$uploadDest"
4059
echo "Swap complete"

0 commit comments

Comments
 (0)