Skip to content

Commit 031134a

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevenmasley/skip_prompt
2 parents 6a4682a + 52230fa commit 031134a

File tree

89 files changed

+2374
-1173
lines changed

Some content is hidden

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

89 files changed

+2374
-1173
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
site/ @coder/frontend
2-
site/src/xServices @presleyp

.github/workflows/coder.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
- run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
106106
- run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.26
107107
- run: go install golang.org/x/tools/cmd/goimports@latest
108-
- run: "make --output-sync -j gen"
108+
- run: "make --output-sync -j -B gen"
109109
- run: ./scripts/check_unstaged.sh
110110

111111
style-fmt:
@@ -133,8 +133,7 @@ jobs:
133133
- name: Install node_modules
134134
run: ./scripts/yarn_install.sh
135135

136-
- name: "make fmt"
137-
run: "make --output-sync -j fmt"
136+
- run: "make --output-sync -j -B fmt"
138137

139138
test-go:
140139
name: "test/go"
@@ -355,7 +354,7 @@ jobs:
355354
js-${{ runner.os }}-
356355
357356
- name: Build site
358-
run: make site/out/index.html
357+
run: make -B site/out/index.html
359358

360359
- name: Build Release
361360
uses: goreleaser/goreleaser-action@v2.9.1
@@ -488,7 +487,7 @@ jobs:
488487

489488
- name: Build
490489
run: |
491-
make site/out/index.html
490+
make -B site/out/index.html
492491
493492
- run: yarn playwright:install
494493
working-directory: site

.vscode/settings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"cSpell.words": [
3+
"buildname",
34
"circbuf",
45
"cliflag",
56
"cliui",
@@ -55,6 +56,7 @@
5556
"TCGETS",
5657
"tcpip",
5758
"TCSETS",
59+
"testid",
5860
"tfexec",
5961
"tfjson",
6062
"tfstate",
@@ -76,7 +78,7 @@
7678
},
7779
{
7880
"match": "provisionerd/proto/provisionerd.proto",
79-
"cmd": "make provisionerd/proto/provisionerd.pb.go",
81+
"cmd": "make provisionerd/proto/provisionerd.pb.go"
8082
}
8183
]
8284
},
@@ -104,5 +106,5 @@
104106
},
105107
// We often use a version of TypeScript that's ahead of the version shipped
106108
// with VS Code.
107-
"typescript.tsdk": "./site/node_modules/typescript/lib",
109+
"typescript.tsdk": "./site/node_modules/typescript/lib"
108110
}

cli/agent_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ func TestWorkspaceAgent(t *testing.T) {
1919
instanceID := "instanceidentifier"
2020
certificates, metadataClient := coderdtest.NewAzureInstanceIdentity(t, instanceID)
2121
client := coderdtest.New(t, &coderdtest.Options{
22-
AzureCertificates: certificates,
22+
AzureCertificates: certificates,
23+
IncludeProvisionerD: true,
2324
})
2425
user := coderdtest.CreateFirstUser(t, client)
25-
coderdtest.NewProvisionerDaemon(t, client)
2626
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
2727
Parse: echo.ParseComplete,
2828
Provision: []*proto.Provision_Response{{
@@ -73,10 +73,10 @@ func TestWorkspaceAgent(t *testing.T) {
7373
instanceID := "instanceidentifier"
7474
certificates, metadataClient := coderdtest.NewAWSInstanceIdentity(t, instanceID)
7575
client := coderdtest.New(t, &coderdtest.Options{
76-
AWSCertificates: certificates,
76+
AWSCertificates: certificates,
77+
IncludeProvisionerD: true,
7778
})
7879
user := coderdtest.CreateFirstUser(t, client)
79-
coderdtest.NewProvisionerDaemon(t, client)
8080
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
8181
Parse: echo.ParseComplete,
8282
Provision: []*proto.Provision_Response{{
@@ -128,9 +128,9 @@ func TestWorkspaceAgent(t *testing.T) {
128128
validator, metadata := coderdtest.NewGoogleInstanceIdentity(t, instanceID, false)
129129
client := coderdtest.New(t, &coderdtest.Options{
130130
GoogleTokenValidator: validator,
131+
IncludeProvisionerD: true,
131132
})
132133
user := coderdtest.CreateFirstUser(t, client)
133-
coderdtest.NewProvisionerDaemon(t, client)
134134
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
135135
Parse: echo.ParseComplete,
136136
Provision: []*proto.Provision_Response{{

cli/autostart_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ func TestAutostart(t *testing.T) {
2222

2323
var (
2424
ctx = context.Background()
25-
client = coderdtest.New(t, nil)
26-
_ = coderdtest.NewProvisionerDaemon(t, client)
25+
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
2726
user = coderdtest.CreateFirstUser(t, client)
2827
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
2928
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
@@ -54,8 +53,7 @@ func TestAutostart(t *testing.T) {
5453

5554
var (
5655
ctx = context.Background()
57-
client = coderdtest.New(t, nil)
58-
_ = coderdtest.NewProvisionerDaemon(t, client)
56+
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
5957
user = coderdtest.CreateFirstUser(t, client)
6058
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
6159
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
@@ -99,8 +97,7 @@ func TestAutostart(t *testing.T) {
9997
t.Parallel()
10098

10199
var (
102-
client = coderdtest.New(t, nil)
103-
_ = coderdtest.NewProvisionerDaemon(t, client)
100+
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
104101
user = coderdtest.CreateFirstUser(t, client)
105102
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
106103
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
@@ -117,8 +114,7 @@ func TestAutostart(t *testing.T) {
117114
t.Parallel()
118115

119116
var (
120-
client = coderdtest.New(t, nil)
121-
_ = coderdtest.NewProvisionerDaemon(t, client)
117+
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
122118
user = coderdtest.CreateFirstUser(t, client)
123119
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
124120
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
@@ -136,8 +132,7 @@ func TestAutostart(t *testing.T) {
136132

137133
var (
138134
ctx = context.Background()
139-
client = coderdtest.New(t, nil)
140-
_ = coderdtest.NewProvisionerDaemon(t, client)
135+
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
141136
user = coderdtest.CreateFirstUser(t, client)
142137
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
143138
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)

cli/cliflag/cliflag.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"os"
1616
"strconv"
1717
"strings"
18+
"time"
1819

1920
"github.com/spf13/pflag"
2021
)
@@ -83,6 +84,23 @@ func BoolVarP(flagset *pflag.FlagSet, ptr *bool, name string, shorthand string,
8384
flagset.BoolVarP(ptr, name, shorthand, valb, fmtUsage(usage, env))
8485
}
8586

87+
// DurationVarP sets a time.Duration flag on the given flag set.
88+
func DurationVarP(flagset *pflag.FlagSet, ptr *time.Duration, name string, shorthand string, env string, def time.Duration, usage string) {
89+
val, ok := os.LookupEnv(env)
90+
if !ok || val == "" {
91+
flagset.DurationVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
92+
return
93+
}
94+
95+
valb, err := time.ParseDuration(val)
96+
if err != nil {
97+
flagset.DurationVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
98+
return
99+
}
100+
101+
flagset.DurationVarP(ptr, name, shorthand, valb, fmtUsage(usage, env))
102+
}
103+
86104
func fmtUsage(u string, env string) string {
87105
if env == "" {
88106
return fmt.Sprintf("%s.", u)

cli/cliflag/cliflag_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"strconv"
66
"testing"
7+
"time"
78

89
"github.com/spf13/pflag"
910
"github.com/stretchr/testify/require"
@@ -183,6 +184,45 @@ func TestCliflag(t *testing.T) {
183184
require.NoError(t, err)
184185
require.Equal(t, def, got)
185186
})
187+
188+
t.Run("DurationDefault", func(t *testing.T) {
189+
var ptr time.Duration
190+
flagset, name, shorthand, env, usage := randomFlag()
191+
def, _ := cryptorand.Duration()
192+
193+
cliflag.DurationVarP(flagset, &ptr, name, shorthand, env, def, usage)
194+
got, err := flagset.GetDuration(name)
195+
require.NoError(t, err)
196+
require.Equal(t, def, got)
197+
require.Contains(t, flagset.FlagUsages(), usage)
198+
require.Contains(t, flagset.FlagUsages(), fmt.Sprintf(" - consumes $%s", env))
199+
})
200+
201+
t.Run("DurationEnvVar", func(t *testing.T) {
202+
var ptr time.Duration
203+
flagset, name, shorthand, env, usage := randomFlag()
204+
envValue, _ := cryptorand.Duration()
205+
t.Setenv(env, envValue.String())
206+
def, _ := cryptorand.Duration()
207+
208+
cliflag.DurationVarP(flagset, &ptr, name, shorthand, env, def, usage)
209+
got, err := flagset.GetDuration(name)
210+
require.NoError(t, err)
211+
require.Equal(t, envValue, got)
212+
})
213+
214+
t.Run("DurationFailParse", func(t *testing.T) {
215+
var ptr time.Duration
216+
flagset, name, shorthand, env, usage := randomFlag()
217+
envValue, _ := cryptorand.String(10)
218+
t.Setenv(env, envValue)
219+
def, _ := cryptorand.Duration()
220+
221+
cliflag.DurationVarP(flagset, &ptr, name, shorthand, env, def, usage)
222+
got, err := flagset.GetDuration(name)
223+
require.NoError(t, err)
224+
require.Equal(t, def, got)
225+
})
186226
}
187227

188228
func randomFlag() (*pflag.FlagSet, string, string, string, string) {

cli/configssh_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ import (
2727
func TestConfigSSH(t *testing.T) {
2828
t.Parallel()
2929

30-
client := coderdtest.New(t, nil)
30+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
3131
user := coderdtest.CreateFirstUser(t, client)
32-
coderdtest.NewProvisionerDaemon(t, client)
3332
authToken := uuid.NewString()
3433
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
3534
Parse: echo.ParseComplete,

cli/create_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ func TestCreate(t *testing.T) {
1717
t.Parallel()
1818
t.Run("Create", func(t *testing.T) {
1919
t.Parallel()
20-
client := coderdtest.New(t, nil)
20+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
2121
user := coderdtest.CreateFirstUser(t, client)
22-
coderdtest.NewProvisionerDaemon(t, client)
2322
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
2423
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
2524
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
@@ -48,9 +47,8 @@ func TestCreate(t *testing.T) {
4847

4948
t.Run("CreateFromListWithSkip", func(t *testing.T) {
5049
t.Parallel()
51-
client := coderdtest.New(t, nil)
50+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
5251
user := coderdtest.CreateFirstUser(t, client)
53-
coderdtest.NewProvisionerDaemon(t, client)
5452
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
5553
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
5654
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
@@ -71,9 +69,8 @@ func TestCreate(t *testing.T) {
7169

7270
t.Run("FromNothing", func(t *testing.T) {
7371
t.Parallel()
74-
client := coderdtest.New(t, nil)
72+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
7573
user := coderdtest.CreateFirstUser(t, client)
76-
coderdtest.NewProvisionerDaemon(t, client)
7774
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
7875
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
7976
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
@@ -103,9 +100,8 @@ func TestCreate(t *testing.T) {
103100

104101
t.Run("WithParameter", func(t *testing.T) {
105102
t.Parallel()
106-
client := coderdtest.New(t, nil)
103+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
107104
user := coderdtest.CreateFirstUser(t, client)
108-
coderdtest.NewProvisionerDaemon(t, client)
109105

110106
defaultValue := "something"
111107
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{

cli/delete_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cli_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
8+
"github.com/coder/coder/cli/clitest"
9+
"github.com/coder/coder/coderd/coderdtest"
10+
"github.com/coder/coder/pty/ptytest"
11+
)
12+
13+
func TestDelete(t *testing.T) {
14+
t.Run("WithParameter", func(t *testing.T) {
15+
t.Parallel()
16+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
17+
user := coderdtest.CreateFirstUser(t, client)
18+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
19+
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
20+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
21+
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
22+
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
23+
cmd, root := clitest.New(t, "delete", workspace.Name)
24+
clitest.SetupConfig(t, client, root)
25+
doneChan := make(chan struct{})
26+
pty := ptytest.New(t)
27+
cmd.SetIn(pty.Input())
28+
cmd.SetOut(pty.Output())
29+
go func() {
30+
defer close(doneChan)
31+
err := cmd.Execute()
32+
require.NoError(t, err)
33+
}()
34+
pty.ExpectMatch("Cleaning Up")
35+
<-doneChan
36+
})
37+
}

cli/gitssh_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
func TestGitSSH(t *testing.T) {
2323
t.Parallel()
2424
t.Run("Dial", func(t *testing.T) {
25-
client := coderdtest.New(t, nil)
25+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
2626
user := coderdtest.CreateFirstUser(t, client)
2727

2828
// get user public key
@@ -31,9 +31,8 @@ func TestGitSSH(t *testing.T) {
3131
publicKey, _, _, _, err := gossh.ParseAuthorizedKey([]byte(keypair.PublicKey))
3232
require.NoError(t, err)
3333

34-
// setup provisioner
34+
// setup template
3535
agentToken := uuid.NewString()
36-
coderdtest.NewProvisionerDaemon(t, client)
3736
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
3837
Parse: echo.ParseComplete,
3938
ProvisionDryRun: echo.ProvisionComplete,

cli/list_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ func TestList(t *testing.T) {
1414
t.Parallel()
1515
t.Run("Single", func(t *testing.T) {
1616
t.Parallel()
17-
client := coderdtest.New(t, nil)
17+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
1818
user := coderdtest.CreateFirstUser(t, client)
19-
coderdtest.NewProvisionerDaemon(t, client)
2019
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
2120
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
2221
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

cli/logout.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
"golang.org/x/xerrors"
9+
)
10+
11+
func logout() *cobra.Command {
12+
return &cobra.Command{
13+
Use: "logout",
14+
Short: "Remove local autheticated session",
15+
RunE: func(cmd *cobra.Command, args []string) error {
16+
config := createConfig(cmd)
17+
err := os.RemoveAll(string(config))
18+
if err != nil {
19+
return xerrors.Errorf("remove files at %s: %w", config, err)
20+
}
21+
22+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"Successfully logged out.\n")
23+
return nil
24+
},
25+
}
26+
}

0 commit comments

Comments
 (0)