| 414 | } |
| 415 | |
| 416 | func (c *Client) OrganizationProvisionerJobs(ctx context.Context, organizationID uuid.UUID, opts *OrganizationProvisionerJobsOptions) ([]ProvisionerJob, error) { |
| 417 | qp := url.Values{} |
| 418 | if opts != nil { |
| 419 | if opts.Limit > 0 { |
| 420 | qp.Add("limit", strconv.Itoa(opts.Limit)) |
| 421 | } |
| 422 | if len(opts.IDs) > 0 { |
| 423 | qp.Add("ids", joinSliceStringer(opts.IDs)) |
| 424 | } |
| 425 | if len(opts.Status) > 0 { |
| 426 | qp.Add("status", joinSlice(opts.Status)) |
| 427 | } |
| 428 | if len(opts.Tags) > 0 { |
| 429 | tagsRaw, err := json.Marshal(opts.Tags) |
| 430 | if err != nil { |
| 431 | return nil, xerrors.Errorf("marshal tags: %w", err) |
| 432 | } |
| 433 | qp.Add("tags", string(tagsRaw)) |
| 434 | } |
| 435 | if opts.Initiator != "" { |
| 436 | qp.Add("initiator", opts.Initiator) |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | res, err := c.Request(ctx, http.MethodGet, |
| 441 | fmt.Sprintf("/api/v2/organizations/%s/provisionerjobs?%s", organizationID.String(), qp.Encode()), |
| 442 | nil, |
| 443 | ) |
| 444 | if err != nil { |
| 445 | return nil, xerrors.Errorf("make request: %w", err) |
| 446 | } |
| 447 | defer res.Body.Close() |
| 448 | |
| 449 | if res.StatusCode != http.StatusOK { |
| 450 | return nil, ReadBodyAsError(res) |
| 451 | } |
| 452 | |
| 453 | var jobs []ProvisionerJob |
| 454 | return jobs, json.NewDecoder(res.Body).Decode(&jobs) |
| 455 | } |
| 456 | |
| 457 | func (c *Client) OrganizationProvisionerJob(ctx context.Context, organizationID, jobID uuid.UUID) (job ProvisionerJob, err error) { |
| 458 | res, err := c.Request(ctx, http.MethodGet, |