Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'max_unique_snapshots' attribute to Java package types for remote repos #1043

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 11.5.0 (August 2, 2024). Tested on Artifactory 7.90.5 with Terraform 1.9.3 and OpenTofu 1.8.0

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:
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/remote_gradle_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/resources/remote_ivy_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand All @@ -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

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

Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/resources/remote_sbt_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand All @@ -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

Expand Down
11 changes: 11 additions & 0 deletions pkg/artifactory/resource/repository/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
)
Expand Down Expand Up @@ -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),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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{}{
Expand Down
Loading