Skip to content

Commit fe65280

Browse files
committed
chore: update v1 schema
1 parent 6612e3c commit fe65280

Some content is hidden

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

69 files changed

+1004
-487
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ linters-settings:
187187
- t
188188
- id
189189
- wg
190+
- Me
190191
# Optional list of variable declarations that should be ignored completely. (defaults to empty list)
191192
# Entries must be in the form of "<variable name> <type>" or "<variable name> *<type>" for
192193
# variables, or "const <name>" for constants.

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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.
1718
coderd/database/generate: fmt/sql coderd/database/dump.sql coderd/database/query.sql

cli/configssh.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/coder/coder/cli/clitest"
88
"github.com/coder/coder/coderd/coderdtest"
9+
"github.com/coder/coder/codersdk"
910
"github.com/coder/coder/pty/ptytest"
1011
"github.com/stretchr/testify/require"
1112
)
@@ -20,7 +21,7 @@ func TestConfigSSH(t *testing.T) {
2021
version := coderdtest.CreateProjectVersion(t, client, user.OrganizationID, nil)
2122
coderdtest.AwaitProjectVersionJob(t, client, version.ID)
2223
project := coderdtest.CreateProject(t, client, user.OrganizationID, version.ID)
23-
workspace := coderdtest.CreateWorkspace(t, client, "", project.ID)
24+
workspace := coderdtest.CreateWorkspace(t, client, codersdk.Me, project.ID)
2425
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
2526
tempFile, err := os.CreateTemp(t.TempDir(), "")
2627
require.NoError(t, err)

cli/login.go

Lines changed: 6 additions & 6 deletions
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
}

cli/parameters.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"context"
55

6+
"github.com/google/uuid"
67
"github.com/spf13/cobra"
78
"golang.org/x/xerrors"
89

@@ -20,42 +21,45 @@ func parameters() *cobra.Command {
2021
return cmd
2122
}
2223

23-
func parseScopeAndID(ctx context.Context, client *codersdk.Client, organization codersdk.Organization, rawScope string, name string) (codersdk.ParameterScope, string, error) {
24+
func parseScopeAndID(ctx context.Context, client *codersdk.Client, organization codersdk.Organization, rawScope string, name string) (codersdk.ParameterScope, uuid.UUID, error) {
2425
scope, err := parseParameterScope(rawScope)
2526
if err != nil {
26-
return scope, "", err
27+
return scope, uuid.Nil, err
2728
}
28-
var scopeID string
29+
30+
var scopeID uuid.UUID
2931
switch scope {
3032
case codersdk.ParameterOrganization:
3133
if name == "" {
3234
scopeID = organization.ID
3335
} else {
34-
org, err := client.OrganizationByName(ctx, "", name)
36+
org, err := client.OrganizationByName(ctx, codersdk.Me, name)
3537
if err != nil {
36-
return scope, "", err
38+
return scope, uuid.Nil, err
3739
}
3840
scopeID = org.ID
3941
}
4042
case codersdk.ParameterProject:
4143
project, err := client.ProjectByName(ctx, organization.ID, name)
4244
if err != nil {
43-
return scope, "", err
45+
return scope, uuid.Nil, err
4446
}
45-
scopeID = project.ID.String()
47+
scopeID = project.ID
4648
case codersdk.ParameterUser:
47-
user, err := client.User(ctx, name)
49+
uid, _ := uuid.Parse(name)
50+
user, err := client.User(ctx, uid)
4851
if err != nil {
49-
return scope, "", err
52+
return scope, uuid.Nil, err
5053
}
5154
scopeID = user.ID
5255
case codersdk.ParameterWorkspace:
53-
workspace, err := client.WorkspaceByName(ctx, "", name)
56+
workspace, err := client.WorkspaceByName(ctx, codersdk.Me, name)
5457
if err != nil {
55-
return scope, "", err
58+
return scope, uuid.Nil, err
5659
}
57-
scopeID = workspace.ID.String()
60+
scopeID = workspace.ID
5861
}
62+
5963
return scope, scopeID, nil
6064
}
6165

cli/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
107107

108108
// currentOrganization returns the currently active organization for the authenticated user.
109109
func currentOrganization(cmd *cobra.Command, client *codersdk.Client) (codersdk.Organization, error) {
110-
orgs, err := client.OrganizationsByUser(cmd.Context(), "me")
110+
orgs, err := client.OrganizationsByUser(cmd.Context(), codersdk.Me)
111111
if err != nil {
112112
return codersdk.Organization{}, nil
113113
}

cli/ssh.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import (
1313
gossh "golang.org/x/crypto/ssh"
1414
"golang.org/x/xerrors"
1515

16+
"golang.org/x/crypto/ssh/terminal"
17+
1618
"github.com/coder/coder/cli/cliflag"
1719
"github.com/coder/coder/cli/cliui"
1820
"github.com/coder/coder/coderd/database"
1921
"github.com/coder/coder/codersdk"
20-
"golang.org/x/crypto/ssh/terminal"
2122
)
2223

2324
func ssh() *cobra.Command {
@@ -31,33 +32,40 @@ func ssh() *cobra.Command {
3132
if err != nil {
3233
return err
3334
}
34-
workspace, err := client.WorkspaceByName(cmd.Context(), "", args[0])
35+
36+
workspace, err := client.WorkspaceByName(cmd.Context(), codersdk.Me, args[0])
3537
if err != nil {
3638
return err
3739
}
40+
3841
if workspace.LatestBuild.Transition != database.WorkspaceTransitionStart {
3942
return xerrors.New("workspace must be in start transition to ssh")
4043
}
44+
4145
if workspace.LatestBuild.Job.CompletedAt == nil {
4246
err = cliui.WorkspaceBuild(cmd.Context(), cmd.ErrOrStderr(), client, workspace.LatestBuild.ID, workspace.CreatedAt)
4347
if err != nil {
4448
return err
4549
}
4650
}
51+
4752
if workspace.LatestBuild.Transition == database.WorkspaceTransitionDelete {
4853
return xerrors.New("workspace is deleting...")
4954
}
55+
5056
resources, err := client.WorkspaceResourcesByBuild(cmd.Context(), workspace.LatestBuild.ID)
5157
if err != nil {
5258
return err
5359
}
60+
5461
resourceByAddress := make(map[string]codersdk.WorkspaceResource)
5562
for _, resource := range resources {
5663
if resource.Agent == nil {
5764
continue
5865
}
5966
resourceByAddress[resource.Address] = resource
6067
}
68+
6169
var resourceAddress string
6270
if len(args) >= 2 {
6371
resourceAddress = args[1]
@@ -72,6 +80,7 @@ func ssh() *cobra.Command {
7280
break
7381
}
7482
}
83+
7584
resource, exists := resourceByAddress[resourceAddress]
7685
if !exists {
7786
resourceKeys := make([]string, 0)
@@ -99,6 +108,7 @@ func ssh() *cobra.Command {
99108
return err
100109
}
101110
defer conn.Close()
111+
102112
if stdio {
103113
rawSSH, err := conn.SSH()
104114
if err != nil {
@@ -134,13 +144,16 @@ func ssh() *cobra.Command {
134144
if err != nil {
135145
return err
136146
}
147+
137148
sshSession.Stdin = cmd.InOrStdin()
138149
sshSession.Stdout = cmd.OutOrStdout()
139150
sshSession.Stderr = cmd.OutOrStdout()
151+
140152
err = sshSession.Shell()
141153
if err != nil {
142154
return err
143155
}
156+
144157
err = sshSession.Wait()
145158
if err != nil {
146159
return err

cli/ssh_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestSSH(t *testing.T) {
5353
})
5454
coderdtest.AwaitProjectVersionJob(t, client, version.ID)
5555
project := coderdtest.CreateProject(t, client, user.OrganizationID, version.ID)
56-
workspace := coderdtest.CreateWorkspace(t, client, "", project.ID)
56+
workspace := coderdtest.CreateWorkspace(t, client, codersdk.Me, project.ID)
5757
go func() {
5858
// Run this async so the SSH command has to wait for
5959
// the build and agent to connect!
@@ -111,7 +111,7 @@ func TestSSH(t *testing.T) {
111111
})
112112
coderdtest.AwaitProjectVersionJob(t, client, version.ID)
113113
project := coderdtest.CreateProject(t, client, user.OrganizationID, version.ID)
114-
workspace := coderdtest.CreateWorkspace(t, client, "", project.ID)
114+
workspace := coderdtest.CreateWorkspace(t, client, codersdk.Me, project.ID)
115115
go func() {
116116
// Run this async so the SSH command has to wait for
117117
// the build and agent to connect!

cli/start.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func start() *cobra.Command {
253253
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "\n\n"+cliui.Styles.Bold.Render("Interrupt caught. Gracefully exiting..."))
254254

255255
if dev {
256-
workspaces, err := client.WorkspacesByUser(cmd.Context(), "")
256+
workspaces, err := client.WorkspacesByUser(cmd.Context(), codersdk.Me)
257257
if err != nil {
258258
return xerrors.Errorf("get workspaces: %w", err)
259259
}
@@ -340,10 +340,10 @@ func start() *cobra.Command {
340340

341341
func createFirstUser(cmd *cobra.Command, client *codersdk.Client, cfg config.Root) error {
342342
_, err := client.CreateFirstUser(cmd.Context(), codersdk.CreateFirstUserRequest{
343-
Email: "admin@coder.com",
344-
Username: "developer",
345-
Password: "password",
346-
Organization: "acme-corp",
343+
Email: "admin@coder.com",
344+
Username: "developer",
345+
Password: "password",
346+
OrganizationName: "acme-corp",
347347
})
348348
if err != nil {
349349
return xerrors.Errorf("create first user: %w", err)

0 commit comments

Comments
 (0)