Skip to content

Commit

Permalink
Update pagination for saml
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszBlizniak committed Sep 4, 2024
1 parent 45291f0 commit 3adaf7d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
39 changes: 25 additions & 14 deletions cloudsmith/resource_repository_privileges.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions cloudsmith/resource_saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,23 @@ 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
}
samlList = append(samlList, samlPage...)
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++
}

Expand Down
17 changes: 9 additions & 8 deletions docs/resources/repository_retention.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3adaf7d

Please sign in to comment.