MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / ReloadHandler

Function ReloadHandler

server-source-code/internal/context/middleware.go:115–140  ·  view source on GitHub ↗

ReloadHandler returns a handler for POST /internal/reload that evicts a host from the pool and Redis caches. Requires X-Registry-Reload-Secret header to match reloadSecret. Query param: host (the host to evict).

(poolCache *PoolCache, redisCache *RedisCache, reloadSecret string)

Source from the content-addressed store, hash-verified

113// Requires X-Registry-Reload-Secret header to match reloadSecret.
114// Query param: host (the host to evict).
115func ReloadHandler(poolCache *PoolCache, redisCache *RedisCache, reloadSecret string) http.HandlerFunc {
116 return func(w http.ResponseWriter, r *http.Request) {
117 if r.Method != http.MethodPost {
118 http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
119 return
120 }
121 if reloadSecret != "" && !secureCompare(r.Header.Get(reloadSecretHeader), reloadSecret) {
122 http.Error(w, "unauthorized", http.StatusUnauthorized)
123 return
124 }
125 host := r.URL.Query().Get("host")
126 if host == "" {
127 http.Error(w, "host query param required", http.StatusBadRequest)
128 return
129 }
130 if poolCache != nil {
131 poolCache.Evict(host)
132 }
133 if redisCache != nil {
134 redisCache.Evict(host)
135 }
136 w.Header().Set("Content-Type", "application/json")
137 w.WriteHeader(http.StatusOK)
138 _, _ = w.Write([]byte(`{"ok":true}`))
139 }
140}
141
142// Historical note: a /api/v1/internal/migrate-tenant handler lived here
143// until the legacy-import control plane was redrawn. It let the manager

Callers

nothing calls this directly

Calls 7

secureCompareFunction · 0.85
ErrorMethod · 0.80
QueryMethod · 0.80
WriteMethod · 0.80
GetMethod · 0.45
EvictMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected