Skip to content

feat: get and update group IdP Sync settings #14647

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
:(
  • Loading branch information
aslilac committed Sep 13, 2024
commit 497d7e65111da8f01bdd46867913fe7f6b43ed0c
1 change: 1 addition & 0 deletions coderd/idpsync/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
}

func (s AGPLIDPSync) GroupSyncSettings() runtimeconfig.RuntimeEntry[*GroupSyncSettings] {
fmt.Println("GroupSyncSettings key:", s.Group)

Check failure on line 34 in coderd/idpsync/group.go

View workflow job for this annotation

GitHub Actions / lint

unhandled-error: Unhandled error in call to function fmt.Println (revive)
return s.Group
}

Expand Down
4 changes: 2 additions & 2 deletions codersdk/idpsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (c *Client) GroupIDPSyncSettings(ctx context.Context, orgID string) (GroupS
return resp, json.NewDecoder(res.Body).Decode(&resp)
}

func (c *Client) PatchGroupIDPSyncSettings(ctx context.Context, orgID string, req GroupSyncSettings) (GroupSyncSettings, error) {
res, err := c.Request(ctx, http.MethodPatch, fmt.Sprintf("/api/v2/organizations/%s/settings/idpsync/groups", orgID), req)
func (c *Client) PostGroupIDPSyncSettings(ctx context.Context, orgID string, req GroupSyncSettings) (GroupSyncSettings, error) {
res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/v2/organizations/%s/settings/idpsync/groups", orgID), req)
if err != nil {
return GroupSyncSettings{}, xerrors.Errorf("make request: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
r.Delete("/organizations/{organization}/members/roles/{roleName}", api.deleteOrgRole)
r.Route("/organizations/{organization}/settings", func(r chi.Router) {
r.Get("/idpsync/groups", api.groupIDPSyncSettings)
r.Patch("/idpsync/groups", api.patchGroupIDPSyncSettings)
r.Post("/idpsync/groups", api.patchGroupIDPSyncSettings)
})
})

Expand Down
72 changes: 38 additions & 34 deletions enterprise/coderd/idpsync_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package coderd_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/coderd/audit"
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/coderd/database/dbauthz"
"github.com/coder/coder/v2/coderd/idpsync"
"github.com/coder/coder/v2/coderd/runtimeconfig"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
"github.com/coder/coder/v2/enterprise/coderd/license"
Expand All @@ -27,7 +27,7 @@
string(codersdk.ExperimentMultiOrganization),
}

client, user := coderdenttest.New(t, &coderdenttest.Options{
client, db, user := coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
Options: &coderdtest.Options{
DeploymentValues: dv,
},
Expand All @@ -38,50 +38,54 @@
},
},
})
ctx := testutil.Context(t, testutil.WaitLong)
settings, err := client.GroupIDPSyncSettings(ctx, user.OrganizationID.String())

ctx := testutil.Context(t, testutil.WaitShort)
dbresv := runtimeconfig.OrganizationResolver(user.OrganizationID, runtimeconfig.NewStoreResolver(db))
entry := runtimeconfig.MustNew[*idpsync.GroupSyncSettings]("group-sync-settings")
err := entry.SetRuntimeValue(dbauthz.AsSystemRestricted(ctx), dbresv, &idpsync.GroupSyncSettings{Field: "august"})

Check failure on line 45 in enterprise/coderd/idpsync_test.go

View workflow job for this annotation

GitHub Actions / lint

ruleguard: Using 'AsSystemRestricted' is dangerous and should be accompanied by a comment explaining why it's ok and a nolint. (gocritic)
require.NoError(t, err)
fmt.Printf("%v#", settings)

// TODO
settings, err := client.GroupIDPSyncSettings(ctx, user.OrganizationID.String())
require.NoError(t, err)
require.Equal(t, "august", settings.Field)
})
}

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

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

auditor := audit.NewMock()
client, user := coderdenttest.New(t, &coderdenttest.Options{
AuditLogging: true,
dv := coderdtest.DeploymentValues(t)
dv.Experiments = []string{
string(codersdk.ExperimentCustomRoles),
string(codersdk.ExperimentMultiOrganization),
}

client, db, user := coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
Options: &coderdtest.Options{
IncludeProvisionerDaemon: true,
Auditor: auditor,
DeploymentValues: dv,
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureTemplateRBAC: 1,
codersdk.FeatureAuditLog: 1,
codersdk.FeatureCustomRoles: 1,
codersdk.FeatureMultipleOrganizations: 1,
},
},
})
_, _ = coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleUserAdmin())

// TODO
})
}

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

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

client, user := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureTemplateRBAC: 1,
},
}})
_, _ = coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleUserAdmin())
ctx := testutil.Context(t, testutil.WaitShort)
settings, err := client.PostGroupIDPSyncSettings(ctx, user.OrganizationID.String(), codersdk.GroupSyncSettings{
Field: "august",
})
require.NoError(t, err)
require.Equal(t, "august", settings.Field)

// TODO
dbresv := runtimeconfig.OrganizationResolver(user.OrganizationID, runtimeconfig.NewStoreResolver(db))
entry := runtimeconfig.MustNew[*idpsync.GroupSyncSettings]("group-sync-settings")
dbSettings, err := entry.Resolve(ctx, dbresv)
require.NoError(t, err)
require.Equal(t, "august", dbSettings.Field)
})
}
Loading