MCPcopy
hub / github.com/PatchMon/PatchMon / applySettingsUpdate

Function applySettingsUpdate

server-source-code/internal/handler/settings.go:785–919  ·  view source on GitHub ↗
(s *models.Settings, req map[string]interface{}, enc *util.Encryption)

Source from the content-addressed store, hash-verified

783}
784
785func applySettingsUpdate(s *models.Settings, req map[string]interface{}, enc *util.Encryption) {
786 urlVal, hasExplicitURL := getReqString(req, "server_url", "serverUrl")
787 if hasExplicitURL {
788 s.ServerURL = urlVal
789 }
790 if v, ok := getReqString(req, "server_protocol", "serverProtocol"); ok {
791 s.ServerProtocol = v
792 }
793 if v, ok := getReqString(req, "server_host", "serverHost"); ok {
794 s.ServerHost = v
795 }
796 if v, ok := getReqFloat64(req, "server_port", "serverPort"); ok {
797 s.ServerPort = int(v)
798 }
799 // Derive server_url from protocol/host/port when any of those were updated (matches Node backend behavior).
800 // Only derive when server_url was not explicitly sent (explicit URL takes precedence).
801 _, hasProtocol := getReqString(req, "server_protocol", "serverProtocol")
802 _, hasHost := getReqString(req, "server_host", "serverHost")
803 _, hasPort := getReqFloat64(req, "server_port", "serverPort")
804 if !hasExplicitURL && (hasProtocol || hasHost || hasPort) {
805 s.ServerURL = constructServerURL(s.ServerProtocol, s.ServerHost, s.ServerPort)
806 }
807 if v, ok := getReqFloat64(req, "update_interval", "updateInterval"); ok {
808 s.UpdateInterval = int(v)
809 }
810 if v, ok := getReqBool(req, "auto_update", "autoUpdate"); ok {
811 s.AutoUpdate = v
812 }
813 if v, ok := getReqString(req, "default_compliance_mode", "defaultComplianceMode"); ok {
814 s.DefaultComplianceMode = v
815 }
816 if v, ok := getReqFloat64(req, "compliance_scan_interval", "complianceScanInterval"); ok {
817 val := int(v)
818 if val >= 60 && val <= 10080 {
819 s.ComplianceScanInterval = val
820 }
821 }
822 if v, ok := getReqString(req, "package_cache_refresh_mode", "packageCacheRefreshMode"); ok {
823 if v == "always" || v == "if_stale" || v == "never" {
824 s.PackageCacheRefreshMode = v
825 }
826 }
827 if v, ok := getReqFloat64(req, "package_cache_refresh_max_age", "packageCacheRefreshMaxAge"); ok {
828 val := int(v)
829 if val >= 1 && val <= 1440 {
830 s.PackageCacheRefreshMaxAge = val
831 }
832 }
833 if v, ok := getReqString(req, "github_repo_url", "githubRepoUrl"); ok {
834 s.GithubRepoURL = v
835 }
836 if v, ok := getReqString(req, "ssh_key_path", "sshKeyPath"); ok {
837 s.SSHKeyPath = &v
838 }
839 if v, ok := getReqString(req, "repository_type", "repositoryType"); ok {
840 s.RepositoryType = v
841 }
842 if v, ok := getReqBool(req, "signup_enabled", "signupEnabled"); ok {

Callers 1

UpdateMethod · 0.85

Calls 6

getReqStringFunction · 0.85
getReqFloat64Function · 0.85
constructServerURLFunction · 0.85
getReqBoolFunction · 0.85
getReqStringOrEmptyFunction · 0.85
EncryptMethod · 0.80

Tested by

no test coverage detected