From ca20145627bf51afe91bbd296c3859f96143b8e6 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Fri, 8 Nov 2024 15:05:40 -0600 Subject: [PATCH 1/2] chore: add organization sync cli --- cli/organizationsettings.go | 48 +++++++++++++++++---- enterprise/cli/organizationsettings_test.go | 48 +++++++++++++++++++++ 2 files changed, 88 insertions(+), 8 deletions(-) diff --git a/cli/organizationsettings.go b/cli/organizationsettings.go index 2c6b901de10ca..920ae41ebe1fc 100644 --- a/cli/organizationsettings.go +++ b/cli/organizationsettings.go @@ -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", @@ -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 { @@ -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 @@ -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) diff --git a/enterprise/cli/organizationsettings_test.go b/enterprise/cli/organizationsettings_test.go index ad80c57cb3671..b0344ca358513 100644 --- a/enterprise/cli/organizationsettings_test.go +++ b/enterprise/cli/organizationsettings_test.go @@ -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()) + }) +} From 73c38e7bc7708e7eba8198fd0cca937ca1adfda5 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Fri, 8 Nov 2024 15:08:32 -0600 Subject: [PATCH 2/2] make gen, update-golden-files --- ...der_organizations_settings_set_--help.golden | 7 +++++-- ...anizations_settings_set_--help_--help.golden | 7 +++++-- ...er_organizations_settings_show_--help.golden | 7 +++++-- ...nizations_settings_show_--help_--help.golden | 7 +++++-- docs/manifest.json | 10 ++++++++++ .../reference/cli/organizations_settings_set.md | 9 +++++---- ...anizations_settings_set_organization-sync.md | 17 +++++++++++++++++ .../cli/organizations_settings_show.md | 9 +++++---- ...nizations_settings_show_organization-sync.md | 17 +++++++++++++++++ 9 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 docs/reference/cli/organizations_settings_set_organization-sync.md create mode 100644 docs/reference/cli/organizations_settings_show_organization-sync.md diff --git a/cli/testdata/coder_organizations_settings_set_--help.golden b/cli/testdata/coder_organizations_settings_set_--help.golden index e86ceddf73865..a6554785f3131 100644 --- a/cli/testdata/coder_organizations_settings_set_--help.golden +++ b/cli/testdata/coder_organizations_settings_set_--help.golden @@ -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. diff --git a/cli/testdata/coder_organizations_settings_set_--help_--help.golden b/cli/testdata/coder_organizations_settings_set_--help_--help.golden index e86ceddf73865..a6554785f3131 100644 --- a/cli/testdata/coder_organizations_settings_set_--help_--help.golden +++ b/cli/testdata/coder_organizations_settings_set_--help_--help.golden @@ -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. diff --git a/cli/testdata/coder_organizations_settings_show_--help.golden b/cli/testdata/coder_organizations_settings_show_--help.golden index ee575a0fd067b..da8ccb18c14a1 100644 --- a/cli/testdata/coder_organizations_settings_show_--help.golden +++ b/cli/testdata/coder_organizations_settings_show_--help.golden @@ -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. diff --git a/cli/testdata/coder_organizations_settings_show_--help_--help.golden b/cli/testdata/coder_organizations_settings_show_--help_--help.golden index ee575a0fd067b..da8ccb18c14a1 100644 --- a/cli/testdata/coder_organizations_settings_show_--help_--help.golden +++ b/cli/testdata/coder_organizations_settings_show_--help_--help.golden @@ -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. diff --git a/docs/manifest.json b/docs/manifest.json index 8a8cc6c771794..5c53ee05352dd 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -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.", @@ -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.", diff --git a/docs/reference/cli/organizations_settings_set.md b/docs/reference/cli/organizations_settings_set.md index b4fd819184030..e1e9bf0261a1b 100644 --- a/docs/reference/cli/organizations_settings_set.md +++ b/docs/reference/cli/organizations_settings_set.md @@ -20,7 +20,8 @@ coder organizations settings set ## Subcommands -| Name | Purpose | -| --------------------------------------------------------------------- | ---------------------------------------------------------- | -| [group-sync](./organizations_settings_set_group-sync.md) | Group sync settings to sync groups from an IdP. | -| [role-sync](./organizations_settings_set_role-sync.md) | Role sync settings to sync organization roles from an IdP. | +| Name | Purpose | +| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------ | +| [group-sync](./organizations_settings_set_group-sync.md) | Group sync settings to sync groups from an IdP. | +| [role-sync](./organizations_settings_set_role-sync.md) | Role sync settings to sync organization roles from an IdP. | +| [organization-sync](./organizations_settings_set_organization-sync.md) | Organization sync settings to sync organization memberships from an IdP. | diff --git a/docs/reference/cli/organizations_settings_set_organization-sync.md b/docs/reference/cli/organizations_settings_set_organization-sync.md new file mode 100644 index 0000000000000..6b6557e2c3358 --- /dev/null +++ b/docs/reference/cli/organizations_settings_set_organization-sync.md @@ -0,0 +1,17 @@ + + +# organizations settings set organization-sync + +Organization sync settings to sync organization memberships from an IdP. + +Aliases: + +- organizationsync +- org-sync +- orgsync + +## Usage + +```console +coder organizations settings set organization-sync +``` diff --git a/docs/reference/cli/organizations_settings_show.md b/docs/reference/cli/organizations_settings_show.md index 651f0a6f199de..feaef7d0124f9 100644 --- a/docs/reference/cli/organizations_settings_show.md +++ b/docs/reference/cli/organizations_settings_show.md @@ -20,7 +20,8 @@ coder organizations settings show ## Subcommands -| Name | Purpose | -| ---------------------------------------------------------------------- | ---------------------------------------------------------- | -| [group-sync](./organizations_settings_show_group-sync.md) | Group sync settings to sync groups from an IdP. | -| [role-sync](./organizations_settings_show_role-sync.md) | Role sync settings to sync organization roles from an IdP. | +| Name | Purpose | +| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ | +| [group-sync](./organizations_settings_show_group-sync.md) | Group sync settings to sync groups from an IdP. | +| [role-sync](./organizations_settings_show_role-sync.md) | Role sync settings to sync organization roles from an IdP. | +| [organization-sync](./organizations_settings_show_organization-sync.md) | Organization sync settings to sync organization memberships from an IdP. | diff --git a/docs/reference/cli/organizations_settings_show_organization-sync.md b/docs/reference/cli/organizations_settings_show_organization-sync.md new file mode 100644 index 0000000000000..7e2e025c2a4af --- /dev/null +++ b/docs/reference/cli/organizations_settings_show_organization-sync.md @@ -0,0 +1,17 @@ + + +# organizations settings show organization-sync + +Organization sync settings to sync organization memberships from an IdP. + +Aliases: + +- organizationsync +- org-sync +- orgsync + +## Usage + +```console +coder organizations settings show organization-sync +``` 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