10 MB ExecuteDesktopAction executes a mouse/keyboard/scroll action on the agent's desktop.
(ctx context.Context, action DesktopAction)
| 689 | // ExecuteDesktopAction executes a mouse/keyboard/scroll action on the |
| 690 | // agent's desktop. |
| 691 | func (c *agentConn) ExecuteDesktopAction(ctx context.Context, action DesktopAction) (DesktopActionResponse, error) { |
| 692 | ctx, span := tracing.StartSpan(ctx) |
| 693 | defer span.End() |
| 694 | |
| 695 | host := net.JoinHostPort( |
| 696 | c.agentAddress().String(), |
| 697 | strconv.Itoa(AgentHTTPAPIServerPort), |
| 698 | ) |
| 699 | |
| 700 | body, err := json.Marshal(action) |
| 701 | if err != nil { |
| 702 | return DesktopActionResponse{}, xerrors.Errorf("marshal action: %w", err) |
| 703 | } |
| 704 | |
| 705 | url := fmt.Sprintf("http://%s/api/v0/desktop/action", host) |
| 706 | req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body)) |
| 707 | if err != nil { |
| 708 | return DesktopActionResponse{}, xerrors.Errorf("create request: %w", err) |
| 709 | } |
| 710 | req.Header.Set("Content-Type", "application/json") |
| 711 | c.headersMu.RLock() |
| 712 | if len(c.extraHeaders) > 0 { |
| 713 | for k, v := range c.extraHeaders { |
| 714 | req.Header[k] = v |
| 715 | } |
| 716 | } |
| 717 | c.headersMu.RUnlock() |
| 718 | |
| 719 | resp, err := c.apiClient().Do(req) |
| 720 | if err != nil { |
| 721 | return DesktopActionResponse{}, xerrors.Errorf("action request: %w", err) |
| 722 | } |
| 723 | defer resp.Body.Close() |
| 724 | |
| 725 | if resp.StatusCode != http.StatusOK { |
| 726 | return DesktopActionResponse{}, codersdk.ReadBodyAsError(resp) |
| 727 | } |
| 728 | |
| 729 | var result DesktopActionResponse |
| 730 | if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { |
| 731 | return DesktopActionResponse{}, xerrors.Errorf("decode action response: %w", err) |
| 732 | } |
| 733 | return result, nil |
| 734 | } |
| 735 | |
| 736 | // StartDesktopRecording starts a desktop recording session on the |
| 737 | // agent with the given recording ID. The recording ID is |
nothing calls this directly
no test coverage detected