diff --git a/cloudsmith/resource_repository_privileges.go b/cloudsmith/resource_repository_privileges.go index e329fd8..7c888b5 100644 --- a/cloudsmith/resource_repository_privileges.go +++ b/cloudsmith/resource_repository_privileges.go @@ -180,24 +180,35 @@ func resourceRepositoryPrivilegesRead(d *schema.ResourceData, m interface{}) err organization := requiredString(d, "organization") repository := requiredString(d, "repository") - req := pc.APIClient.ReposApi.ReposPrivilegesList(pc.Auth, organization, repository) - // TODO: add a proper loop here to ensure we always get all privs, - // regardless of how many are configured. - req = req.Page(1) - req = req.PageSize(1000) - privileges, resp, err := pc.APIClient.ReposApi.ReposPrivilegesListExecute(req) - if err != nil { - if is404(resp) { - d.SetId("") - return nil + var allPrivileges []cloudsmith.RepositoryPrivilegeDict + page := int64(1) + pageSize := int64(1000) + + for { + req := pc.APIClient.ReposApi.ReposPrivilegesList(pc.Auth, organization, repository) + req = req.Page(page) + req = req.PageSize(pageSize) + privileges, resp, err := pc.APIClient.ReposApi.ReposPrivilegesListExecute(req) + if err != nil { + if is404(resp) { + d.SetId("") + return nil + } + return err } - return err + allPrivileges = append(allPrivileges, privileges.GetPrivileges()...) + + // Check if we have retrieved all pages + if int64(len(privileges.GetPrivileges())) < pageSize { + break + } + page++ } - d.Set("service", flattenRepositoryPrivilegeServices(privileges.GetPrivileges())) - d.Set("team", flattenRepositoryPrivilegeTeams(privileges.GetPrivileges())) - d.Set("user", flattenRepositoryPrivilegeUsers(privileges.GetPrivileges())) + d.Set("service", flattenRepositoryPrivilegeServices(allPrivileges)) + d.Set("team", flattenRepositoryPrivilegeTeams(allPrivileges)) + d.Set("user", flattenRepositoryPrivilegeUsers(allPrivileges)) // namespace and repository are not returned from the privileges read // endpoint, so we can use the values stored in resource state. We rely on diff --git a/cloudsmith/resource_saml.go b/cloudsmith/resource_saml.go index 1828c96..bd1954b 100644 --- a/cloudsmith/resource_saml.go +++ b/cloudsmith/resource_saml.go @@ -104,7 +104,7 @@ func retrieveSAMLSyncListPages(pc *providerConfig, organization string, pageSize if pageCount == -1 || pageCount == 0 { var samlPage []cloudsmith.OrganizationGroupSync var err error - samlPage, pageCount, err = retrieveSAMLSyncListPage(pc, organization, pageSize, 1) + samlPage, _, err = retrieveSAMLSyncListPage(pc, organization, pageSize, 1) if err != nil { return nil, err } @@ -112,12 +112,15 @@ func retrieveSAMLSyncListPages(pc *providerConfig, organization string, pageSize pageCurrentCount++ } - for pageCurrentCount <= pageCount { - samlPage, _, err := retrieveSAMLSyncListPage(pc, organization, pageSize, pageCount) + for { + samlPage, totalPages, err := retrieveSAMLSyncListPage(pc, organization, pageSize, pageCurrentCount) if err != nil { return nil, err } samlList = append(samlList, samlPage...) + if pageCurrentCount >= totalPages { + break + } pageCurrentCount++ } diff --git a/docs/resources/repository_retention.md b/docs/resources/repository_retention.md index 5f1cf25..e023011 100644 --- a/docs/resources/repository_retention.md +++ b/docs/resources/repository_retention.md @@ -41,14 +41,15 @@ resource "cloudsmith_repository_retention_rule" "retention_rule" { The following arguments are supported: -* [`namespace`]("Go to definition") - (Required) The namespace of the repository. -* [`repository`]("Go to definition") - (Required) If true, the retention lifecycle rules will be activated for the repository and settings will be updated. -* [`retention_enabled`]("Go to definition") - (Required) If true, the retention lifecycle rules will be activated for the repository and settings will be updated.* [`retention_count_limit`]("Go to definition") - (Optional) The maximum number of packages to retain. Must be between 0 and 10000. -* [`retention_days_limit`]("Go to definition") - (Optional) The number of days of packages to retain. Must be between `0` and `180`. -* [`retention_group_by_name`]("Go to definition") - (Optional) If true, retention will apply to groups of packages by name rather than all packages. -* [`retention_group_by_format`]("Go to definition") - (Optional) If true, retention will apply to packages by package formats rather than across all package formats. -* [`retention_group_by_package_type`]("Go to definition") - (Optional) If true, retention will apply to packages by package type rather than across all package types for one or more formats. -* [`retention_size_limit`]("Go to definition") - (Optional) The maximum total size (in bytes) of packages to retain. Must be between `0` and `21474836480` (21.47 GB / 21474.83 MB). +* `namespace` - (Required) The namespace of the repository. +* `repository` - (Required) If true, the retention lifecycle rules will be activated for the repository and settings will be updated. +* `retention_enabled` - (Required) If true, the retention lifecycle rules will be activated for the repository and settings will be updated. +* `retention_count_limit` - (Optional) The maximum number of packages to retain. Must be between 0 and 10000. +* `retention_days_limit` - (Optional) The number of days of packages to retain. Must be between `0` and `180`. +* `retention_group_by_name` - (Optional) If true, retention will apply to groups of packages by name rather than all packages. +* `retention_group_by_format` - (Optional) If true, retention will apply to packages by package formats rather than across all package formats. +* `retention_group_by_package_type` - (Optional) If true, retention will apply to packages by package type rather than across all package types for one or more formats. +* `retention_size_limit` - (Optional) The maximum total size (in bytes) of packages to retain. Must be between `0` and `21474836480` (21.47 GB / 21474.83 MB). ## Import