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