MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / handleAccessApply

Method handleAccessApply

internal/serverapi/users.go:511–565  ·  view source on GitHub ↗

handleAccessApply 将该节点的完整配置重新下发。

(w http.ResponseWriter, r *http.Request, userID, ibID string)

Source from the content-addressed store, hash-verified

509
510// handleAccessApply 将该节点的完整配置重新下发。
511func (a *userAPI) handleAccessApply(w http.ResponseWriter, r *http.Request, userID, ibID string) {
512 if r.Method != http.MethodPost {
513 writeMethodNotAllowed(w, http.MethodPost)
514 return
515 }
516 acc, err := a.users.GetUserInbound(ibID)
517 if err != nil {
518 writeUserInboundError(w, err)
519 return
520 }
521 if acc.UserID != userID {
522 writeJSON(w, http.StatusNotFound, map[string]any{"error": "user inbound not found"})
523 return
524 }
525
526 nodeInbounds, err := a.inboundStore.ListInboundsByNode(acc.NodeID)
527 if err != nil {
528 internalError(w, r, err)
529 return
530 }
531 allAccesses, err := a.users.ListUserInboundsByNode(acc.NodeID)
532 if err != nil {
533 internalError(w, r, err)
534 return
535 }
536 userIDs := collectUserIDs(allAccesses)
537 userMap, err := a.users.GetUsersByIDs(userIDs)
538 if err != nil {
539 internalError(w, r, err)
540 return
541 }
542
543 client, err := a.base.clientFor(acc.NodeID)
544 if err != nil {
545 writeNodeError(w, err)
546 return
547 }
548 accNode, _ := a.base.store.Get(acc.NodeID)
549 ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
550 defer cancel()
551
552 status, config, err := jobs.ApplyNodeUsers(ctx, client, nodeInbounds, allAccesses, userMap, a.inboundStore, a.outboundStore, a.applyOpts, accNode)
553 if err != nil {
554 writeJSON(w, http.StatusBadGateway, map[string]any{"error": err.Error()})
555 return
556 }
557
558 writeJSON(w, http.StatusOK, map[string]any{
559 "access": acc,
560 "users_count": len(allAccesses),
561 "active_users": len(filterEnabledAccesses(allAccesses, userMap)),
562 "node_status": status,
563 "node_config": json.RawMessage(config),
564 })
565}
566
567// handleAccessSubscription 返回该节点访问凭据对应的所有订阅链接。
568func (a *userAPI) handleAccessSubscription(w http.ResponseWriter, r *http.Request, userID, ibID string) {

Callers 1

handleUserRoutesMethod · 0.95

Calls 15

ApplyNodeUsersFunction · 0.92
writeMethodNotAllowedFunction · 0.85
writeUserInboundErrorFunction · 0.85
internalErrorFunction · 0.85
writeNodeErrorFunction · 0.85
filterEnabledAccessesFunction · 0.85
clientForMethod · 0.80
writeJSONFunction · 0.70
collectUserIDsFunction · 0.70
GetUserInboundMethod · 0.65
ListInboundsByNodeMethod · 0.65

Tested by

no test coverage detected