Skip to content

Commit b06dcad

Browse files
committed
Merge branch 'main' into dean/app-urls-use-slug
2 parents b53611f + 90f77a3 commit b06dcad

File tree

109 files changed

+2572
-1242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2572
-1242
lines changed

agent/agent.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
242242
if err != nil {
243243
return nil, xerrors.Errorf("listen on the ssh port: %w", err)
244244
}
245+
a.closeMutex.Lock()
246+
a.connCloseWait.Add(1)
247+
a.closeMutex.Unlock()
245248
go func() {
249+
defer a.connCloseWait.Done()
246250
for {
247251
conn, err := sshListener.Accept()
248252
if err != nil {
@@ -256,7 +260,11 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
256260
if err != nil {
257261
return nil, xerrors.Errorf("listen for reconnecting pty: %w", err)
258262
}
263+
a.closeMutex.Lock()
264+
a.connCloseWait.Add(1)
265+
a.closeMutex.Unlock()
259266
go func() {
267+
defer a.connCloseWait.Done()
260268
for {
261269
conn, err := reconnectingPTYListener.Accept()
262270
if err != nil {
@@ -290,7 +298,11 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
290298
if err != nil {
291299
return nil, xerrors.Errorf("listen for speedtest: %w", err)
292300
}
301+
a.closeMutex.Lock()
302+
a.connCloseWait.Add(1)
303+
a.closeMutex.Unlock()
293304
go func() {
305+
defer a.connCloseWait.Done()
294306
for {
295307
conn, err := speedtestListener.Accept()
296308
if err != nil {
@@ -311,7 +323,11 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
311323
if err != nil {
312324
return nil, xerrors.Errorf("listen for statistics: %w", err)
313325
}
326+
a.closeMutex.Lock()
327+
a.connCloseWait.Add(1)
328+
a.closeMutex.Unlock()
314329
go func() {
330+
defer a.connCloseWait.Done()
315331
defer statisticsListener.Close()
316332
server := &http.Server{
317333
Handler: a.statisticsHandler(),

agent/agent_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"os/exec"
1313
"os/user"
14+
"path"
1415
"path/filepath"
1516
"runtime"
1617
"strconv"
@@ -231,7 +232,13 @@ func TestAgent(t *testing.T) {
231232
require.NoError(t, err, "get working directory")
232233
require.Equal(t, home, wd, "working directory should be home user home")
233234
tempFile := filepath.Join(t.TempDir(), "sftp")
234-
file, err := client.Create(tempFile)
235+
// SFTP only accepts unix-y paths.
236+
remoteFile := filepath.ToSlash(tempFile)
237+
if !path.IsAbs(remoteFile) {
238+
// On Windows, e.g. "/C:/Users/...".
239+
remoteFile = path.Join("/", remoteFile)
240+
}
241+
file, err := client.Create(remoteFile)
235242
require.NoError(t, err)
236243
err = file.Close()
237244
require.NoError(t, err)

cli/cliui/provisionerjob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
103103
}
104104
updateStage("Running", *job.StartedAt)
105105
}
106-
updateJob()
107106

108107
if opts.Cancel != nil {
109108
// Handles ctrl+c to cancel a job.
@@ -131,6 +130,7 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
131130

132131
// The initial stage needs to print after the signal handler has been registered.
133132
printStage()
133+
updateJob()
134134

135135
logs, closer, err := opts.Logs()
136136
if err != nil {

cli/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func create() *cobra.Command {
3333
return err
3434
}
3535

36-
organization, err := currentOrganization(cmd, client)
36+
organization, err := CurrentOrganization(cmd, client)
3737
if err != nil {
3838
return err
3939
}

cli/deployment/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,14 +462,20 @@ func readSliceFromViper[T any](vip *viper.Viper, key string, value any) []T {
462462
if prop == "-" {
463463
prop = fve.Tag.Get("yaml")
464464
}
465-
value := vip.Get(fmt.Sprintf("%s.%d.%s", key, entry, prop))
465+
configKey := fmt.Sprintf("%s.%d.%s", key, entry, prop)
466+
value := vip.Get(configKey)
466467
if value == nil {
467468
continue
468469
}
469470
if instance == nil {
470471
newType := reflect.Indirect(reflect.New(elementType))
471472
instance = &newType
472473
}
474+
switch instance.Field(i).Type().String() {
475+
case "[]string":
476+
value = vip.GetStringSlice(configKey)
477+
default:
478+
}
473479
instance.Field(i).Set(reflect.ValueOf(value))
474480
}
475481
if instance == nil {

cli/deployment/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func TestConfig(t *testing.T) {
158158
"CODER_GITAUTH_0_AUTH_URL": "https://auth.com",
159159
"CODER_GITAUTH_0_TOKEN_URL": "https://token.com",
160160
"CODER_GITAUTH_0_REGEX": "github.com",
161+
"CODER_GITAUTH_0_SCOPES": "read write",
161162

162163
"CODER_GITAUTH_1_ID": "another",
163164
"CODER_GITAUTH_1_TYPE": "gitlab",
@@ -177,6 +178,7 @@ func TestConfig(t *testing.T) {
177178
AuthURL: "https://auth.com",
178179
TokenURL: "https://token.com",
179180
Regex: "github.com",
181+
Scopes: []string{"read", "write"},
180182
}, {
181183
ID: "another",
182184
Type: "gitlab",

cli/login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func login() *cobra.Command {
8686
return xerrors.Errorf("Failed to check server %q for first user, is the URL correct and is coder accessible from your browser? Error - has initial user: %w", serverURL.String(), err)
8787
}
8888
if !hasInitialUser {
89-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"Your Coder deployment hasn't been set up!\n")
89+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Caret+"Your Coder deployment hasn't been set up!\n")
9090

9191
if username == "" {
9292
if !isTTY(cmd) {
@@ -244,7 +244,7 @@ func login() *cobra.Command {
244244
return xerrors.Errorf("write server url: %w", err)
245245
}
246246

247-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"Welcome to Coder, %s! You're authenticated.\n", cliui.Styles.Keyword.Render(resp.Username))
247+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Caret+"Welcome to Coder, %s! You're authenticated.\n", cliui.Styles.Keyword.Render(resp.Username))
248248
return nil
249249
},
250250
}

cli/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func logout() *cobra.Command {
6767
errorString := strings.TrimRight(errorStringBuilder.String(), "\n")
6868
return xerrors.New("Failed to log out.\n" + errorString)
6969
}
70-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"You are no longer logged in. You can log in using 'coder login <url>'.\n")
70+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Caret+"You are no longer logged in. You can log in using 'coder login <url>'.\n")
7171
return nil
7272
},
7373
}

cli/parameterslist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func parameterList() *cobra.Command {
2727
return err
2828
}
2929

30-
organization, err := currentOrganization(cmd, client)
30+
organization, err := CurrentOrganization(cmd, client)
3131
if err != nil {
3232
return xerrors.Errorf("get current organization: %w", err)
3333
}

cli/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
var (
33-
caret = cliui.Styles.Prompt.String()
33+
Caret = cliui.Styles.Prompt.String()
3434

3535
// Applied as annotations to workspace commands
3636
// so they display in a separated "help" section.
@@ -352,8 +352,8 @@ func createAgentClient(cmd *cobra.Command) (*codersdk.Client, error) {
352352
return client, nil
353353
}
354354

355-
// currentOrganization returns the currently active organization for the authenticated user.
356-
func currentOrganization(cmd *cobra.Command, client *codersdk.Client) (codersdk.Organization, error) {
355+
// CurrentOrganization returns the currently active organization for the authenticated user.
356+
func CurrentOrganization(cmd *cobra.Command, client *codersdk.Client) (codersdk.Organization, error) {
357357
orgs, err := client.OrganizationsByUser(cmd.Context(), codersdk.Me)
358358
if err != nil {
359359
return codersdk.Organization{}, nil

0 commit comments

Comments
 (0)