Skip to content

Commit 99dd13d

Browse files
authored
chore: add cli command to update organization sync settings (coder#15459)
1 parent 75b2990 commit 99dd13d

11 files changed

+162
-24
lines changed

cli/organizationsettings.go

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ func (r *RootCmd) organizationSettings(orgContext *OrganizationContext) *serpent
4848
return cli.RoleIDPSyncSettings(ctx, org.String())
4949
},
5050
},
51+
{
52+
Name: "organization-sync",
53+
Aliases: []string{"organizationsync", "org-sync", "orgsync"},
54+
Short: "Organization sync settings to sync organization memberships from an IdP.",
55+
DisableOrgContext: true,
56+
Patch: func(ctx context.Context, cli *codersdk.Client, _ uuid.UUID, input json.RawMessage) (any, error) {
57+
var req codersdk.OrganizationSyncSettings
58+
err := json.Unmarshal(input, &req)
59+
if err != nil {
60+
return nil, xerrors.Errorf("unmarshalling organization sync settings: %w", err)
61+
}
62+
return cli.PatchOrganizationIDPSyncSettings(ctx, req)
63+
},
64+
Fetch: func(ctx context.Context, cli *codersdk.Client, _ uuid.UUID) (any, error) {
65+
return cli.OrganizationIDPSyncSettings(ctx)
66+
},
67+
},
5168
}
5269
cmd := &serpent.Command{
5370
Use: "settings",
@@ -68,8 +85,13 @@ type organizationSetting struct {
6885
Name string
6986
Aliases []string
7087
Short string
71-
Patch func(ctx context.Context, cli *codersdk.Client, org uuid.UUID, input json.RawMessage) (any, error)
72-
Fetch func(ctx context.Context, cli *codersdk.Client, org uuid.UUID) (any, error)
88+
// DisableOrgContext is kinda a kludge. It tells the command constructor
89+
// to not require an organization context. This is used for the organization
90+
// sync settings which are not tied to a specific organization.
91+
// It feels excessive to build a more elaborate solution for this one-off.
92+
DisableOrgContext bool
93+
Patch func(ctx context.Context, cli *codersdk.Client, org uuid.UUID, input json.RawMessage) (any, error)
94+
Fetch func(ctx context.Context, cli *codersdk.Client, org uuid.UUID) (any, error)
7395
}
7496

7597
func (r *RootCmd) setOrganizationSettings(orgContext *OrganizationContext, settings []organizationSetting) *serpent.Command {
@@ -107,9 +129,14 @@ func (r *RootCmd) setOrganizationSettings(orgContext *OrganizationContext, setti
107129
),
108130
Handler: func(inv *serpent.Invocation) error {
109131
ctx := inv.Context()
110-
org, err := orgContext.Selected(inv, client)
111-
if err != nil {
112-
return err
132+
var org codersdk.Organization
133+
var err error
134+
135+
if !set.DisableOrgContext {
136+
org, err = orgContext.Selected(inv, client)
137+
if err != nil {
138+
return err
139+
}
113140
}
114141

115142
// Read in the json
@@ -178,9 +205,14 @@ func (r *RootCmd) printOrganizationSetting(orgContext *OrganizationContext, sett
178205
),
179206
Handler: func(inv *serpent.Invocation) error {
180207
ctx := inv.Context()
181-
org, err := orgContext.Selected(inv, client)
182-
if err != nil {
183-
return err
208+
var org codersdk.Organization
209+
var err error
210+
211+
if !set.DisableOrgContext {
212+
org, err = orgContext.Selected(inv, client)
213+
if err != nil {
214+
return err
215+
}
184216
}
185217

186218
output, err := fetch(ctx, client, org.ID)

cli/testdata/coder_organizations_settings_set_--help.golden

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ USAGE:
1010
$ coder organization settings set groupsync < input.json
1111

1212
SUBCOMMANDS:
13-
group-sync Group sync settings to sync groups from an IdP.
14-
role-sync Role sync settings to sync organization roles from an IdP.
13+
group-sync Group sync settings to sync groups from an IdP.
14+
organization-sync Organization sync settings to sync organization
15+
memberships from an IdP.
16+
role-sync Role sync settings to sync organization roles from an
17+
IdP.
1518

1619
———
1720
Run `coder --help` for a list of global options.

cli/testdata/coder_organizations_settings_set_--help_--help.golden

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ USAGE:
1010
$ coder organization settings set groupsync < input.json
1111

1212
SUBCOMMANDS:
13-
group-sync Group sync settings to sync groups from an IdP.
14-
role-sync Role sync settings to sync organization roles from an IdP.
13+
group-sync Group sync settings to sync groups from an IdP.
14+
organization-sync Organization sync settings to sync organization
15+
memberships from an IdP.
16+
role-sync Role sync settings to sync organization roles from an
17+
IdP.
1518

1619
———
1720
Run `coder --help` for a list of global options.

cli/testdata/coder_organizations_settings_show_--help.golden

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ USAGE:
1010
$ coder organization settings show groupsync
1111

1212
SUBCOMMANDS:
13-
group-sync Group sync settings to sync groups from an IdP.
14-
role-sync Role sync settings to sync organization roles from an IdP.
13+
group-sync Group sync settings to sync groups from an IdP.
14+
organization-sync Organization sync settings to sync organization
15+
memberships from an IdP.
16+
role-sync Role sync settings to sync organization roles from an
17+
IdP.
1518

1619
———
1720
Run `coder --help` for a list of global options.

cli/testdata/coder_organizations_settings_show_--help_--help.golden

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ USAGE:
1010
$ coder organization settings show groupsync
1111

1212
SUBCOMMANDS:
13-
group-sync Group sync settings to sync groups from an IdP.
14-
role-sync Role sync settings to sync organization roles from an IdP.
13+
group-sync Group sync settings to sync groups from an IdP.
14+
organization-sync Organization sync settings to sync organization
15+
memberships from an IdP.
16+
role-sync Role sync settings to sync organization roles from an
17+
IdP.
1518

1619
———
1720
Run `coder --help` for a list of global options.

docs/manifest.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,11 @@
10561056
"description": "Group sync settings to sync groups from an IdP.",
10571057
"path": "reference/cli/organizations_settings_set_group-sync.md"
10581058
},
1059+
{
1060+
"title": "organizations settings set organization-sync",
1061+
"description": "Organization sync settings to sync organization memberships from an IdP.",
1062+
"path": "reference/cli/organizations_settings_set_organization-sync.md"
1063+
},
10591064
{
10601065
"title": "organizations settings set role-sync",
10611066
"description": "Role sync settings to sync organization roles from an IdP.",
@@ -1071,6 +1076,11 @@
10711076
"description": "Group sync settings to sync groups from an IdP.",
10721077
"path": "reference/cli/organizations_settings_show_group-sync.md"
10731078
},
1079+
{
1080+
"title": "organizations settings show organization-sync",
1081+
"description": "Organization sync settings to sync organization memberships from an IdP.",
1082+
"path": "reference/cli/organizations_settings_show_organization-sync.md"
1083+
},
10741084
{
10751085
"title": "organizations settings show role-sync",
10761086
"description": "Role sync settings to sync organization roles from an IdP.",

docs/reference/cli/organizations_settings_set.md

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

docs/reference/cli/organizations_settings_set_organization-sync.md

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

docs/reference/cli/organizations_settings_show.md

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

docs/reference/cli/organizations_settings_show_organization-sync.md

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy