From 075ad65b8d56eab12f0a89bd4aadec9725de92bb Mon Sep 17 00:00:00 2001 From: Bartosz Blizniak Date: Mon, 2 Sep 2024 12:45:01 +0100 Subject: [PATCH 1/2] update code --- .../resource_repository_retention_rule.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cloudsmith/resource_repository_retention_rule.go b/cloudsmith/resource_repository_retention_rule.go index 27950d5..280c161 100644 --- a/cloudsmith/resource_repository_retention_rule.go +++ b/cloudsmith/resource_repository_retention_rule.go @@ -103,6 +103,21 @@ func resourceRepoRetentionRuleRead(d *schema.ResourceData, meta interface{}) err return nil } +func validateInt64Between(min, max int64) schema.SchemaValidateFunc { + return func(i interface{}, k string) (s []string, es []error) { + v, ok := i.(int) + if !ok { + es = append(es, fmt.Errorf("expected type of %s to be int", k)) + return + } + + if int64(v) < min || int64(v) > max { + es = append(es, fmt.Errorf("%q must be between %d and %d, got: %d", k, min, max, v)) + } + return + } +} + func resourceRepoRetentionRule() *schema.Resource { return &schema.Resource{ Create: resourceRepoRetentionRuleUpdate, @@ -168,7 +183,7 @@ func resourceRepoRetentionRule() *schema.Resource { Type: schema.TypeInt, Optional: true, Description: "The maximum total size (in bytes) of packages to retain. Must be between 0 and 21474836480.", - ValidateFunc: validation.IntBetween(0, 21474836480), + ValidateFunc: validateInt64Between(0, 21474836480), }, }, } From 6496183bab30749dede00079711c824d55a2e1d6 Mon Sep 17 00:00:00 2001 From: Bartosz Blizniak Date: Mon, 2 Sep 2024 13:11:40 +0100 Subject: [PATCH 2/2] update code --- .../resource_repository_retention_rule.go | 22 +++---------------- docs/resources/repository_retention.md | 4 ++-- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/cloudsmith/resource_repository_retention_rule.go b/cloudsmith/resource_repository_retention_rule.go index 280c161..1adc676 100644 --- a/cloudsmith/resource_repository_retention_rule.go +++ b/cloudsmith/resource_repository_retention_rule.go @@ -103,21 +103,6 @@ func resourceRepoRetentionRuleRead(d *schema.ResourceData, meta interface{}) err return nil } -func validateInt64Between(min, max int64) schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { - v, ok := i.(int) - if !ok { - es = append(es, fmt.Errorf("expected type of %s to be int", k)) - return - } - - if int64(v) < min || int64(v) > max { - es = append(es, fmt.Errorf("%q must be between %d and %d, got: %d", k, min, max, v)) - } - return - } -} - func resourceRepoRetentionRule() *schema.Resource { return &schema.Resource{ Create: resourceRepoRetentionRuleUpdate, @@ -180,10 +165,9 @@ func resourceRepoRetentionRule() *schema.Resource { Description: "If true, retention will apply to packages by package type rather than across all package types for one or more formats.", }, "retention_size_limit": { - Type: schema.TypeInt, - Optional: true, - Description: "The maximum total size (in bytes) of packages to retain. Must be between 0 and 21474836480.", - ValidateFunc: validateInt64Between(0, 21474836480), + Type: schema.TypeInt, + Optional: true, + Description: "The maximum total size (in bytes) of packages to retain. Must be between 0 and 21474836480 (21.47 GB / 21474.83 MB).", }, }, } diff --git a/docs/resources/repository_retention.md b/docs/resources/repository_retention.md index 6c8abe6..5f1cf25 100644 --- a/docs/resources/repository_retention.md +++ b/docs/resources/repository_retention.md @@ -44,11 +44,11 @@ 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_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. +* [`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). ## Import