Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99dd13d

Browse files
authored
chore: add cli command to update organization sync settings (#15459)
1 parent75b2990 commit99dd13d

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
returncli.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+
varreq codersdk.OrganizationSyncSettings
58+
err:=json.Unmarshal(input,&req)
59+
iferr!=nil {
60+
returnnil,xerrors.Errorf("unmarshalling organization sync settings: %w",err)
61+
}
62+
returncli.PatchOrganizationIDPSyncSettings(ctx,req)
63+
},
64+
Fetch:func(ctx context.Context,cli*codersdk.Client,_ uuid.UUID) (any,error) {
65+
returncli.OrganizationIDPSyncSettings(ctx)
66+
},
67+
},
5168
}
5269
cmd:=&serpent.Command{
5370
Use:"settings",
@@ -68,8 +85,13 @@ type organizationSetting struct {
6885
Namestring
6986
Aliases []string
7087
Shortstring
71-
Patchfunc(ctx context.Context,cli*codersdk.Client,org uuid.UUID,input json.RawMessage) (any,error)
72-
Fetchfunc(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+
DisableOrgContextbool
93+
Patchfunc(ctx context.Context,cli*codersdk.Client,org uuid.UUID,input json.RawMessage) (any,error)
94+
Fetchfunc(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-
iferr!=nil {
112-
returnerr
132+
varorg codersdk.Organization
133+
varerrerror
134+
135+
if!set.DisableOrgContext {
136+
org,err=orgContext.Selected(inv,client)
137+
iferr!=nil {
138+
returnerr
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-
iferr!=nil {
183-
returnerr
208+
varorg codersdk.Organization
209+
varerrerror
210+
211+
if!set.DisableOrgContext {
212+
org,err=orgContext.Selected(inv,client)
213+
iferr!=nil {
214+
returnerr
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 aboutcustomizing 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 aboutcustomizing 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 aboutcustomizing 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 aboutcustomizing how changed files appear on GitHub.

‎enterprise/cli/organizationsettings_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,51 @@ func TestUpdateRoleSync(t *testing.T) {
115115
require.JSONEq(t,string(expectedData),buf.String())
116116
})
117117
}
118+
119+
funcTestUpdateOrganizationSync(t*testing.T) {
120+
t.Parallel()
121+
122+
t.Run("OK",func(t*testing.T) {
123+
t.Parallel()
124+
125+
owner,_:=coderdenttest.New(t,&coderdenttest.Options{
126+
LicenseOptions:&coderdenttest.LicenseOptions{
127+
Features: license.Features{
128+
codersdk.FeatureMultipleOrganizations:1,
129+
},
130+
},
131+
})
132+
133+
ctx:=testutil.Context(t,testutil.WaitLong)
134+
inv,root:=clitest.New(t,"organization","settings","set","organization-sync")
135+
//nolint:gocritic // Using the owner, testing the cli not perms
136+
clitest.SetupConfig(t,owner,root)
137+
138+
expectedSettings:= codersdk.OrganizationSyncSettings{
139+
Field:"organizations",
140+
Mapping:map[string][]uuid.UUID{
141+
"test": {uuid.New()},
142+
},
143+
}
144+
expectedData,err:=json.Marshal(expectedSettings)
145+
require.NoError(t,err)
146+
147+
buf:=new(bytes.Buffer)
148+
inv.Stdout=buf
149+
inv.Stdin=bytes.NewBuffer(expectedData)
150+
err=inv.WithContext(ctx).Run()
151+
require.NoError(t,err)
152+
require.JSONEq(t,string(expectedData),buf.String())
153+
154+
// Now read it back
155+
inv,root=clitest.New(t,"organization","settings","show","organization-sync")
156+
//nolint:gocritic // Using the owner, testing the cli not perms
157+
clitest.SetupConfig(t,owner,root)
158+
159+
buf=new(bytes.Buffer)
160+
inv.Stdout=buf
161+
err=inv.WithContext(ctx).Run()
162+
require.NoError(t,err)
163+
require.JSONEq(t,string(expectedData),buf.String())
164+
})
165+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp