| 362 | } |
| 363 | |
| 364 | func (c *Client) OrganizationProvisionerDaemons(ctx context.Context, organizationID uuid.UUID, opts *OrganizationProvisionerDaemonsOptions) ([]ProvisionerDaemon, error) { |
| 365 | qp := url.Values{} |
| 366 | if opts != nil { |
| 367 | if opts.Limit > 0 { |
| 368 | qp.Add("limit", strconv.Itoa(opts.Limit)) |
| 369 | } |
| 370 | if opts.Offline { |
| 371 | qp.Add("offline", "true") |
| 372 | } |
| 373 | if len(opts.Status) > 0 { |
| 374 | qp.Add("status", joinSlice(opts.Status)) |
| 375 | } |
| 376 | if opts.MaxAge > 0 { |
| 377 | qp.Add("max_age", opts.MaxAge.String()) |
| 378 | } |
| 379 | if len(opts.IDs) > 0 { |
| 380 | qp.Add("ids", joinSliceStringer(opts.IDs)) |
| 381 | } |
| 382 | if len(opts.Tags) > 0 { |
| 383 | tagsRaw, err := json.Marshal(opts.Tags) |
| 384 | if err != nil { |
| 385 | return nil, xerrors.Errorf("marshal tags: %w", err) |
| 386 | } |
| 387 | qp.Add("tags", string(tagsRaw)) |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | res, err := c.Request(ctx, http.MethodGet, |
| 392 | fmt.Sprintf("/api/v2/organizations/%s/provisionerdaemons?%s", organizationID.String(), qp.Encode()), |
| 393 | nil, |
| 394 | ) |
| 395 | if err != nil { |
| 396 | return nil, xerrors.Errorf("execute request: %w", err) |
| 397 | } |
| 398 | defer res.Body.Close() |
| 399 | |
| 400 | if res.StatusCode != http.StatusOK { |
| 401 | return nil, ReadBodyAsError(res) |
| 402 | } |
| 403 | |
| 404 | var daemons []ProvisionerDaemon |
| 405 | return daemons, json.NewDecoder(res.Body).Decode(&daemons) |
| 406 | } |
| 407 | |
| 408 | type OrganizationProvisionerJobsOptions struct { |
| 409 | Limit int |