handleSSHRequest builds a handler context and dispatches to the shared registry
(w io.Writer, req *common.HubRequest[cbor.RawMessage])
| 161 | |
| 162 | // handleSSHRequest builds a handler context and dispatches to the shared registry |
| 163 | func (a *Agent) handleSSHRequest(w io.Writer, req *common.HubRequest[cbor.RawMessage]) error { |
| 164 | // SSH does not support fingerprint auth action |
| 165 | if req.Action == common.CheckFingerprint { |
| 166 | return cbor.NewEncoder(w).Encode(common.AgentResponse{Error: "unsupported action"}) |
| 167 | } |
| 168 | |
| 169 | // responder that writes AgentResponse to stdout |
| 170 | // Uses legacy typed fields for backward compatibility with <= 0.17 |
| 171 | sshResponder := func(data any, requestID *uint32) error { |
| 172 | response := newAgentResponse(data, requestID) |
| 173 | return cbor.NewEncoder(w).Encode(response) |
| 174 | } |
| 175 | |
| 176 | ctx := &HandlerContext{ |
| 177 | Client: nil, |
| 178 | Agent: a, |
| 179 | Request: req, |
| 180 | RequestID: nil, |
| 181 | HubVerified: true, |
| 182 | SendResponse: sshResponder, |
| 183 | } |
| 184 | |
| 185 | if handler, ok := a.handlerRegistry.GetHandler(req.Action); ok { |
| 186 | if err := handler.Handle(ctx); err != nil { |
| 187 | return cbor.NewEncoder(w).Encode(common.AgentResponse{Error: err.Error()}) |
| 188 | } |
| 189 | return nil |
| 190 | } |
| 191 | return cbor.NewEncoder(w).Encode(common.AgentResponse{Error: fmt.Sprintf("unknown action: %d", req.Action)}) |
| 192 | } |
| 193 | |
| 194 | // handleLegacyStats serves the legacy one-shot stats payload for older hubs |
| 195 | func (a *Agent) handleLegacyStats(w io.Writer, hubVersion semver.Version) error { |
no test coverage detected