Skip to content

Commit 8da592a

Browse files
committed
Merge branch 'main' into bq/refactor-rename-feature
2 parents 4ce0baf + b412ef0 commit 8da592a

File tree

147 files changed

+2599
-1894
lines changed

Some content is hidden

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

147 files changed

+2599
-1894
lines changed

.github/workflows/ci.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ jobs:
506506
507507
- uses: actions/setup-node@v3
508508
with:
509-
node-version: "14"
509+
node-version: "16.16.0"
510510

511511
- name: Install node_modules
512512
run: ./scripts/yarn_install.sh
@@ -555,7 +555,7 @@ jobs:
555555

556556
- uses: actions/setup-node@v3
557557
with:
558-
node-version: "14"
558+
node-version: "16.16.0"
559559

560560
- name: Echo Go Cache Paths
561561
id: go-cache-paths
@@ -609,6 +609,10 @@ jobs:
609609
# only get 1 commit on shallow checkout.
610610
fetch-depth: 0
611611

612+
- uses: actions/setup-node@v3
613+
with:
614+
node-version: "16.16.0"
615+
612616
- name: Install dependencies
613617
run: cd site && yarn
614618

Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,15 @@ install: build/coder_$(VERSION)_$(GOOS)_$(GOARCH)$(GOOS_BIN_EXT)
368368
cp "$<" "$$output_file"
369369
.PHONY: install
370370

371-
fmt: fmt/prettier fmt/terraform fmt/shfmt
371+
fmt: fmt/prettier fmt/terraform fmt/shfmt fmt/go
372372
.PHONY: fmt
373373

374+
fmt/go:
375+
# VS Code users should check out
376+
# https://github.com/mvdan/gofumpt#visual-studio-code
377+
go run mvdan.cc/gofumpt@v0.4.0 -w -l .
378+
.PHONY: fmt/go
379+
374380
fmt/prettier:
375381
echo "--- prettier"
376382
cd site

agent/ssh.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (h *forwardedUnixHandler) HandleSSHRequest(ctx ssh.Context, _ *ssh.Server,
7070

7171
// Create socket parent dir if not exists.
7272
parentDir := filepath.Dir(addr)
73-
err = os.MkdirAll(parentDir, 0700)
73+
err = os.MkdirAll(parentDir, 0o700)
7474
if err != nil {
7575
h.log.Warn(ctx, "create parent dir for SSH unix forward request",
7676
slog.F("parent_dir", parentDir),

cli/clitest/clitest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func extractTar(t *testing.T, data []byte, directory string) {
7878
path := filepath.Join(directory, header.Name)
7979
mode := header.FileInfo().Mode()
8080
if mode == 0 {
81-
mode = 0600
81+
mode = 0o600
8282
}
8383
switch header.Typeflag {
8484
case tar.TypeDir:

cli/config/file.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (f File) Delete() error {
6060

6161
// Write writes the string to the file.
6262
func (f File) Write(s string) error {
63-
return write(string(f), 0600, []byte(s))
63+
return write(string(f), 0o600, []byte(s))
6464
}
6565

6666
// Read reads the file to a string.
@@ -72,7 +72,7 @@ func (f File) Read() (string, error) {
7272
// open opens a file in the configuration directory,
7373
// creating all intermediate directories.
7474
func open(path string, flag int, mode os.FileMode) (*os.File, error) {
75-
err := os.MkdirAll(filepath.Dir(path), 0750)
75+
err := os.MkdirAll(filepath.Dir(path), 0o750)
7676
if err != nil {
7777
return nil, err
7878
}

cli/create_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ func TestCreateWithRichParameters(t *testing.T) {
351351
},
352352
},
353353
},
354-
}},
354+
},
355+
},
355356
ProvisionApply: []*proto.Provision_Response{{
356357
Type: &proto.Provision_Response_Complete{
357358
Complete: &proto.Provision_Complete{},
@@ -475,7 +476,8 @@ func TestCreateValidateRichParameters(t *testing.T) {
475476
Parameters: richParameters,
476477
},
477478
},
478-
}},
479+
},
480+
},
479481
ProvisionApply: []*proto.Provision_Response{
480482
{
481483
Type: &proto.Provision_Response_Complete{

cli/dotfiles.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func dotfiles() *cobra.Command {
111111
}
112112

113113
// ensure command dir exists
114-
err = os.MkdirAll(gitCmdDir, 0750)
114+
err = os.MkdirAll(gitCmdDir, 0o750)
115115
if err != nil {
116116
return xerrors.Errorf("ensuring dir at %s: %w", gitCmdDir, err)
117117
}

cli/dotfiles_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestDotfiles(t *testing.T) {
2727
testRepo := testGitRepo(t, root)
2828

2929
// nolint:gosec
30-
err := os.WriteFile(filepath.Join(testRepo, ".bashrc"), []byte("wow"), 0750)
30+
err := os.WriteFile(filepath.Join(testRepo, ".bashrc"), []byte("wow"), 0o750)
3131
require.NoError(t, err)
3232

3333
c := exec.Command("git", "add", ".bashrc")
@@ -56,7 +56,7 @@ func TestDotfiles(t *testing.T) {
5656
testRepo := testGitRepo(t, root)
5757

5858
// nolint:gosec
59-
err := os.WriteFile(filepath.Join(testRepo, "install.sh"), []byte("#!/bin/bash\necho wow > "+filepath.Join(string(root), ".bashrc")), 0750)
59+
err := os.WriteFile(filepath.Join(testRepo, "install.sh"), []byte("#!/bin/bash\necho wow > "+filepath.Join(string(root), ".bashrc")), 0o750)
6060
require.NoError(t, err)
6161

6262
c := exec.Command("git", "add", "install.sh")
@@ -82,12 +82,12 @@ func TestDotfiles(t *testing.T) {
8282
testRepo := testGitRepo(t, root)
8383

8484
// nolint:gosec
85-
err := os.WriteFile(filepath.Join(testRepo, ".bashrc"), []byte("wow"), 0750)
85+
err := os.WriteFile(filepath.Join(testRepo, ".bashrc"), []byte("wow"), 0o750)
8686
require.NoError(t, err)
8787

8888
// add a conflicting file at destination
8989
// nolint:gosec
90-
err = os.WriteFile(filepath.Join(string(root), ".bashrc"), []byte("backup"), 0750)
90+
err = os.WriteFile(filepath.Join(string(root), ".bashrc"), []byte("backup"), 0o750)
9191
require.NoError(t, err)
9292

9393
c := exec.Command("git", "add", ".bashrc")
@@ -119,7 +119,7 @@ func testGitRepo(t *testing.T, root config.Root) string {
119119
r, err := cryptorand.String(8)
120120
require.NoError(t, err)
121121
dir := filepath.Join(string(root), fmt.Sprintf("test-repo-%s", r))
122-
err = os.MkdirAll(dir, 0750)
122+
err = os.MkdirAll(dir, 0o750)
123123
require.NoError(t, err)
124124

125125
c := exec.Command("git", "init")

cli/logout_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func TestLogout(t *testing.T) {
149149
require.NoError(t, err)
150150
} else {
151151
// Changing the permissions to throw error during deletion.
152-
err = os.Chmod(string(config), 0500)
152+
err = os.Chmod(string(config), 0o500)
153153
require.NoError(t, err)
154154
}
155155
defer func() {

cli/parameter.go

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ func createParameterMapFromFile(parameterFile string) (map[string]string, error)
1818
parameterMap := make(map[string]string)
1919

2020
parameterFileContents, err := os.ReadFile(parameterFile)
21-
2221
if err != nil {
2322
return nil, err
2423
}

cli/publickey.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import (
1111
)
1212

1313
func publickey() *cobra.Command {
14-
var (
15-
reset bool
16-
)
14+
var reset bool
1715

1816
cmd := &cobra.Command{
1917
Use: "publickey",

cli/resetpassword.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import (
1515
)
1616

1717
func resetPassword() *cobra.Command {
18-
var (
19-
postgresURL string
20-
)
18+
var postgresURL string
2119

2220
root := &cobra.Command{
2321
Use: "reset-password <username>",

cli/root.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ const (
6464
envURL = "CODER_URL"
6565
)
6666

67-
var (
68-
errUnauthenticated = xerrors.New(notLoggedInMessage)
69-
)
67+
var errUnauthenticated = xerrors.New(notLoggedInMessage)
7068

7169
func init() {
7270
// Set cobra template functions in init to avoid conflicts in tests.

cli/scaletest.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ func (r *userCleanupRunner) Run(ctx context.Context, _ string, _ io.Writer) erro
309309
}
310310

311311
func scaletestCleanup() *cobra.Command {
312-
var (
313-
cleanupStrategy = &scaletestStrategyFlags{cleanup: true}
314-
)
312+
cleanupStrategy := &scaletestStrategyFlags{cleanup: true}
315313

316314
cmd := &cobra.Command{
317315
Use: "cleanup",
@@ -810,8 +808,10 @@ type runnableTraceWrapper struct {
810808
span trace.Span
811809
}
812810

813-
var _ harness.Runnable = &runnableTraceWrapper{}
814-
var _ harness.Cleanable = &runnableTraceWrapper{}
811+
var (
812+
_ harness.Runnable = &runnableTraceWrapper{}
813+
_ harness.Cleanable = &runnableTraceWrapper{}
814+
)
815815

816816
func (r *runnableTraceWrapper) Run(ctx context.Context, id string, logs io.Writer) error {
817817
ctx, span := r.tracer.Start(ctx, r.spanName, trace.WithNewRoot())

cli/server.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
976976

977977
// parseURL parses a string into a URL.
978978
func parseURL(u string) (*url.URL, error) {
979-
var (
980-
hasScheme = strings.HasPrefix(u, "http:") || strings.HasPrefix(u, "https:")
981-
)
979+
hasScheme := strings.HasPrefix(u, "http:") || strings.HasPrefix(u, "https:")
982980

983981
if !hasScheme {
984982
return nil, xerrors.Errorf("URL %q must have a scheme of either http or https", u)
@@ -1529,7 +1527,7 @@ func buildLogger(cmd *cobra.Command, cfg *codersdk.DeploymentConfig) (slog.Logge
15291527
sinks = append(sinks, sinkFn(cmd.ErrOrStderr()))
15301528

15311529
default:
1532-
fi, err := os.OpenFile(loc, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
1530+
fi, err := os.OpenFile(loc, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
15331531
if err != nil {
15341532
return xerrors.Errorf("open log file %q: %w", loc, err)
15351533
}

cli/state.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func statePull() *cobra.Command {
5858
return nil
5959
}
6060

61-
return os.WriteFile(args[1], state, 0600)
61+
return os.WriteFile(args[1], state, 0o600)
6262
},
6363
}
6464
cmd.Flags().IntVarP(&buildNumber, "build", "b", 0, "Specify a workspace build to target by name.")

cli/templateinit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func templateInit() *cobra.Command {
6767
relPath = "./" + relPath
6868
}
6969
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Extracting %s to %s...\n", cliui.Styles.Field.Render(selectedTemplate.ID), relPath)
70-
err = os.MkdirAll(directory, 0700)
70+
err = os.MkdirAll(directory, 0o700)
7171
if err != nil {
7272
return err
7373
}

cli/templatelist_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestTemplateList(t *testing.T) {
4646
}()
4747

4848
// expect that templates are listed alphabetically
49-
var templatesList = []string{firstTemplate.Name, secondTemplate.Name}
49+
templatesList := []string{firstTemplate.Name, secondTemplate.Name}
5050
sort.Strings(templatesList)
5151

5252
require.NoError(t, <-errC)

cli/templatepull.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func templatePull() *cobra.Command {
108108
}
109109
}
110110

111-
err = os.WriteFile(dest, raw, 0600)
111+
err = os.WriteFile(dest, raw, 0o600)
112112
if err != nil {
113113
return xerrors.Errorf("write to path: %w", err)
114114
}

cli/templatepull_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestTemplatePull(t *testing.T) {
9797

9898
// Create the file so that we can test that the command
9999
// warns the user before overwriting a preexisting file.
100-
fi, err := os.OpenFile(dest, os.O_CREATE|os.O_RDONLY, 0600)
100+
fi, err := os.OpenFile(dest, os.O_CREATE|os.O_RDONLY, 0o600)
101101
require.NoError(t, err)
102102
_ = fi.Close()
103103

cli/templatepush.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ func (pf *templateUploadFlags) stdin() bool {
3434
}
3535

3636
func (pf *templateUploadFlags) upload(cmd *cobra.Command, client *codersdk.Client) (*codersdk.UploadResponse, error) {
37-
var (
38-
content io.Reader
39-
)
37+
var content io.Reader
4038
if pf.stdin() {
4139
content = cmd.InOrStdin()
4240
} else {

cli/templateversions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type templateVersionRow struct {
9999
func templateVersionsToRows(activeVersionID uuid.UUID, templateVersions ...codersdk.TemplateVersion) []templateVersionRow {
100100
rows := make([]templateVersionRow, len(templateVersions))
101101
for i, templateVersion := range templateVersions {
102-
var activeStatus = ""
102+
activeStatus := ""
103103
if templateVersion.ID == activeVersionID {
104104
activeStatus = cliui.Styles.Code.Render(cliui.Styles.Keyword.Render("Active"))
105105
}

cli/tokens.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ func tokens() *cobra.Command {
4747
}
4848

4949
func createToken() *cobra.Command {
50-
var (
51-
tokenLifetime time.Duration
52-
)
50+
var tokenLifetime time.Duration
5351
cmd := &cobra.Command{
5452
Use: "create",
5553
Short: "Create a tokens",

cli/update_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ func TestUpdateWithRichParameters(t *testing.T) {
172172
},
173173
},
174174
},
175-
}},
175+
},
176+
},
176177
ProvisionApply: []*proto.Provision_Response{{
177178
Type: &proto.Provision_Response_Complete{
178179
Complete: &proto.Provision_Complete{},
@@ -269,7 +270,8 @@ func TestUpdateValidateRichParameters(t *testing.T) {
269270
Parameters: richParameters,
270271
},
271272
},
272-
}},
273+
},
274+
},
273275
ProvisionApply: []*proto.Provision_Response{
274276
{
275277
Type: &proto.Provision_Response_Complete{

cli/util.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import (
1212
"github.com/coder/coder/coderd/util/tz"
1313
)
1414

15-
var errInvalidScheduleFormat = xerrors.New("Schedule must be in the format Mon-Fri 09:00AM America/Chicago")
16-
var errInvalidTimeFormat = xerrors.New("Start time must be in the format hh:mm[am|pm] or HH:MM")
17-
var errUnsupportedTimezone = xerrors.New("The location you provided looks like a timezone. Check https://ipinfo.io for your location.")
15+
var (
16+
errInvalidScheduleFormat = xerrors.New("Schedule must be in the format Mon-Fri 09:00AM America/Chicago")
17+
errInvalidTimeFormat = xerrors.New("Start time must be in the format hh:mm[am|pm] or HH:MM")
18+
errUnsupportedTimezone = xerrors.New("The location you provided looks like a timezone. Check https://ipinfo.io for your location.")
19+
)
1820

1921
// durationDisplay formats a duration for easier display:
2022
// - Durations of 24 hours or greater are displays as Xd

cli/vscodessh.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func vscodeSSH() *cobra.Command {
7474
ctx, cancel := context.WithCancel(cmd.Context())
7575
defer cancel()
7676

77-
err = fs.MkdirAll(networkInfoDir, 0700)
77+
err = fs.MkdirAll(networkInfoDir, 0o700)
7878
if err != nil {
7979
return xerrors.Errorf("mkdir: %w", err)
8080
}
@@ -168,7 +168,7 @@ func vscodeSSH() *cobra.Command {
168168
sendErr(err)
169169
return
170170
}
171-
err = afero.WriteFile(fs, networkInfoFilePath, rawStats, 0600)
171+
err = afero.WriteFile(fs, networkInfoFilePath, rawStats, 0o600)
172172
if err != nil {
173173
sendErr(err)
174174
return

cli/vscodessh_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func TestVSCodeSSH(t *testing.T) {
4141
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
4242

4343
fs := afero.NewMemMapFs()
44-
err = afero.WriteFile(fs, "/url", []byte(client.URL.String()), 0600)
44+
err = afero.WriteFile(fs, "/url", []byte(client.URL.String()), 0o600)
4545
require.NoError(t, err)
46-
err = afero.WriteFile(fs, "/token", []byte(client.SessionToken()), 0600)
46+
err = afero.WriteFile(fs, "/token", []byte(client.SessionToken()), 0o600)
4747
require.NoError(t, err)
4848

4949
cmd, _ := clitest.New(t,

0 commit comments

Comments
 (0)