Skip to content

Commit 9619985

Browse files
filiptronicekroboquat
authored andcommitted
Clean up some theia references
Fix condition remove `printVarFromTheia` Unused theia lib
1 parent 540ec68 commit 9619985

File tree

3 files changed

+44
-163
lines changed

3 files changed

+44
-163
lines changed

components/gitpod-cli/cmd/credential-helper.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package cmd
77
import (
88
"bufio"
99
"context"
10-
"errors"
1110
"fmt"
1211
"io"
1312
"io/ioutil"
@@ -22,7 +21,6 @@ import (
2221
"github.com/spf13/cobra"
2322
"google.golang.org/grpc"
2423

25-
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/theialib"
2624
supervisor "github.com/gitpod-io/gitpod/supervisor/api"
2725
)
2826

@@ -75,27 +73,6 @@ var credentialHelper = &cobra.Command{
7573
log.Println("'host' is missing")
7674
}
7775

78-
if isTheiaIDE() {
79-
service, err := theialib.NewServiceFromEnv()
80-
if err != nil {
81-
log.WithError(err).Print("cannot connect to Theia")
82-
return
83-
}
84-
if action == "get" {
85-
resp, err := service.GetGitToken(theialib.GetGitTokenRequest{
86-
Command: gitCommand,
87-
Host: host,
88-
RepoURL: repoURL,
89-
})
90-
if err != nil {
91-
log.WithError(err).Print("cannot get token")
92-
return
93-
}
94-
user = resp.User
95-
token = resp.Token
96-
}
97-
return
98-
}
9976
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
10077
defer cancel()
10178
supervisorAddr := os.Getenv("SUPERVISOR_ADDR")
@@ -134,11 +111,6 @@ var credentialHelper = &cobra.Command{
134111
},
135112
}
136113

137-
func isTheiaIDE() bool {
138-
stat, err := os.Stat("/theia")
139-
return !errors.Is(os.ErrNotExist, err) && stat != nil && stat.IsDir()
140-
}
141-
142114
func parseHostFromStdin() string {
143115
host := ""
144116
scanner := bufio.NewScanner(os.Stdin)

components/gitpod-cli/cmd/env.go

Lines changed: 44 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"golang.org/x/xerrors"
1919
"google.golang.org/grpc"
2020

21-
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/theialib"
2221
serverapi "github.com/gitpod-io/gitpod/gitpod-protocol"
2322
supervisor "github.com/gitpod-io/gitpod/supervisor/api"
2423
)
@@ -124,148 +123,78 @@ func connectToServer(ctx context.Context) (*connectToServerResult, error) {
124123
}
125124

126125
func getEnvs() {
127-
if !isTheiaIDE() {
128-
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
129-
defer cancel()
130-
result, err := connectToServer(ctx)
131-
if err != nil {
132-
fail(err.Error())
133-
}
134-
135-
vars, err := result.client.GetEnvVars(ctx)
136-
if err != nil {
137-
fail("failed to fetch env vars from server: " + err.Error())
138-
}
139-
140-
for _, v := range vars {
141-
printVar(v, exportEnvs)
142-
}
143-
return
144-
}
145-
146-
service, err := theialib.NewServiceFromEnv()
126+
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
127+
defer cancel()
128+
result, err := connectToServer(ctx)
147129
if err != nil {
148130
fail(err.Error())
149131
}
150132

151-
vars, err := service.GetEnvVars(theialib.GetEnvvarsRequest{})
133+
vars, err := result.client.GetEnvVars(ctx)
152134
if err != nil {
153-
fail(fmt.Sprintf("cannot get environment variables: %v", err))
135+
fail("failed to fetch env vars from server: " + err.Error())
154136
}
155137

156-
for _, v := range vars.Variables {
157-
printVarFromTheia(v, exportEnvs)
138+
for _, v := range vars {
139+
printVar(v, exportEnvs)
158140
}
159141
}
160142

161143
func setEnvs(args []string) {
162-
if !isTheiaIDE() {
163-
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
164-
defer cancel()
165-
result, err := connectToServer(ctx)
166-
if err != nil {
167-
fail(err.Error())
168-
}
169-
170-
vars, err := parseArgs(args, result.repositoryPattern)
171-
if err != nil {
172-
fail(err.Error())
173-
}
174-
175-
var exitCode int
176-
var wg sync.WaitGroup
177-
wg.Add(len(vars))
178-
for _, v := range vars {
179-
go func(v *serverapi.UserEnvVarValue) {
180-
err = result.client.SetEnvVar(ctx, v)
181-
if err != nil {
182-
fmt.Fprintf(os.Stderr, "cannot set %s: %v\n", v.Name, err)
183-
exitCode = -1
184-
} else {
185-
printVar(v, exportEnvs)
186-
}
187-
wg.Done()
188-
}(v)
189-
}
190-
wg.Wait()
191-
os.Exit(exitCode)
192-
}
193-
194-
service, err := theialib.NewServiceFromEnv()
144+
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
145+
defer cancel()
146+
result, err := connectToServer(ctx)
195147
if err != nil {
196148
fail(err.Error())
197149
}
198150

199-
vars := make([]theialib.EnvironmentVariable, len(args))
200-
for i, arg := range args {
201-
kv := strings.Split(arg, "=")
202-
if len(kv) != 2 {
203-
fail(fmt.Sprintf("%s has no value (correct format is %s=some_value)", arg, arg))
204-
}
205-
206-
key := strings.TrimSpace(kv[0])
207-
if key == "" {
208-
fail("variable must have a name")
209-
}
210-
// Do not trim value - the user might want whitespace here
211-
// Also do not check if the value is empty, as an empty value means we want to delete the variable
212-
val := kv[1]
213-
if val == "" {
214-
fail("variable must have a value; use -u to unset a variable")
215-
}
216-
217-
vars[i] = theialib.EnvironmentVariable{Name: key, Value: val}
218-
}
219-
220-
_, err = service.SetEnvVar(theialib.SetEnvvarRequest{Variables: vars})
151+
vars, err := parseArgs(args, result.repositoryPattern)
221152
if err != nil {
222-
fail(fmt.Sprintf("cannot set environment variables: %v", err))
153+
fail(err.Error())
223154
}
224155

156+
var exitCode int
157+
var wg sync.WaitGroup
158+
wg.Add(len(vars))
225159
for _, v := range vars {
226-
printVarFromTheia(v, exportEnvs)
160+
go func(v *serverapi.UserEnvVarValue) {
161+
err = result.client.SetEnvVar(ctx, v)
162+
if err != nil {
163+
fmt.Fprintf(os.Stderr, "cannot set %s: %v\n", v.Name, err)
164+
exitCode = -1
165+
} else {
166+
printVar(v, exportEnvs)
167+
}
168+
wg.Done()
169+
}(v)
227170
}
171+
wg.Wait()
172+
os.Exit(exitCode)
228173
}
229174

230175
func deleteEnvs(args []string) {
231-
if !isTheiaIDE() {
232-
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
233-
defer cancel()
234-
result, err := connectToServer(ctx)
235-
if err != nil {
236-
fail(err.Error())
237-
}
238-
239-
var exitCode int
240-
var wg sync.WaitGroup
241-
wg.Add(len(args))
242-
for _, name := range args {
243-
go func(name string) {
244-
err = result.client.DeleteEnvVar(ctx, &serverapi.UserEnvVarValue{Name: name, RepositoryPattern: result.repositoryPattern})
245-
if err != nil {
246-
fmt.Fprintf(os.Stderr, "cannot unset %s: %v\n", name, err)
247-
exitCode = -1
248-
}
249-
wg.Done()
250-
}(name)
251-
}
252-
wg.Wait()
253-
os.Exit(exitCode)
254-
}
255-
256-
service, err := theialib.NewServiceFromEnv()
176+
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
177+
defer cancel()
178+
result, err := connectToServer(ctx)
257179
if err != nil {
258180
fail(err.Error())
259181
}
260182

261-
resp, err := service.DeleteEnvVar(theialib.DeleteEnvvarRequest{Variables: args})
262-
if err != nil {
263-
fail(fmt.Sprintf("cannot unset environment variables: %v", err))
264-
}
265-
266-
if len(resp.NotDeleted) != 0 {
267-
fail(fmt.Sprintf("cannot unset environment variables: %s", strings.Join(resp.NotDeleted, ", ")))
183+
var exitCode int
184+
var wg sync.WaitGroup
185+
wg.Add(len(args))
186+
for _, name := range args {
187+
go func(name string) {
188+
err = result.client.DeleteEnvVar(ctx, &serverapi.UserEnvVarValue{Name: name, RepositoryPattern: result.repositoryPattern})
189+
if err != nil {
190+
fmt.Fprintf(os.Stderr, "cannot unset %s: %v\n", name, err)
191+
exitCode = -1
192+
}
193+
wg.Done()
194+
}(name)
268195
}
196+
wg.Wait()
197+
os.Exit(exitCode)
269198
}
270199

271200
func fail(msg string) {
@@ -282,15 +211,6 @@ func printVar(v *serverapi.UserEnvVarValue, export bool) {
282211
}
283212
}
284213

285-
func printVarFromTheia(v theialib.EnvironmentVariable, export bool) {
286-
val := strings.Replace(v.Value, "\"", "\\\"", -1)
287-
if export {
288-
fmt.Printf("export %s=\"%s\"\n", v.Name, val)
289-
} else {
290-
fmt.Printf("%s=%s\n", v.Name, val)
291-
}
292-
}
293-
294214
func parseArgs(args []string, pattern string) ([]*serverapi.UserEnvVarValue, error) {
295215
vars := make([]*serverapi.UserEnvVarValue, len(args))
296216
for i, arg := range args {

components/gitpod-cli/cmd/preview.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
"github.com/google/shlex"
1616
"github.com/spf13/cobra"
1717
"golang.org/x/sys/unix"
18-
19-
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/theialib"
2018
)
2119

2220
var regexLocalhost = regexp.MustCompile(`((^(localhost|127\.0\.0\.1))|(https?://(localhost|127\.0\.0\.1)))(:[0-9]+)?`)
@@ -39,15 +37,6 @@ var previewCmd = &cobra.Command{
3937
openPreview("GP_EXTERNAL_BROWSER", url)
4038
return
4139
}
42-
if isTheiaIDE() {
43-
if service, err := theialib.NewServiceFromEnv(); err == nil {
44-
_, err = service.OpenPreview(theialib.OpenPreviewRequest{URL: url})
45-
if err == nil {
46-
// we've opened the preview. All is well.
47-
return
48-
}
49-
}
50-
}
5140
openPreview("GP_PREVIEW_BROWSER", url)
5241
},
5342
}

0 commit comments

Comments
 (0)