Skip to content

Commit 913d141

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevenmasley/rbac
2 parents 5a2834a + 4dd3c57 commit 913d141

File tree

113 files changed

+4404
-3262
lines changed

Some content is hidden

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

113 files changed

+4404
-3262
lines changed

.github/dependabot.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ updates:
2727
- package-ecosystem: "gomod"
2828
directory: "/"
2929
schedule:
30-
interval: "daily"
30+
interval: "weekly"
3131
time: "06:00"
3232
timezone: "America/Chicago"
3333
commit-message:
@@ -36,7 +36,7 @@ updates:
3636
- package-ecosystem: "npm"
3737
directory: "/site/"
3838
schedule:
39-
interval: "daily"
39+
interval: "weekly"
4040
time: "06:00"
4141
timezone: "America/Chicago"
4242
commit-message:

.github/semantic.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
# https://www.notion.so/coderhq/Conventional-commits-1d51287f58b64026bb29393f277734ed
88
###############################################################################
99

10+
# We have no valid scopes right now.
11+
# A scope should be added when commits aren't aligning with associated change anymore.
12+
scopes:
13+
1014
# We only check that the PR title is semantic. The PR title is automatically
1115
# applied to the "Squash & Merge" flow as the suggested commit message, so this
1216
# should suffice unless someone drastically alters the message in that flow.

.github/workflows/coder.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ jobs:
8989

9090
- run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
9191
- run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.26
92+
- run: go install golang.org/x/tools/cmd/goimports@latest
9293
- run: "make --output-sync -j gen"
9394
- run: ./scripts/check_unstaged.sh
9495

@@ -323,6 +324,17 @@ jobs:
323324
with:
324325
install-only: true
325326

327+
- name: Cache Node
328+
id: cache-node
329+
uses: actions/cache@v3
330+
with:
331+
path: |
332+
**/node_modules
333+
.eslintcache
334+
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
335+
restore-keys: |
336+
js-${{ runner.os }}-
337+
326338
- name: Build Release
327339
run: make release
328340

.github/workflows/release.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,38 @@ jobs:
1414
with:
1515
go-version: "~1.18"
1616

17+
- name: Echo Go Cache Paths
18+
id: go-cache-paths
19+
run: |
20+
echo "::set-output name=go-build::$(go env GOCACHE)"
21+
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
22+
23+
- name: Go Build Cache
24+
uses: actions/cache@v3
25+
with:
26+
path: ${{ steps.go-cache-paths.outputs.go-build }}
27+
key: ${{ runner.os }}-release-go-build-${{ hashFiles('**/go.sum') }}
28+
29+
- name: Go Mod Cache
30+
uses: actions/cache@v3
31+
with:
32+
path: ${{ steps.go-cache-paths.outputs.go-mod }}
33+
key: ${{ runner.os }}-release-go-mod-${{ hashFiles('**/go.sum') }}
34+
35+
- name: Cache Node
36+
id: cache-node
37+
uses: actions/cache@v3
38+
with:
39+
path: |
40+
**/node_modules
41+
.eslintcache
42+
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
43+
restore-keys: |
44+
js-${{ runner.os }}-
45+
46+
- name: Build Site
47+
run: make site/out
48+
1749
- name: Run GoReleaser
1850
uses: goreleaser/goreleaser-action@v2.9.1
1951
with:

.golangci.yml

+7-21
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,6 @@ linters-settings:
177177
- name: var-declaration
178178
- name: var-naming
179179
- name: waitgroup-by-value
180-
varnamelen:
181-
ignore-names:
182-
- err
183-
- rw
184-
- r
185-
- i
186-
- db
187-
- t
188-
- id
189-
- wg
190-
# Optional list of variable declarations that should be ignored completely. (defaults to empty list)
191-
# Entries must be in the form of "<variable name> <type>" or "<variable name> *<type>" for
192-
# variables, or "const <name>" for constants.
193-
ignore-decls:
194-
- rw http.ResponseWriter
195-
- r *http.Request
196-
- t testing.T
197-
- t testing.TB
198-
- ok bool
199-
- wg sync.WaitGroup
200180

201181
issues:
202182
# Rules listed here: https://github.com/securego/gosec#available-rules
@@ -251,11 +231,17 @@ linters:
251231
- staticcheck
252232
- structcheck
253233
- tenv
234+
# In Go, it's possible for a package to test it's internal functionality
235+
# without testing any exported functions. This is enabled to promote
236+
# decomposing a package before testing it's internals. A function caller
237+
# should be able to test most of the functionality from exported functions.
238+
#
239+
# There are edge-cases to this rule, but they should be carefully considered
240+
# to avoid structural inconsistency.
254241
- testpackage
255242
- tparallel
256243
- typecheck
257244
- unconvert
258245
- unused
259246
- varcheck
260-
- varnamelen
261247
- wastedassign

.goreleaser.yml

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ archives:
44
- coder
55
files:
66
- README.md
7+
format_overrides:
8+
- goos: windows
9+
format: zip
710

811
before:
912
hooks:

Makefile

+15-11
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ build: site/out bin
1212
# Runs migrations to output a dump of the database.
1313
coderd/database/dump.sql: $(wildcard coderd/database/migrations/*.sql)
1414
go run coderd/database/dump/main.go
15+
.PHONY: coderd/database/dump.sql
1516

1617
# Generates Go code for querying the database.
17-
coderd/database/generate: fmt/sql coderd/database/dump.sql coderd/database/query.sql
18-
cd coderd/database && sqlc generate && rm db_tmp.go
19-
cd coderd/database && gofmt -w -r 'Querier -> querier' *.go
20-
cd coderd/database && gofmt -w -r 'Queries -> sqlQuerier' *.go
18+
coderd/database/generate: fmt/sql coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql)
19+
coderd/database/generate.sh
2120
.PHONY: coderd/database/generate
2221

2322
fmt/prettier:
@@ -30,13 +29,18 @@ else
3029
endif
3130
.PHONY: fmt/prettier
3231

33-
fmt/sql: ./coderd/database/query.sql
34-
npx sql-formatter \
35-
--language postgresql \
36-
--lines-between-queries 2 \
37-
./coderd/database/query.sql \
38-
--output ./coderd/database/query.sql
39-
sed -i 's/@ /@/g' ./coderd/database/query.sql
32+
fmt/sql: $(wildcard coderd/database/queries/*.sql)
33+
# TODO: this is slightly slow
34+
for fi in coderd/database/queries/*.sql; do \
35+
npx sql-formatter \
36+
--language postgresql \
37+
--lines-between-queries 2 \
38+
--tab-indent \
39+
$$fi \
40+
--output $$fi; \
41+
done
42+
43+
sed -i 's/@ /@/g' ./coderd/database/queries/*.sql
4044

4145
fmt: fmt/prettier fmt/sql
4246
.PHONY: fmt

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ $ coder workspaces create my-first-workspace
5151
$ coder ssh my-first-workspace
5252
```
5353

54+
### Working with Projects
55+
56+
You can edit the Terraform from a sample project:
57+
58+
```sh
59+
$ coder projects init
60+
$ cd gcp-linux/
61+
$ vim main.tf
62+
$ coder projects update gcp-linux
63+
```
64+
5465
## Development
5566

5667
The code structure is inspired by [Basics of Unix Philosophy](https://homepage.cs.uri.edu/~thenry/resources/unix_art/ch01s06.html) and [Effective Go](https://go.dev/doc/effective_go).

cli/cliui/cliui_darwin.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//go:build darwin
2+
// +build darwin
3+
4+
package cliui
5+
6+
import (
7+
"golang.org/x/sys/unix"
8+
9+
"golang.org/x/xerrors"
10+
)
11+
12+
func removeLineLengthLimit(inputFD int) (func(), error) {
13+
termios, err := unix.IoctlGetTermios(inputFD, unix.TIOCGETA)
14+
if err != nil {
15+
return nil, xerrors.Errorf("get termios: %w", err)
16+
}
17+
newState := *termios
18+
// MacOS has a default line limit of 1024. See:
19+
// https://unix.stackexchange.com/questions/204815/terminal-does-not-accept-pasted-or-typed-lines-of-more-than-1024-characters
20+
//
21+
// This removes canonical input processing, so deletes will not function
22+
// as expected. This _seems_ fine for most use-cases, but is unfortunate.
23+
newState.Lflag &^= unix.ICANON
24+
err = unix.IoctlSetTermios(inputFD, unix.TIOCSETA, &newState)
25+
if err != nil {
26+
return nil, xerrors.Errorf("set termios: %w", err)
27+
}
28+
return func() {
29+
_ = unix.IoctlSetTermios(inputFD, unix.TIOCSETA, termios)
30+
}, nil
31+
}

cli/cliui/cliui_other.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build !darwin
2+
// +build !darwin
3+
4+
package cliui
5+
6+
import "golang.org/x/xerrors"
7+
8+
func removeLineLengthLimit(_ int) (func(), error) {
9+
return nil, xerrors.New("not implemented")
10+
}

cli/cliui/prompt.go

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"os"
1010
"os/signal"
11+
"runtime"
1112
"strings"
1213

1314
"github.com/bgentry/speakeasy"
@@ -42,10 +43,21 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
4243
go func() {
4344
var line string
4445
var err error
46+
4547
inFile, valid := cmd.InOrStdin().(*os.File)
4648
if opts.Secret && valid && isatty.IsTerminal(inFile.Fd()) {
4749
line, err = speakeasy.Ask("")
4850
} else {
51+
if runtime.GOOS == "darwin" && valid {
52+
var restore func()
53+
restore, err = removeLineLengthLimit(int(inFile.Fd()))
54+
if err != nil {
55+
errCh <- err
56+
return
57+
}
58+
defer restore()
59+
}
60+
4961
reader := bufio.NewReader(cmd.InOrStdin())
5062
line, err = reader.ReadString('\n')
5163

cli/configssh.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func configSSH() *cobra.Command {
5252
sshConfigContent = sshConfigContent[:startIndex-1] + sshConfigContent[endIndex+len(sshEndToken):]
5353
}
5454

55-
workspaces, err := client.WorkspacesByUser(cmd.Context(), "")
55+
workspaces, err := client.WorkspacesByUser(cmd.Context(), codersdk.Me)
5656
if err != nil {
5757
return err
5858
}

cli/configssh_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import (
44
"os"
55
"testing"
66

7+
"github.com/stretchr/testify/require"
8+
79
"github.com/coder/coder/cli/clitest"
810
"github.com/coder/coder/coderd/coderdtest"
11+
"github.com/coder/coder/codersdk"
912
"github.com/coder/coder/pty/ptytest"
10-
"github.com/stretchr/testify/require"
1113
)
1214

1315
func TestConfigSSH(t *testing.T) {
@@ -20,7 +22,7 @@ func TestConfigSSH(t *testing.T) {
2022
version := coderdtest.CreateProjectVersion(t, client, user.OrganizationID, nil)
2123
coderdtest.AwaitProjectVersionJob(t, client, version.ID)
2224
project := coderdtest.CreateProject(t, client, user.OrganizationID, version.ID)
23-
workspace := coderdtest.CreateWorkspace(t, client, "", project.ID)
25+
workspace := coderdtest.CreateWorkspace(t, client, codersdk.Me, project.ID)
2426
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
2527
tempFile, err := os.CreateTemp(t.TempDir(), "")
2628
require.NoError(t, err)

cli/login.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ func login() *cobra.Command {
119119
}
120120

121121
_, err = client.CreateFirstUser(cmd.Context(), codersdk.CreateFirstUserRequest{
122-
Email: email,
123-
Username: username,
124-
Organization: username,
125-
Password: password,
122+
Email: email,
123+
Username: username,
124+
OrganizationName: username,
125+
Password: password,
126126
})
127127
if err != nil {
128128
return xerrors.Errorf("create initial user: %w", err)
@@ -167,7 +167,7 @@ func login() *cobra.Command {
167167
Secret: true,
168168
Validate: func(token string) error {
169169
client.SessionToken = token
170-
_, err := client.User(cmd.Context(), "me")
170+
_, err := client.User(cmd.Context(), codersdk.Me)
171171
if err != nil {
172172
return xerrors.New("That's not a valid token!")
173173
}
@@ -180,7 +180,7 @@ func login() *cobra.Command {
180180

181181
// Login to get user data - verify it is OK before persisting
182182
client.SessionToken = sessionToken
183-
resp, err := client.User(cmd.Context(), "me")
183+
resp, err := client.User(cmd.Context(), codersdk.Me)
184184
if err != nil {
185185
return xerrors.Errorf("get user: %w", err)
186186
}

0 commit comments

Comments
 (0)