queryOperation sends a query to the Incus server and then converts the response metadata into an Operation object. It sets up an early event listener, performs the query, processes the response, and manages the lifecycle of the event listener.
(method string, path string, data any, ETag string)
| 400 | // queryOperation sends a query to the Incus server and then converts the response metadata into an Operation object. |
| 401 | // It sets up an early event listener, performs the query, processes the response, and manages the lifecycle of the event listener. |
| 402 | func (r *ProtocolIncus) queryOperation(method string, path string, data any, ETag string) (Operation, string, error) { |
| 403 | // Attempt to setup an early event listener |
| 404 | var listener *EventListener |
| 405 | |
| 406 | skipListener := r.skipEvents |
| 407 | if !skipListener { |
| 408 | var err error |
| 409 | |
| 410 | listener, err = r.GetEvents() |
| 411 | if err != nil { |
| 412 | if api.StatusErrorCheck(err, http.StatusForbidden) { |
| 413 | skipListener = true |
| 414 | } |
| 415 | |
| 416 | listener = nil |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | // Send the query |
| 421 | resp, etag, err := r.query(method, path, data, ETag) |
| 422 | if err != nil { |
| 423 | if listener != nil { |
| 424 | listener.Disconnect() |
| 425 | } |
| 426 | |
| 427 | return nil, "", err |
| 428 | } |
| 429 | |
| 430 | // Get to the operation |
| 431 | respOperation, err := resp.MetadataAsOperation() |
| 432 | if err != nil { |
| 433 | if listener != nil { |
| 434 | listener.Disconnect() |
| 435 | } |
| 436 | |
| 437 | return nil, "", err |
| 438 | } |
| 439 | |
| 440 | // Setup an Operation wrapper |
| 441 | op := operation{ |
| 442 | Operation: *respOperation, |
| 443 | r: r, |
| 444 | listener: listener, |
| 445 | skipListener: skipListener, |
| 446 | chActive: make(chan bool), |
| 447 | } |
| 448 | |
| 449 | // Log the data |
| 450 | logger.Debugf("Got operation from Incus") |
| 451 | logger.Debugf("%s", logger.Pretty(op.Operation)) |
| 452 | |
| 453 | return &op, etag, nil |
| 454 | } |
| 455 | |
| 456 | // rawWebsocket creates a websocket connection to the provided URL using the underlying HTTP transport of the ProtocolIncus receiver. |
| 457 | // It sets up the request headers, manages the connection handshake, sets TCP timeouts, and handles any errors that may occur during these operations. |
no test coverage detected