Skip to content

Commit faee35f

Browse files
authored
Merge branch 'main' into depot-runners
2 parents f58bb06 + 9abaa94 commit faee35f

Some content is hidden

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

45 files changed

+813
-456
lines changed

cli/organizationmembers.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func (r *RootCmd) organizationMembers() *serpent.Command {
2020
r.listOrganizationMembers(),
2121
r.assignOrganizationRoles(),
2222
r.addOrganizationMember(),
23+
r.removeOrganizationMember(),
2324
},
2425
Handler: func(inv *serpent.Invocation) error {
2526
return inv.Command.HelpHandler(inv)
@@ -29,6 +30,37 @@ func (r *RootCmd) organizationMembers() *serpent.Command {
2930
return cmd
3031
}
3132

33+
func (r *RootCmd) removeOrganizationMember() *serpent.Command {
34+
client := new(codersdk.Client)
35+
36+
cmd := &serpent.Command{
37+
Use: "remove <username | user_id>",
38+
Short: "Remove a new member to the current organization",
39+
Middleware: serpent.Chain(
40+
r.InitClient(client),
41+
serpent.RequireNArgs(1),
42+
),
43+
Handler: func(inv *serpent.Invocation) error {
44+
ctx := inv.Context()
45+
organization, err := CurrentOrganization(r, inv, client)
46+
if err != nil {
47+
return err
48+
}
49+
user := inv.Args[0]
50+
51+
err = client.DeleteOrganizationMember(ctx, organization.ID, user)
52+
if err != nil {
53+
return xerrors.Errorf("could not remove member from organization %q: %w", organization.HumanName(), err)
54+
}
55+
56+
_, _ = fmt.Fprintf(inv.Stdout, "Organization member removed from %q\n", organization.HumanName())
57+
return nil
58+
},
59+
}
60+
61+
return cmd
62+
}
63+
3264
func (r *RootCmd) addOrganizationMember() *serpent.Command {
3365
client := new(codersdk.Client)
3466

@@ -49,10 +81,10 @@ func (r *RootCmd) addOrganizationMember() *serpent.Command {
4981

5082
_, err = client.PostOrganizationMember(ctx, organization.ID, user)
5183
if err != nil {
52-
return xerrors.Errorf("could not add member to organization: %w", err)
84+
return xerrors.Errorf("could not add member to organization %q: %w", organization.HumanName(), err)
5385
}
5486

55-
_, _ = fmt.Fprintln(inv.Stdout, "Organization member added")
87+
_, _ = fmt.Fprintf(inv.Stdout, "Organization member added to %q\n", organization.HumanName())
5688
return nil
5789
},
5890
}

cli/organizationmembers_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,49 @@ func TestAddOrganizationMembers(t *testing.T) {
7272
require.Len(t, members, 2)
7373
})
7474
}
75+
76+
func TestRemoveOrganizationMembers(t *testing.T) {
77+
t.Parallel()
78+
79+
t.Run("OK", func(t *testing.T) {
80+
t.Parallel()
81+
82+
ownerClient := coderdtest.New(t, &coderdtest.Options{})
83+
owner := coderdtest.CreateFirstUser(t, ownerClient)
84+
orgAdminClient, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.ScopedRoleOrgAdmin(owner.OrganizationID))
85+
_, user := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID)
86+
87+
ctx := testutil.Context(t, testutil.WaitMedium)
88+
89+
inv, root := clitest.New(t, "organization", "members", "remove", "--organization", owner.OrganizationID.String(), user.Username)
90+
clitest.SetupConfig(t, orgAdminClient, root)
91+
92+
buf := new(bytes.Buffer)
93+
inv.Stdout = buf
94+
err := inv.WithContext(ctx).Run()
95+
require.NoError(t, err)
96+
97+
members, err := orgAdminClient.OrganizationMembers(ctx, owner.OrganizationID)
98+
require.NoError(t, err)
99+
100+
require.Len(t, members, 2)
101+
})
102+
103+
t.Run("UserNotExists", func(t *testing.T) {
104+
t.Parallel()
105+
106+
ownerClient := coderdtest.New(t, &coderdtest.Options{})
107+
owner := coderdtest.CreateFirstUser(t, ownerClient)
108+
orgAdminClient, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.ScopedRoleOrgAdmin(owner.OrganizationID))
109+
110+
ctx := testutil.Context(t, testutil.WaitMedium)
111+
112+
inv, root := clitest.New(t, "organization", "members", "remove", "--organization", owner.OrganizationID.String(), "random_name")
113+
clitest.SetupConfig(t, orgAdminClient, root)
114+
115+
buf := new(bytes.Buffer)
116+
inv.Stdout = buf
117+
err := inv.WithContext(ctx).Run()
118+
require.ErrorContains(t, err, "must be an existing uuid or username")
119+
})
120+
}

coderd/apidoc/docs.go

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/healthcheck/healthcheck.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,27 +156,27 @@ func Run(ctx context.Context, opts *ReportOptions) *healthsdk.HealthcheckReport
156156
wg.Wait()
157157

158158
report.Time = time.Now()
159-
report.FailingSections = []healthsdk.HealthSection{}
159+
failingSections := []healthsdk.HealthSection{}
160160
if report.DERP.Severity.Value() > health.SeverityWarning.Value() {
161-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionDERP)
161+
failingSections = append(failingSections, healthsdk.HealthSectionDERP)
162162
}
163163
if report.AccessURL.Severity.Value() > health.SeverityOK.Value() {
164-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionAccessURL)
164+
failingSections = append(failingSections, healthsdk.HealthSectionAccessURL)
165165
}
166166
if report.Websocket.Severity.Value() > health.SeverityWarning.Value() {
167-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionWebsocket)
167+
failingSections = append(failingSections, healthsdk.HealthSectionWebsocket)
168168
}
169169
if report.Database.Severity.Value() > health.SeverityWarning.Value() {
170-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionDatabase)
170+
failingSections = append(failingSections, healthsdk.HealthSectionDatabase)
171171
}
172172
if report.WorkspaceProxy.Severity.Value() > health.SeverityWarning.Value() {
173-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionWorkspaceProxy)
173+
failingSections = append(failingSections, healthsdk.HealthSectionWorkspaceProxy)
174174
}
175175
if report.ProvisionerDaemons.Severity.Value() > health.SeverityWarning.Value() {
176-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionProvisionerDaemons)
176+
failingSections = append(failingSections, healthsdk.HealthSectionProvisionerDaemons)
177177
}
178178

179-
report.Healthy = len(report.FailingSections) == 0
179+
report.Healthy = len(failingSections) == 0
180180

181181
// Review healthcheck sub-reports.
182182
report.Severity = health.SeverityOK

coderd/healthcheck/healthcheck_test.go

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ func TestHealthcheck(t *testing.T) {
4949
t.Parallel()
5050

5151
for _, c := range []struct {
52-
name string
53-
checker *testChecker
54-
healthy bool
55-
severity health.Severity
56-
failingSections []healthsdk.HealthSection
52+
name string
53+
checker *testChecker
54+
healthy bool
55+
severity health.Severity
5756
}{{
5857
name: "OK",
5958
checker: &testChecker{
@@ -93,9 +92,8 @@ func TestHealthcheck(t *testing.T) {
9392
},
9493
},
9594
},
96-
healthy: true,
97-
severity: health.SeverityOK,
98-
failingSections: []healthsdk.HealthSection{},
95+
healthy: true,
96+
severity: health.SeverityOK,
9997
}, {
10098
name: "DERPFail",
10199
checker: &testChecker{
@@ -135,9 +133,8 @@ func TestHealthcheck(t *testing.T) {
135133
},
136134
},
137135
},
138-
healthy: false,
139-
severity: health.SeverityError,
140-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionDERP},
136+
healthy: false,
137+
severity: health.SeverityError,
141138
}, {
142139
name: "DERPWarning",
143140
checker: &testChecker{
@@ -178,9 +175,8 @@ func TestHealthcheck(t *testing.T) {
178175
},
179176
},
180177
},
181-
healthy: true,
182-
severity: health.SeverityWarning,
183-
failingSections: []healthsdk.HealthSection{},
178+
healthy: true,
179+
severity: health.SeverityWarning,
184180
}, {
185181
name: "AccessURLFail",
186182
checker: &testChecker{
@@ -220,9 +216,8 @@ func TestHealthcheck(t *testing.T) {
220216
},
221217
},
222218
},
223-
healthy: false,
224-
severity: health.SeverityWarning,
225-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionAccessURL},
219+
healthy: false,
220+
severity: health.SeverityWarning,
226221
}, {
227222
name: "WebsocketFail",
228223
checker: &testChecker{
@@ -262,9 +257,8 @@ func TestHealthcheck(t *testing.T) {
262257
},
263258
},
264259
},
265-
healthy: false,
266-
severity: health.SeverityError,
267-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionWebsocket},
260+
healthy: false,
261+
severity: health.SeverityError,
268262
}, {
269263
name: "DatabaseFail",
270264
checker: &testChecker{
@@ -304,9 +298,8 @@ func TestHealthcheck(t *testing.T) {
304298
},
305299
},
306300
},
307-
healthy: false,
308-
severity: health.SeverityError,
309-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionDatabase},
301+
healthy: false,
302+
severity: health.SeverityError,
310303
}, {
311304
name: "ProxyFail",
312305
checker: &testChecker{
@@ -346,9 +339,8 @@ func TestHealthcheck(t *testing.T) {
346339
},
347340
},
348341
},
349-
severity: health.SeverityError,
350-
healthy: false,
351-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionWorkspaceProxy},
342+
severity: health.SeverityError,
343+
healthy: false,
352344
}, {
353345
name: "ProxyWarn",
354346
checker: &testChecker{
@@ -389,9 +381,8 @@ func TestHealthcheck(t *testing.T) {
389381
},
390382
},
391383
},
392-
severity: health.SeverityWarning,
393-
healthy: true,
394-
failingSections: []healthsdk.HealthSection{},
384+
severity: health.SeverityWarning,
385+
healthy: true,
395386
}, {
396387
name: "ProvisionerDaemonsFail",
397388
checker: &testChecker{
@@ -431,9 +422,8 @@ func TestHealthcheck(t *testing.T) {
431422
},
432423
},
433424
},
434-
severity: health.SeverityError,
435-
healthy: false,
436-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionProvisionerDaemons},
425+
severity: health.SeverityError,
426+
healthy: false,
437427
}, {
438428
name: "ProvisionerDaemonsWarn",
439429
checker: &testChecker{
@@ -474,9 +464,8 @@ func TestHealthcheck(t *testing.T) {
474464
},
475465
},
476466
},
477-
severity: health.SeverityWarning,
478-
healthy: true,
479-
failingSections: []healthsdk.HealthSection{},
467+
severity: health.SeverityWarning,
468+
healthy: true,
480469
}, {
481470
name: "AllFail",
482471
healthy: false,
@@ -518,14 +507,6 @@ func TestHealthcheck(t *testing.T) {
518507
},
519508
},
520509
severity: health.SeverityError,
521-
failingSections: []healthsdk.HealthSection{
522-
healthsdk.HealthSectionDERP,
523-
healthsdk.HealthSectionAccessURL,
524-
healthsdk.HealthSectionWebsocket,
525-
healthsdk.HealthSectionDatabase,
526-
healthsdk.HealthSectionWorkspaceProxy,
527-
healthsdk.HealthSectionProvisionerDaemons,
528-
},
529510
}} {
530511
c := c
531512
t.Run(c.name, func(t *testing.T) {
@@ -537,7 +518,6 @@ func TestHealthcheck(t *testing.T) {
537518

538519
assert.Equal(t, c.healthy, report.Healthy)
539520
assert.Equal(t, c.severity, report.Severity)
540-
assert.Equal(t, c.failingSections, report.FailingSections)
541521
assert.Equal(t, c.checker.DERPReport.Healthy, report.DERP.Healthy)
542522
assert.Equal(t, c.checker.DERPReport.Severity, report.DERP.Severity)
543523
assert.Equal(t, c.checker.DERPReport.Warnings, report.DERP.Warnings)

0 commit comments

Comments
 (0)