(w http.ResponseWriter, r *http.Request, nodeID string)
| 555 | } |
| 556 | |
| 557 | func (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 | |
| 602 | func (a *API) handleNodeApply(w http.ResponseWriter, r *http.Request, nodeID string) { |
| 603 | if r.Method != http.MethodPost { |
no test coverage detected