handlePutDbConfig Upserts a new database config
()
| 643 | |
| 644 | // handlePutDbConfig Upserts a new database config |
| 645 | func (h *handler) handlePutDbConfig() (err error) { |
| 646 | h.assertAdminOnly() |
| 647 | contextNoCancel := base.NewNonCancelCtx() |
| 648 | |
| 649 | var dbConfig *DbConfig |
| 650 | |
| 651 | auditFields := base.AuditFields{} |
| 652 | if h.permissionsResults[PermUpdateDb.PermissionName] { |
| 653 | // user authorized to change all fields |
| 654 | var err error |
| 655 | var rawBytes []byte |
| 656 | rawBytes, dbConfig, err = h.readSanitizeDbConfigJSON() |
| 657 | if err != nil { |
| 658 | return err |
| 659 | } |
| 660 | configStr, err := redactConfigAsStr(h.ctx(), string(rawBytes)) |
| 661 | if err != nil { |
| 662 | base.WarnfCtx(h.ctx(), "Error redacting config for audit logging: %v", err) |
| 663 | } |
| 664 | auditFields[base.AuditFieldPayload] = configStr |
| 665 | } else { |
| 666 | hasAuthPerm := h.permissionsResults[PermConfigureAuth.PermissionName] |
| 667 | hasSyncPerm := h.permissionsResults[PermConfigureSyncFn.PermissionName] |
| 668 | var rawBytes []byte |
| 669 | rawBytes, err := io.ReadAll(h.requestBody) |
| 670 | if err != nil { |
| 671 | return err |
| 672 | } |
| 673 | configStr, err := redactConfigAsStr(h.ctx(), string(rawBytes)) |
| 674 | if err != nil { |
| 675 | base.WarnfCtx(h.ctx(), "Error redacting config for audit logging: %v", err) |
| 676 | } |
| 677 | auditFields[base.AuditFieldPayload] = configStr |
| 678 | |
| 679 | var mapDbConfig map[string]interface{} |
| 680 | err = ReadJSONFromMIMERawErr(h.rq.Header, io.NopCloser(bytes.NewReader(rawBytes)), &mapDbConfig) |
| 681 | if err != nil { |
| 682 | return err |
| 683 | } |
| 684 | |
| 685 | unknownFileKeys := make([]string, 0) |
| 686 | for key, _ := range mapDbConfig { |
| 687 | if key == "sync" && hasSyncPerm || key == "guest" && hasAuthPerm { |
| 688 | continue |
| 689 | } |
| 690 | unknownFileKeys = append(unknownFileKeys, key) |
| 691 | } |
| 692 | |
| 693 | if len(unknownFileKeys) > 0 { |
| 694 | return base.HTTPErrorf(http.StatusForbidden, "not authorized to update field: %s", strings.Join(unknownFileKeys, ",")) |
| 695 | } |
| 696 | |
| 697 | err = ReadJSONFromMIMERawErr(h.rq.Header, io.NopCloser(bytes.NewReader(rawBytes)), &dbConfig) |
| 698 | if err != nil { |
| 699 | return err |
| 700 | } |
| 701 | } |
| 702 |
nothing calls this directly
no test coverage detected