46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package webui
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/access"
|
|
"github.com/samcharles93/archie-core/internal/secret"
|
|
)
|
|
|
|
func (s *Server) handleSecretEngines(w http.ResponseWriter, r *http.Request) {
|
|
view, found, err := s.configSource()(r.Context())
|
|
if err != nil || !found || view.SecretEngines == nil {
|
|
http.Error(w, "secret engine report unavailable", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
writeJSON(w, map[string]any{"engines": view.SecretEngines})
|
|
}
|
|
|
|
func (s *Server) handleSecretCheck(w http.ResponseWriter, r *http.Request) {
|
|
if !s.authorizeTaskMutation(w, r) {
|
|
return
|
|
}
|
|
if p, ok := access.PrincipalFromContext(r.Context()); ok && !p.InstanceAdmin() {
|
|
http.Error(w, "instance administrator required", http.StatusForbidden)
|
|
return
|
|
}
|
|
ref, ok := decodeBody[secret.SecretRef](w, r)
|
|
if !ok {
|
|
return
|
|
}
|
|
if ref.Engine == "" || ref.Key == "" {
|
|
http.Error(w, "engine and key are required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if s.CheckSecret == nil {
|
|
http.Error(w, "secret resolution unavailable", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
resolved, err := s.CheckSecret(r.Context(), ref)
|
|
if err != nil {
|
|
http.Error(w, "secret resolution unavailable", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
writeJSON(w, map[string]any{"resolved": resolved, "process": "archie-gateway"})
|
|
}
|