feat: add endpoint for partial updates to org sync mapping (#16316)

This commit is contained in:
ケイラ
2025-01-30 10:52:50 -07:00
committed by GitHub
parent f651ab937b
commit 2371153a37
17 changed files with 595 additions and 11 deletions

View File

@ -12,6 +12,13 @@ import (
"golang.org/x/xerrors"
)
type IDPSyncMapping[ResourceIdType uuid.UUID | string] struct {
// The IdP claim the user has
Given string
// The ID of the Coder resource the user should be added to
Gets ResourceIdType
}
type GroupSyncSettings struct {
// Field is the name of the claim field that specifies what groups a user
// should be in. If empty, no groups will be synced.
@ -137,6 +144,26 @@ func (c *Client) PatchOrganizationIDPSyncSettings(ctx context.Context, req Organ
return resp, json.NewDecoder(res.Body).Decode(&resp)
}
// If the same mapping is present in both Add and Remove, Remove will take presidence.
type PatchOrganizationIDPSyncMappingRequest struct {
Add []IDPSyncMapping[uuid.UUID]
Remove []IDPSyncMapping[uuid.UUID]
}
func (c *Client) PatchOrganizationIDPSyncMapping(ctx context.Context, req PatchOrganizationIDPSyncMappingRequest) (OrganizationSyncSettings, error) {
res, err := c.Request(ctx, http.MethodPatch, "/api/v2/settings/idpsync/organization/mapping", req)
if err != nil {
return OrganizationSyncSettings{}, xerrors.Errorf("make request: %w", err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return OrganizationSyncSettings{}, ReadBodyAsError(res)
}
var resp OrganizationSyncSettings
return resp, json.NewDecoder(res.Body).Decode(&resp)
}
func (c *Client) GetAvailableIDPSyncFields(ctx context.Context) ([]string, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/settings/idpsync/available-fields", nil)
if err != nil {