MCPcopy Index your code
hub / github.com/coder/coder / patchRoleIDPSyncConfig

Method patchRoleIDPSyncConfig

enterprise/coderd/idpsync.go:384–439  ·  view source on GitHub ↗

@Summary Update role IdP Sync config @ID update-role-idp-sync-config @Security CoderSessionToken @Produce json @Accept json @Tags Enterprise @Success 200 {object} codersdk.RoleSyncSettings @Param organization path string true "Organization ID or name" format(uuid) @Param request body codersdk.PatchR

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

382// @Param request body codersdk.PatchRoleIDPSyncConfigRequest true "New config values"
383// @Router /api/v2/organizations/{organization}/settings/idpsync/roles/config [patch]
384func (api *API) patchRoleIDPSyncConfig(rw http.ResponseWriter, r *http.Request) {
385 ctx := r.Context()
386 org := httpmw.OrganizationParam(r)
387 auditor := *api.AGPL.Auditor.Load()
388 aReq, commitAudit := audit.InitRequest[idpsync.RoleSyncSettings](rw, &audit.RequestParams{
389 Audit: auditor,
390 Log: api.Logger,
391 Request: r,
392 Action: database.AuditActionWrite,
393 OrganizationID: org.ID,
394 })
395 defer commitAudit()
396
397 if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceIdpsyncSettings.InOrg(org.ID)) {
398 httpapi.Forbidden(rw)
399 return
400 }
401
402 var req codersdk.PatchRoleIDPSyncConfigRequest
403 if !httpapi.Read(ctx, rw, r, &req) {
404 return
405 }
406
407 var settings idpsync.RoleSyncSettings
408 //nolint:gocritic // Requires system context to update runtime config
409 sysCtx := dbauthz.AsSystemRestricted(ctx)
410 err := database.ReadModifyUpdate(api.Database, func(tx database.Store) error {
411 existing, err := api.IDPSync.RoleSyncSettings(sysCtx, org.ID, tx)
412 if err != nil {
413 return err
414 }
415 aReq.Old = *existing
416
417 settings = idpsync.RoleSyncSettings{
418 Field: req.Field,
419 Mapping: existing.Mapping,
420 }
421
422 err = api.IDPSync.UpdateRoleSyncSettings(sysCtx, org.ID, tx, settings)
423 if err != nil {
424 return err
425 }
426
427 return nil
428 })
429 if err != nil {
430 httpapi.InternalServerError(rw, err)
431 return
432 }
433
434 aReq.New = settings
435 httpapi.Write(ctx, rw, http.StatusOK, codersdk.RoleSyncSettings{
436 Field: settings.Field,
437 Mapping: settings.Mapping,
438 })
439}
440
441// @Summary Update role IdP Sync mapping

Callers

nothing calls this directly

Calls 14

AuthorizeMethod · 0.95
OrganizationParamFunction · 0.92
InitRequestFunction · 0.92
ForbiddenFunction · 0.92
ReadFunction · 0.92
AsSystemRestrictedFunction · 0.92
ReadModifyUpdateFunction · 0.92
InternalServerErrorFunction · 0.92
WriteFunction · 0.92
InOrgMethod · 0.80
ContextMethod · 0.65
RoleSyncSettingsMethod · 0.65

Tested by

no test coverage detected