GetSessionLogs retrieves logs of an agent session identified by ID.
(ctx context.Context, id string)
| 334 | |
| 335 | // GetSessionLogs retrieves logs of an agent session identified by ID. |
| 336 | func (c *CAPIClient) GetSessionLogs(ctx context.Context, id string) ([]byte, error) { |
| 337 | if id == "" { |
| 338 | return nil, fmt.Errorf("missing session ID") |
| 339 | } |
| 340 | |
| 341 | url := fmt.Sprintf("%s/agents/sessions/%s/logs", c.capiBaseURL, url.PathEscape(id)) |
| 342 | |
| 343 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) |
| 344 | if err != nil { |
| 345 | return nil, err |
| 346 | } |
| 347 | |
| 348 | res, err := c.httpClient.Do(req) |
| 349 | if err != nil { |
| 350 | return nil, err |
| 351 | } |
| 352 | |
| 353 | defer res.Body.Close() |
| 354 | if res.StatusCode != http.StatusOK { |
| 355 | if res.StatusCode == http.StatusNotFound { |
| 356 | return nil, ErrSessionNotFound |
| 357 | } |
| 358 | return nil, fmt.Errorf("failed to get session: %s", res.Status) |
| 359 | } |
| 360 | |
| 361 | return io.ReadAll(res.Body) |
| 362 | } |
| 363 | |
| 364 | // ListSessionsByResourceID retrieves sessions associated with the given resource type and ID. |
| 365 | func (c *CAPIClient) ListSessionsByResourceID(ctx context.Context, resourceType string, resourceID int64, limit int) ([]*Session, error) { |