From 95774110b3c01863aeed85417afd231052218429 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Thu, 1 Aug 2024 09:53:47 -0700 Subject: [PATCH 1/3] Add 'max_unique_snapshots' attribute to Java package types for remote repo --- docs/resources/remote_gradle_repository.md | 2 + docs/resources/remote_ivy_repository.md | 2 + docs/resources/remote_maven_repository.md | 16 ++++---- docs/resources/remote_sbt_repository.md | 2 + .../resource/repository/remote/remote.go | 11 ++++++ ...urce_artifactory_remote_repository_test.go | 37 ++++++++++--------- 6 files changed, 46 insertions(+), 24 deletions(-) diff --git a/docs/resources/remote_gradle_repository.md b/docs/resources/remote_gradle_repository.md index 8707e9725..266de9b5c 100644 --- a/docs/resources/remote_gradle_repository.md +++ b/docs/resources/remote_gradle_repository.md @@ -16,6 +16,7 @@ resource "artifactory_remote_gradle_repository" "gradle-remote" { fetch_sources_eagerly = false suppress_pom_consistency_checks = true reject_invalid_jars = true + max_unique_snapshots = 10 } ``` @@ -36,6 +37,7 @@ The following arguments are supported, along with the [common list of arguments * `suppress_pom_consistency_checks` - (Optional, Default: `true`) - By default, the system keeps your repositories healthy by refusing POMs with incorrect coordinates (path). If the groupId:artifactId:version information inside the POM does not match the deployed path, Artifactory rejects the deployment with a "409 Conflict" error. You can disable this behavior by setting this attribute to `true`. * `reject_invalid_jars` - (Optional, Default: `false`) Reject the caching of jar files that are found to be invalid. For example, pseudo jars retrieved behind a "captive portal". * `remote_repo_checksum_policy_type` - (Optional, Default: `generate-if-absent`) Checking the Checksum effectively verifies the integrity of a deployed resource. The Checksum Policy determines how the system behaves when a client checksum for a remote resource is missing or conflicts with the locally calculated checksum. Available policies are `generate-if-absent`, `fail`, `ignore-and-generate`, and `pass-thru`. +* `max_unique_snapshots` - (Optional) The maximum number of unique snapshots of a single artifact to store. Once the number of snapshots exceeds this setting, older versions are removed. A value of 0 (default) indicates there is no limit, and unique snapshots are not cleaned up. ## Import diff --git a/docs/resources/remote_ivy_repository.md b/docs/resources/remote_ivy_repository.md index d8db798da..24f2b039c 100644 --- a/docs/resources/remote_ivy_repository.md +++ b/docs/resources/remote_ivy_repository.md @@ -15,6 +15,7 @@ resource "artifactory_remote_ivy_repository" "ivy-remote" { fetch_sources_eagerly = false suppress_pom_consistency_checks = true reject_invalid_jars = true + max_unique_snapshots = 10 } ``` @@ -35,6 +36,7 @@ The following arguments are supported, along with the [common list of arguments * `suppress_pom_consistency_checks` - (Optional, Default: `true`) - By default, the system keeps your repositories healthy by refusing POMs with incorrect coordinates (path). If the groupId:artifactId:version information inside the POM does not match the deployed path, Artifactory rejects the deployment with a "409 Conflict" error. You can disable this behavior by setting this attribute to `true`. * `reject_invalid_jars` - (Optional, Default: `false`) Reject the caching of jar files that are found to be invalid. For example, pseudo jars retrieved behind a "captive portal". * `remote_repo_checksum_policy_type` - (Optional, Default: `generate-if-absent`) Checking the Checksum effectively verifies the integrity of a deployed resource. The Checksum Policy determines how the system behaves when a client checksum for a remote resource is missing or conflicts with the locally calculated checksum. Available policies are `generate-if-absent`, `fail`, `ignore-and-generate`, and `pass-thru`. +* `max_unique_snapshots` - (Optional) The maximum number of unique snapshots of a single artifact to store. Once the number of snapshots exceeds this setting, older versions are removed. A value of 0 (default) indicates there is no limit, and unique snapshots are not cleaned up. ## Import diff --git a/docs/resources/remote_maven_repository.md b/docs/resources/remote_maven_repository.md index 994dd742e..b5a63e7de 100644 --- a/docs/resources/remote_maven_repository.md +++ b/docs/resources/remote_maven_repository.md @@ -10,13 +10,14 @@ Official documentation can be found [here](https://www.jfrog.com/confluence/disp ```hcl resource "artifactory_remote_maven_repository" "maven-remote" { - key = "maven-remote-foo" - url = "https://repo1.maven.org/maven2/" - fetch_jars_eagerly = true - fetch_sources_eagerly = false - suppress_pom_consistency_checks = false - reject_invalid_jars = true - metadata_retrieval_timeout_secs = 120 + key = "maven-remote-foo" + url = "https://repo1.maven.org/maven2/" + fetch_jars_eagerly = true + fetch_sources_eagerly = false + suppress_pom_consistency_checks = false + reject_invalid_jars = true + metadata_retrieval_timeout_secs = 120 + max_unique_snapshots = 10 } ``` @@ -39,6 +40,7 @@ The following arguments are supported, along with the [common list of arguments * `remote_repo_checksum_policy_type` - (Optional, Default: `generate-if-absent`) Checking the Checksum effectively verifies the integrity of a deployed resource. The Checksum Policy determines how the system behaves when a client checksum for a remote resource is missing or conflicts with the locally calculated checksum. Available policies are `generate-if-absent`, `fail`, `ignore-and-generate`, and `pass-thru`. `retrieval_cache_period_seconds` attribute. * `curated` - (Optional, Default: `false`) Enable repository to be protected by the Curation service. +* `max_unique_snapshots` - (Optional) The maximum number of unique snapshots of a single artifact to store. Once the number of snapshots exceeds this setting, older versions are removed. A value of 0 (default) indicates there is no limit, and unique snapshots are not cleaned up. ## Import diff --git a/docs/resources/remote_sbt_repository.md b/docs/resources/remote_sbt_repository.md index 7daf67202..9cc0468ab 100644 --- a/docs/resources/remote_sbt_repository.md +++ b/docs/resources/remote_sbt_repository.md @@ -16,6 +16,7 @@ resource "artifactory_remote_sbt_repository" "sbt-remote" { fetch_sources_eagerly = false suppress_pom_consistency_checks = true reject_invalid_jars = true + max_unique_snapshots = 10 } ``` @@ -36,6 +37,7 @@ The following arguments are supported, along with the [common list of arguments * `suppress_pom_consistency_checks` - (Optional, Default: `true`) By default, the system keeps your repositories healthy by refusing POMs with incorrect coordinates (path). If the groupId:artifactId:version information inside the POM does not match the deployed path, Artifactory rejects the deployment with a "409 Conflict" error. You can disable this behavior by setting this attribute to `true`. * `reject_invalid_jars` - (Optional, Default: `false`) Reject the caching of jar files that are found to be invalid. For example, pseudo jars retrieved behind a "captive portal". * `remote_repo_checksum_policy_type` - (Optional, Default: `generate-if-absent`) Checking the Checksum effectively verifies the integrity of a deployed resource. The Checksum Policy determines how the system behaves when a client checksum for a remote resource is missing or conflicts with the locally calculated checksum. Available policies are `generate-if-absent`, `fail`, `ignore-and-generate`, and `pass-thru`. +* `max_unique_snapshots` - (Optional) The maximum number of unique snapshots of a single artifact to store. Once the number of snapshots exceeds this setting, older versions are removed. A value of 0 (default) indicates there is no limit, and unique snapshots are not cleaned up. ## Import diff --git a/pkg/artifactory/resource/repository/remote/remote.go b/pkg/artifactory/resource/repository/remote/remote.go index 0d4eae22f..026b38ae3 100644 --- a/pkg/artifactory/resource/repository/remote/remote.go +++ b/pkg/artifactory/resource/repository/remote/remote.go @@ -77,6 +77,7 @@ type JavaRemoteRepo struct { HandleSnapshots bool `json:"handleSnapshots"` SuppressPomConsistencyChecks bool `json:"suppressPomConsistencyChecks"` RejectInvalidJars bool `json:"rejectInvalidJars"` + MaxUniqueSnapshots int `json:"maxUniqueSnapshots"` } type RepositoryVcsParams struct { @@ -458,6 +459,15 @@ func JavaRemoteSchema(isResource bool, packageType string, suppressPom bool) map Default: false, Description: `Reject the caching of jar files that are found to be invalid. For example, pseudo jars retrieved behind a "captive portal". Default value is 'false'.`, }, + "max_unique_snapshots": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(0)), + Description: "The maximum number of unique snapshots of a single artifact to store. Once the number of " + + "snapshots exceeds this setting, older versions are removed. A value of 0 (default) indicates there is " + + "no limit, and unique snapshots are not cleaned up.", + }, }, repository.RepoLayoutRefSchema(rclass, packageType), ) @@ -554,6 +564,7 @@ func UnpackJavaRemoteRepo(s *schema.ResourceData, repoType string) JavaRemoteRep HandleSnapshots: d.GetBool("handle_snapshots", false), SuppressPomConsistencyChecks: d.GetBool("suppress_pom_consistency_checks", false), RejectInvalidJars: d.GetBool("reject_invalid_jars", false), + MaxUniqueSnapshots: d.GetInt("max_unique_snapshots", false), } } diff --git a/pkg/artifactory/resource/repository/remote/resource_artifactory_remote_repository_test.go b/pkg/artifactory/resource/repository/remote/resource_artifactory_remote_repository_test.go index 5ac0f67f1..85f5dd433 100644 --- a/pkg/artifactory/resource/repository/remote/resource_artifactory_remote_repository_test.go +++ b/pkg/artifactory/resource/repository/remote/resource_artifactory_remote_repository_test.go @@ -591,21 +591,6 @@ func TestAccRemotePypiRepositoryWithAdditionalCheckFunctions(t *testing.T) { })) } -func TestAccRemoteMavenRepository(t *testing.T) { - resource.Test(mkNewRemoteTestCase("maven", t, map[string]interface{}{ - "missed_cache_period_seconds": 1800, // https://github.com/jfrog/terraform-provider-artifactory/issues/225 - "metadata_retrieval_timeout_secs": 30, // https://github.com/jfrog/terraform-provider-artifactory/issues/509 - "list_remote_folder_items": true, - "content_synchronisation": map[string]interface{}{ - "enabled": false, // even when set to true, it seems to come back as false on the wire - "statistics_enabled": true, - "properties_enabled": true, - "source_origin_absence_detection": true, - }, - "curated": false, - })) -} - func TestAccRemoteAllRepository(t *testing.T) { for _, repoType := range remote.PackageTypesLikeBasic { t.Run(repoType, func(t *testing.T) { @@ -707,19 +692,37 @@ func TestAccRemoteAllGradleLikeRepository(t *testing.T) { for _, repoType := range repository.GradleLikePackageTypes { t.Run(repoType, func(t *testing.T) { resource.Test(mkNewRemoteTestCase(repoType, t, map[string]interface{}{ - "missed_cache_period_seconds": 1800, // https://github.com/jfrog/terraform-provider-artifactory/issues/225 - "list_remote_folder_items": true, + "missed_cache_period_seconds": 1800, // https://github.com/jfrog/terraform-provider-artifactory/issues/225 + "metadata_retrieval_timeout_secs": 30, // https://github.com/jfrog/terraform-provider-artifactory/issues/509 + "list_remote_folder_items": true, "content_synchronisation": map[string]interface{}{ "enabled": false, // even when set to true, it seems to come back as false on the wire "statistics_enabled": true, "properties_enabled": true, "source_origin_absence_detection": true, }, + "max_unique_snapshots": 6, })) }) } } +func TestAccRemoteMavenRepository(t *testing.T) { + resource.Test(mkNewRemoteTestCase("maven", t, map[string]interface{}{ + "missed_cache_period_seconds": 1800, // https://github.com/jfrog/terraform-provider-artifactory/issues/225 + "metadata_retrieval_timeout_secs": 30, // https://github.com/jfrog/terraform-provider-artifactory/issues/509 + "list_remote_folder_items": true, + "content_synchronisation": map[string]interface{}{ + "enabled": false, // even when set to true, it seems to come back as false on the wire + "statistics_enabled": true, + "properties_enabled": true, + "source_origin_absence_detection": true, + }, + "max_unique_snapshots": 6, + "curated": false, + })) +} + func TestAccRemotePypiRepositoryWithCustomRegistryUrl(t *testing.T) { const packageType = "pypi" extraFields := map[string]interface{}{ From 8ddaa7aa50a88cb91a29cec6ac0bef1bf7639d7f Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Thu, 1 Aug 2024 10:11:43 -0700 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b46f59853..ffe998be5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 11.5.0 (August 2, 2024) + +IMPROVEMENTS: + +* resource/artifactory_remote_gradle_repository, resource/artifactory_remote_ivy_repository, resource/artifactory_remote_maven_repository, resource/artifactory_remote_sbt_repository: Add `max_unique_snapshots` attribute support. Issue: [#1039](https://github.com/jfrog/terraform-provider-artifactory/issues/1039) PR: [#1043](https://github.com/jfrog/terraform-provider-artifactory/pull/1043) + ## 11.4.0 (July 31, 2024). Tested on Artifactory 7.90.5 with Terraform 1.9.3 and OpenTofu 1.8.0 FEATURES: From b5377e65e860217be8bc2cd010c6f8d6ee482d0f Mon Sep 17 00:00:00 2001 From: JFrog CI Date: Thu, 1 Aug 2024 18:33:05 +0000 Subject: [PATCH 3/3] JFrog Pipelines - Add Artifactory version to CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffe998be5..2004673ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 11.5.0 (August 2, 2024) +## 11.5.0 (August 2, 2024). Tested on Artifactory 7.90.5 with Terraform 1.9.3 and OpenTofu 1.8.0 IMPROVEMENTS: