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

chore: add cli command to update organization sync settings#15459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 2 commits intomainfromstevenmasley/org_sync_cli
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletionscli/organizationsettings.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,6 +48,23 @@ func (r *RootCmd) organizationSettings(orgContext *OrganizationContext) *serpent
return cli.RoleIDPSyncSettings(ctx, org.String())
},
},
{
Name: "organization-sync",
Aliases: []string{"organizationsync", "org-sync", "orgsync"},
Short: "Organization sync settings to sync organization memberships from an IdP.",
DisableOrgContext: true,
Patch: func(ctx context.Context, cli *codersdk.Client, _ uuid.UUID, input json.RawMessage) (any, error) {
var req codersdk.OrganizationSyncSettings
err := json.Unmarshal(input, &req)
if err != nil {
return nil, xerrors.Errorf("unmarshalling organization sync settings: %w", err)
}
return cli.PatchOrganizationIDPSyncSettings(ctx, req)
},
Fetch: func(ctx context.Context, cli *codersdk.Client, _ uuid.UUID) (any, error) {
return cli.OrganizationIDPSyncSettings(ctx)
},
},
}
cmd := &serpent.Command{
Use: "settings",
Expand All@@ -68,8 +85,13 @@ type organizationSetting struct {
Name string
Aliases []string
Short string
Patch func(ctx context.Context, cli *codersdk.Client, org uuid.UUID, input json.RawMessage) (any, error)
Fetch func(ctx context.Context, cli *codersdk.Client, org uuid.UUID) (any, error)
// DisableOrgContext is kinda a kludge. It tells the command constructor
// to not require an organization context. This is used for the organization
// sync settings which are not tied to a specific organization.
// It feels excessive to build a more elaborate solution for this one-off.
DisableOrgContext bool
Patch func(ctx context.Context, cli *codersdk.Client, org uuid.UUID, input json.RawMessage) (any, error)
Fetch func(ctx context.Context, cli *codersdk.Client, org uuid.UUID) (any, error)
}

func (r *RootCmd) setOrganizationSettings(orgContext *OrganizationContext, settings []organizationSetting) *serpent.Command {
Expand DownExpand Up@@ -107,9 +129,14 @@ func (r *RootCmd) setOrganizationSettings(orgContext *OrganizationContext, setti
),
Handler: func(inv *serpent.Invocation) error {
ctx := inv.Context()
org, err := orgContext.Selected(inv, client)
if err != nil {
return err
var org codersdk.Organization
var err error

if !set.DisableOrgContext {
org, err = orgContext.Selected(inv, client)
if err != nil {
return err
}
}

// Read in the json
Expand DownExpand Up@@ -178,9 +205,14 @@ func (r *RootCmd) printOrganizationSetting(orgContext *OrganizationContext, sett
),
Handler: func(inv *serpent.Invocation) error {
ctx := inv.Context()
org, err := orgContext.Selected(inv, client)
if err != nil {
return err
var org codersdk.Organization
var err error

if !set.DisableOrgContext {
org, err = orgContext.Selected(inv, client)
if err != nil {
return err
}
}

output, err := fetch(ctx, client, org.ID)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,8 +10,11 @@ USAGE:
$ coder organization settings set groupsync < input.json

SUBCOMMANDS:
group-sync Group sync settings to sync groups from an IdP.
role-sync Role sync settings to sync organization roles from an IdP.
group-sync Group sync settings to sync groups from an IdP.
organization-sync Organization sync settings to sync organization
memberships from an IdP.
role-sync Role sync settings to sync organization roles from an
IdP.

———
Run `coder --help` for a list of global options.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,8 +10,11 @@ USAGE:
$ coder organization settings set groupsync < input.json

SUBCOMMANDS:
group-sync Group sync settings to sync groups from an IdP.
role-sync Role sync settings to sync organization roles from an IdP.
group-sync Group sync settings to sync groups from an IdP.
organization-sync Organization sync settings to sync organization
memberships from an IdP.
role-sync Role sync settings to sync organization roles from an
IdP.

———
Run `coder --help` for a list of global options.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,8 +10,11 @@ USAGE:
$ coder organization settings show groupsync

SUBCOMMANDS:
group-sync Group sync settings to sync groups from an IdP.
role-sync Role sync settings to sync organization roles from an IdP.
group-sync Group sync settings to sync groups from an IdP.
organization-sync Organization sync settings to sync organization
memberships from an IdP.
role-sync Role sync settings to sync organization roles from an
IdP.

———
Run `coder --help` for a list of global options.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,8 +10,11 @@ USAGE:
$ coder organization settings show groupsync

SUBCOMMANDS:
group-sync Group sync settings to sync groups from an IdP.
role-sync Role sync settings to sync organization roles from an IdP.
group-sync Group sync settings to sync groups from an IdP.
organization-sync Organization sync settings to sync organization
memberships from an IdP.
role-sync Role sync settings to sync organization roles from an
IdP.

———
Run `coder --help` for a list of global options.
10 changes: 10 additions & 0 deletionsdocs/manifest.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1056,6 +1056,11 @@
"description": "Group sync settings to sync groups from an IdP.",
"path": "reference/cli/organizations_settings_set_group-sync.md"
},
{
"title": "organizations settings set organization-sync",
"description": "Organization sync settings to sync organization memberships from an IdP.",
"path": "reference/cli/organizations_settings_set_organization-sync.md"
},
{
"title": "organizations settings set role-sync",
"description": "Role sync settings to sync organization roles from an IdP.",
Expand All@@ -1071,6 +1076,11 @@
"description": "Group sync settings to sync groups from an IdP.",
"path": "reference/cli/organizations_settings_show_group-sync.md"
},
{
"title": "organizations settings show organization-sync",
"description": "Organization sync settings to sync organization memberships from an IdP.",
"path": "reference/cli/organizations_settings_show_organization-sync.md"
},
{
"title": "organizations settings show role-sync",
"description": "Role sync settings to sync organization roles from an IdP.",
Expand Down
9 changes: 5 additions & 4 deletionsdocs/reference/cli/organizations_settings_set.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

9 changes: 5 additions & 4 deletionsdocs/reference/cli/organizations_settings_show.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

48 changes: 48 additions & 0 deletionsenterprise/cli/organizationsettings_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,3 +115,51 @@ func TestUpdateRoleSync(t *testing.T) {
require.JSONEq(t, string(expectedData), buf.String())
})
}

func TestUpdateOrganizationSync(t *testing.T) {
t.Parallel()

t.Run("OK", func(t *testing.T) {
t.Parallel()

owner, _ := coderdenttest.New(t, &coderdenttest.Options{
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureMultipleOrganizations: 1,
},
},
})

ctx := testutil.Context(t, testutil.WaitLong)
inv, root := clitest.New(t, "organization", "settings", "set", "organization-sync")
//nolint:gocritic // Using the owner, testing the cli not perms
clitest.SetupConfig(t, owner, root)

expectedSettings := codersdk.OrganizationSyncSettings{
Field: "organizations",
Mapping: map[string][]uuid.UUID{
"test": {uuid.New()},
},
}
expectedData, err := json.Marshal(expectedSettings)
require.NoError(t, err)

buf := new(bytes.Buffer)
inv.Stdout = buf
inv.Stdin = bytes.NewBuffer(expectedData)
err = inv.WithContext(ctx).Run()
require.NoError(t, err)
require.JSONEq(t, string(expectedData), buf.String())

// Now read it back
inv, root = clitest.New(t, "organization", "settings", "show", "organization-sync")
//nolint:gocritic // Using the owner, testing the cli not perms
clitest.SetupConfig(t, owner, root)

buf = new(bytes.Buffer)
inv.Stdout = buf
err = inv.WithContext(ctx).Run()
require.NoError(t, err)
require.JSONEq(t, string(expectedData), buf.String())
})
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp