Skip to content

Commit d242a84

Browse files
committed
Get stuck on git askpass
1 parent 46f0339 commit d242a84

File tree

10 files changed

+40
-86
lines changed

10 files changed

+40
-86
lines changed

cli/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/coder/coder/codersdk/agentsdk"
2828
)
2929

30-
func (_ *RootCmd) workspaceAgent() *clibase.Cmd {
30+
func (*RootCmd) workspaceAgent() *clibase.Cmd {
3131
var (
3232
auth string
3333
logDir string

cli/clibase/cmd.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ type Invokation struct {
113113
}
114114

115115
func (i *Invokation) Context() context.Context {
116+
if i.ctx == nil {
117+
return context.Background()
118+
}
116119
return i.ctx
117120
}
118121

@@ -230,7 +233,11 @@ func (i *Invokation) run(state *runState) error {
230233
return i.Command.HelpHandler(i)
231234
}
232235

233-
return mw(i.Command.Handler)(i)
236+
err = mw(i.Command.Handler)(i)
237+
if err != nil {
238+
return xerrors.Errorf("running command %s: %w", i.Command.FullName(), err)
239+
}
240+
return nil
234241
}
235242

236243
// findArg returns the index of the first occurrence of arg in args, skipping

cli/clitest/clitest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func StartErr(t *testing.T, inv *clibase.Invokation) <-chan error {
160160
go func() {
161161
defer cancel()
162162
defer close(errCh)
163-
errCh <- inv.Run()
163+
errCh <- inv.WithContext(ctx).Run()
164164
}()
165165

166166
// Don't exit test routine until server is done.

cli/gitaskpass.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ import (
1818

1919
// gitAskpass is used by the Coder agent to automatically authenticate
2020
// with Git providers based on a hostname.
21-
func (r *RootCmd) gitAskpass() *clibase.Cmd {
21+
func (*RootCmd) gitAskpass() *clibase.Cmd {
2222
return &clibase.Cmd{
2323
Use: "gitaskpass",
2424
Hidden: true,
25-
Middleware: clibase.Chain(
26-
clibase.RequireNArgs(1),
27-
),
2825
Handler: func(inv *clibase.Invokation) error {
2926
ctx := inv.Context()
3027

cli/gitaskpass_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ func TestGitAskpass(t *testing.T) {
3333
inv, _ := clitest.New(t, "--agent-url", url, "Username for 'https://github.com':")
3434
pty := ptytest.New(t)
3535
inv.Stdout = pty.Output()
36-
err := inv.Run()
37-
require.NoError(t, err)
36+
clitest.Start(t, inv)
3837
pty.ExpectMatch("something")
3938

4039
inv, _ = clitest.New(t, "--agent-url", url, "Password for 'https://potato@github.com':")
4140
pty = ptytest.New(t)
4241
inv.Stdout = pty.Output()
43-
err = inv.Run()
44-
require.NoError(t, err)
42+
clitest.Start(t, inv)
4543
pty.ExpectMatch("bananas")
4644
})
4745

cli/root.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func Core() []*clibase.Cmd {
9696

9797
// Hidden
9898
r.workspaceAgent(),
99+
r.scaletest(),
99100
}
100101
}
101102

@@ -146,9 +147,6 @@ func (r *RootCmd) Command(subcommands []*clibase.Cmd) *clibase.Cmd {
146147
Command: "coder templates init",
147148
},
148149
),
149-
Middleware: clibase.Chain(
150-
clibase.RequireNArgs(0),
151-
),
152150
Handler: func(i *clibase.Invokation) error {
153151
// The GIT_ASKPASS environment variable must point at
154152
// a binary with no arguments. To prevent writing
@@ -173,6 +171,13 @@ func (r *RootCmd) Command(subcommands []*clibase.Cmd) *clibase.Cmd {
173171
}
174172
})
175173

174+
if r.agentURL == nil {
175+
r.agentURL = new(url.URL)
176+
}
177+
if r.clientURL == nil {
178+
r.clientURL = new(url.URL)
179+
}
180+
176181
cmd.Options = []clibase.Option{
177182
{
178183
Name: varURL,

cli/server.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
367367

368368
// We want to print out the address the user supplied, not the
369369
// loopback device.
370-
cliui.Infof(inv.Stdout, "Started HTTP listener at", (&url.URL{Scheme: "http", Host: listenAddrStr}).String()+"\n")
370+
cliui.Info(inv.Stdout, "Started HTTP listener at", (&url.URL{Scheme: "http", Host: listenAddrStr}).String()+"\n")
371371

372372
// Set the http URL we want to use when connecting to ourselves.
373373
tcpAddr, tcpAddrValid := httpListener.Addr().(*net.TCPAddr)
@@ -431,7 +431,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
431431

432432
// We want to print out the address the user supplied, not the
433433
// loopback device.
434-
cliui.Infof(inv.Stdout, "Started TLS/HTTPS listener at", (&url.URL{Scheme: "https", Host: listenAddrStr}).String()+"\n")
434+
cliui.Info(inv.Stdout, "Started TLS/HTTPS listener at", (&url.URL{Scheme: "https", Host: listenAddrStr}).String()+"\n")
435435

436436
// Set the https URL we want to use when connecting to
437437
// ourselves.
@@ -479,7 +479,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
479479
// If the access URL is empty, we attempt to run a reverse-proxy
480480
// tunnel to make the initial setup really simple.
481481
if cfg.AccessURL.String() == "" {
482-
cliui.Infof(inv.Stdout, "Opening tunnel so workspaces can connect to your deployment. For production scenarios, specify an external access URL\n")
482+
cliui.Info(inv.Stdout, "Opening tunnel so workspaces can connect to your deployment. For production scenarios, specify an external access URL\n")
483483
tunnel, tunnelErr, err = devtunnel.New(ctxTunnel, logger.Named("devtunnel"))
484484
if err != nil {
485485
return xerrors.Errorf("create tunnel: %w", err)
@@ -986,11 +986,11 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
986986
if err != nil {
987987
cliui.Errorf(inv.Stdout, "\nFailed to check for the first user: "+err.Error()+"\n")
988988
} else if !hasFirstUser {
989-
cliui.Infof(inv.Stdout, "\nGet started by creating the first user (in a new terminal):"+"\n")
990-
cliui.Infof(inv.Stdout, cliui.Styles.Code.Render("coder login "+cfg.AccessURL.String())+"\n")
989+
cliui.Info(inv.Stdout, "\nGet started by creating the first user (in a new terminal):"+"\n")
990+
cliui.Info(inv.Stdout, cliui.Styles.Code.Render("coder login "+cfg.AccessURL.String())+"\n")
991991
}
992992

993-
cliui.Infof(inv.Stdout, "\n==> Logs will stream in below (press ctrl+c to gracefully exit):"+"\n")
993+
cliui.Info(inv.Stdout, "\n==> Logs will stream in below (press ctrl+c to gracefully exit):"+"\n")
994994

995995
// Updates the systemd status from activating to activated.
996996
_, err = daemon.SdNotify(false, daemon.SdNotifyReady)
@@ -1038,12 +1038,12 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
10381038
// Stop accepting new connections without interrupting
10391039
// in-flight requests, give in-flight requests 5 seconds to
10401040
// complete.
1041-
cliui.Infof(inv.Stdout, "Shutting down API server..."+"\n")
1041+
cliui.Info(inv.Stdout, "Shutting down API server..."+"\n")
10421042
err = shutdownWithTimeout(httpServer.Shutdown, 3*time.Second)
10431043
if err != nil {
10441044
cliui.Errorf(inv.Stderr, "API server shutdown took longer than 3s: %s\n", err)
10451045
} else {
1046-
cliui.Infof(inv.Stdout, "Gracefully shut down API server\n")
1046+
cliui.Info(inv.Stdout, "Gracefully shut down API server\n")
10471047
}
10481048
// Cancel any remaining in-flight requests.
10491049
shutdownConns()
@@ -1078,9 +1078,9 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
10781078
}
10791079
wg.Wait()
10801080

1081-
cliui.Infof(inv.Stdout, "Waiting for WebSocket connections to close..."+"\n")
1081+
cliui.Info(inv.Stdout, "Waiting for WebSocket connections to close..."+"\n")
10821082
_ = coderAPICloser.Close()
1083-
cliui.Infof(inv.Stdout, "Done waiting for WebSocket connections"+"\n")
1083+
cliui.Info(inv.Stdout, "Done waiting for WebSocket connections"+"\n")
10841084

10851085
// Close tunnel after we no longer have in-flight connections.
10861086
if tunnel != nil {
@@ -1156,15 +1156,15 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
11561156

11571157
createAdminUserCmd := r.newCreateAdminUserCommand()
11581158

1159-
rawUrlOpt := clibase.Option{
1159+
rawURLOpt := clibase.Option{
11601160
Flag: "raw-url",
11611161
Default: "false",
11621162
Value: clibase.BoolOf(&pgRawURL),
11631163
Description: "Output the raw connection URL instead of a psql command.",
11641164
}
1165-
createAdminUserCmd.Options = append(createAdminUserCmd.Options, rawUrlOpt)
1166-
postgresBuiltinURLCmd.Options = append(postgresBuiltinURLCmd.Options, rawUrlOpt)
1167-
postgresBuiltinServeCmd.Options = append(postgresBuiltinURLCmd.Options, rawUrlOpt)
1165+
createAdminUserCmd.Options = append(createAdminUserCmd.Options, rawURLOpt)
1166+
postgresBuiltinURLCmd.Options = append(postgresBuiltinURLCmd.Options, rawURLOpt)
1167+
postgresBuiltinServeCmd.Options = append(postgresBuiltinURLCmd.Options, rawURLOpt)
11681168

11691169
serverCmd.Children = append(
11701170
serverCmd.Children,

cli/server_slim.go

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,17 @@ import (
1515

1616
func Server(_ func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error)) *clibase.Cmd {
1717
root := &clibase.Cmd{
18-
Use: "server",
19-
Short: "Start a Coder server",
20-
Hidden: true,
18+
Use: "server",
19+
Short: "Start a Coder server",
20+
// We accept RawArgs so all commands and flags are accepted.
21+
RawArgs: true,
22+
Hidden: true,
2123
Handler: func(inv *clibase.Invokation) error {
2224
serverUnsupported(inv.Stderr)
2325
return nil
2426
},
2527
}
2628

27-
var pgRawURL bool
28-
postgresBuiltinURLCmd := &clibase.Cmd{
29-
Use: "postgres-builtin-url",
30-
Short: "Output the connection URL for the built-in PostgreSQL deployment.",
31-
Hidden: true,
32-
Handler: func(inv *clibase.Invokation) error {
33-
serverUnsupported(inv.Stderr)
34-
return nil
35-
},
36-
}
37-
postgresBuiltinServeCmd := &clibase.Cmd{
38-
Use: "postgres-builtin-serve",
39-
Short: "Run the built-in PostgreSQL deployment.",
40-
Hidden: true,
41-
Handler: func(inv *clibase.Invokation) error {
42-
serverUnsupported(inv.Stderr)
43-
return nil
44-
},
45-
}
46-
47-
var (
48-
newUserDBURL string
49-
newUserSSHKeygenAlgorithm string
50-
newUserUsername string
51-
newUserEmail string
52-
newUserPassword string
53-
)
54-
createAdminUserCommand := &clibase.Cmd{
55-
Use: "create-admin-user",
56-
Short: "Create a new admin user with the given username, email and password and adds it to every organization.",
57-
Hidden: true,
58-
Handler: func(inv *clibase.Invokation) error {
59-
serverUnsupported(inv.Stderr)
60-
return nil
61-
},
62-
}
63-
64-
// We still have to attach the flags to the commands so users don't get
65-
// an error when they try to use them.
66-
postgresBuiltinURLCmd.Flags().BoolVar(&pgRawURL, "raw-url", false, "Output the raw connection URL instead of a psql command.")
67-
postgresBuiltinServeCmd.Flags().BoolVar(&pgRawURL, "raw-url", false, "Output the raw connection URL instead of a psql command.")
68-
createAdminUserCommand.Flags().StringVar(&newUserDBURL, "postgres-url", "", "URL of a PostgreSQL database. If empty, the built-in PostgreSQL deployment will be used (Coder must not be already running in this case). Consumes $CODER_POSTGRES_URL.")
69-
createAdminUserCommand.Flags().StringVar(&newUserSSHKeygenAlgorithm, "ssh-keygen-algorithm", "ed25519", "The algorithm to use for generating ssh keys. Accepted values are \"ed25519\", \"ecdsa\", or \"rsa4096\". Consumes $CODER_SSH_KEYGEN_ALGORITHM.")
70-
createAdminUserCommand.Flags().StringVar(&newUserUsername, "username", "", "The username of the new user. If not specified, you will be prompted via stdin. Consumes $CODER_USERNAME.")
71-
createAdminUserCommand.Flags().StringVar(&newUserEmail, "email", "", "The email of the new user. If not specified, you will be prompted via stdin. Consumes $CODER_EMAIL.")
72-
createAdminUserCommand.Flags().StringVar(&newUserPassword, "password", "", "The password of the new user. If not specified, you will be prompted via stdin. Consumes $CODER_PASSWORD.")
73-
74-
root.AddCommand(postgresBuiltinURLCmd, postgresBuiltinServeCmd, createAdminUserCommand)
75-
7629
return root
7730
}
7831

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ require (
5858
cdr.dev/slog v1.4.2-0.20230228204227-60d22dceaf04
5959
cloud.google.com/go/compute/metadata v0.2.1
6060
github.com/AlecAivazis/survey/v2 v2.3.5
61-
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
6261
github.com/adrg/xdg v0.4.0
6362
github.com/andybalholm/brotli v1.0.4
6463
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2
@@ -73,7 +72,6 @@ require (
7372
github.com/charmbracelet/lipgloss v0.6.0
7473
github.com/cli/safeexec v1.0.0
7574
github.com/codeclysm/extract v2.2.0+incompatible
76-
github.com/coder/flog v1.0.0
7775
github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d
7876
github.com/coder/terraform-provider-coder v0.6.15
7977
github.com/coreos/go-oidc/v3 v3.4.0

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdko
165165
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
166166
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
167167
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
168-
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
169-
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
170168
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
171169
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
172170
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
@@ -366,8 +364,6 @@ github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoC
366364
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
367365
github.com/codeclysm/extract v2.2.0+incompatible h1:q3wyckoA30bhUSiwdQezMqVhwd8+WGE64/GL//LtUhI=
368366
github.com/codeclysm/extract v2.2.0+incompatible/go.mod h1:2nhFMPHiU9At61hz+12bfrlpXSUrOnK+wR+KlGO4Uks=
369-
github.com/coder/flog v1.0.0 h1:gqr4jYDQWYmsvFD0RV6Vs+SAj1Kbn0HGlV7UghfxP+8=
370-
github.com/coder/flog v1.0.0/go.mod h1:UQlQvrkJBvnRGo69Le8E24Tcl5SJleAAR7gYEHzAmdQ=
371367
github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1 h1:UqBrPWSYvRI2s5RtOul20JukUEpu4ip9u7biBL+ntgk=
372368
github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
373369
github.com/coder/go-scim/pkg/v2 v2.0.0-20230221055123-1d63c1222136 h1:0RgB61LcNs24WOxc3PBvygSNTQurm0PYPujJjLLOzs0=

0 commit comments

Comments
 (0)