MCPcopy Index your code
hub / github.com/0xUnixIO/pulse / handleNodeRestart

Method handleNodeRestart

internal/serverapi/api.go:557–600  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, nodeID string)

Source from the content-addressed store, hash-verified

555}
556
557func (a *API) handleNodeRestart(w http.ResponseWriter, r *http.Request, nodeID string) {
558 if r.Method != http.MethodPost {
559 writeMethodNotAllowed(w, http.MethodPost)
560 return
561 }
562 if a.usersStore == nil || a.inboundStore == nil {
563 writeJSON(w, http.StatusInternalServerError, map[string]any{"error": "stores not configured"})
564 return
565 }
566 client, err := a.clientFor(nodeID)
567 if err != nil {
568 writeNodeError(w, err)
569 return
570 }
571 nodeInbounds, err := a.inboundStore.ListInboundsByNode(nodeID)
572 if err != nil {
573 writeJSON(w, http.StatusInternalServerError, map[string]any{"error": err.Error()})
574 return
575 }
576 userAccesses, err := a.usersStore.ListUserInboundsByNode(nodeID)
577 if err != nil {
578 writeJSON(w, http.StatusInternalServerError, map[string]any{"error": err.Error()})
579 return
580 }
581 userIDs := collectNodeUserIDs(userAccesses)
582 userMap, err := a.usersStore.GetUsersByIDs(userIDs)
583 if err != nil {
584 writeJSON(w, http.StatusInternalServerError, map[string]any{"error": err.Error()})
585 return
586 }
587 node, err := a.store.Get(nodeID)
588 if err != nil {
589 writeJSON(w, http.StatusInternalServerError, map[string]any{"error": err.Error()})
590 return
591 }
592 ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
593 defer cancel()
594 status, _, err := jobs.ApplyNodeUsers(ctx, client, nodeInbounds, userAccesses, userMap, a.inboundStore, a.outboundStore, a.applyOpts, node)
595 if err != nil {
596 writeJSON(w, http.StatusUnprocessableEntity, map[string]any{"error": err.Error()})
597 return
598 }
599 writeJSON(w, http.StatusOK, status)
600}
601
602func (a *API) handleNodeApply(w http.ResponseWriter, r *http.Request, nodeID string) {
603 if r.Method != http.MethodPost {

Callers 1

handleNodeRoutesMethod · 0.95

Calls 11

clientForMethod · 0.95
ApplyNodeUsersFunction · 0.92
writeMethodNotAllowedFunction · 0.85
writeNodeErrorFunction · 0.85
collectNodeUserIDsFunction · 0.85
writeJSONFunction · 0.70
ListInboundsByNodeMethod · 0.65
GetUsersByIDsMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected