From 77add7298e13084ba88f5f64eea4f44ed208bf78 Mon Sep 17 00:00:00 2001 From: George Angel Date: Thu, 24 Mar 2022 17:52:10 +1000 Subject: [PATCH] Use searchVersion query param to GET packages (#15) Instead of GETing all packages, only return packages that match the version name --- internal/provider/data_source_package.go | 8 +++++--- nebraska/packages.go | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/provider/data_source_package.go b/internal/provider/data_source_package.go index b10730d..c28836e 100644 --- a/internal/provider/data_source_package.go +++ b/internal/provider/data_source_package.go @@ -143,15 +143,17 @@ func dataSourcePackageRead(ctx context.Context, d *schema.ResourceData, meta int return diag.FromErr(err) } d.Set("application_id", appID) - packagePage, err := c.ListPackages(appID) + + version := d.Get("version").(string) + arch := d.Get("arch").(string) + + packagePage, err := c.SearchPackages(appID, version) if err != nil { return diag.FromErr(err) } if packagePage.Count != packagePage.TotalCount { return diag.FromErr(fmt.Errorf("GET packages returned %d/%d packages. We don't paginate.", packagePage.Count, packagePage.TotalCount)) } - version := d.Get("version").(string) - arch := d.Get("arch").(string) for _, p := range packagePage.Packages { if p.Version == version && api.Arch(p.Arch).String() == arch { diff --git a/nebraska/packages.go b/nebraska/packages.go index 2c69bf2..b9dd6b6 100644 --- a/nebraska/packages.go +++ b/nebraska/packages.go @@ -70,9 +70,9 @@ func (c *Client) GetPackage(appID, id string) (*codegen.Package, error) { return data, nil } -// ListPackages lists the packages for a particular application -func (c *Client) ListPackages(appID string) (*codegen.PackagePage, error) { - req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/apps/%s/packages?page=1&perpage=10000", appID), nil) +// SearchPackages lists the packages for a particular application and version +func (c *Client) SearchPackages(appID, id string) (*codegen.PackagePage, error) { + req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/apps/%s/packages?page=1&perpage=100000&searchVersion=%s", appID, id), nil) if err != nil { return nil, err }