From 7b877120f24f3187af104031f97ab7b12ca8f9ed Mon Sep 17 00:00:00 2001 From: Valentin Delaye Date: Sat, 14 Sep 2024 14:33:40 +0200 Subject: [PATCH] Add helmoci repository --- .../settings/HelmOciRepositorySettings.java | 8 ++ .../impl/jackson/RepositorySettingsMixIn.java | 1 + .../impl/FederatedRepositoryBuilderImpl.java | 2 +- .../impl/LocalRepositoryBuilderImpl.java | 2 +- .../client/model/impl/PackageTypeImpl.java | 1 + .../impl/RemoteRepositoryBuilderImpl.java | 2 +- .../impl/VirtualRepositoryBuilderImpl.java | 2 +- .../impl/HelmOciRepositorySettingsImpl.java | 21 +++ .../artifactory.client.release.properties | 2 +- .../HelmOciPackageTypeRepositoryTests.groovy | 129 ++++++++++++++++++ 10 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 api/src/main/java/org/jfrog/artifactory/client/model/repository/settings/HelmOciRepositorySettings.java create mode 100644 services/src/main/java/org/jfrog/artifactory/client/model/repository/settings/impl/HelmOciRepositorySettingsImpl.java create mode 100644 services/src/test/groovy/org/jfrog/artifactory/client/HelmOciPackageTypeRepositoryTests.groovy diff --git a/api/src/main/java/org/jfrog/artifactory/client/model/repository/settings/HelmOciRepositorySettings.java b/api/src/main/java/org/jfrog/artifactory/client/model/repository/settings/HelmOciRepositorySettings.java new file mode 100644 index 00000000..15f67313 --- /dev/null +++ b/api/src/main/java/org/jfrog/artifactory/client/model/repository/settings/HelmOciRepositorySettings.java @@ -0,0 +1,8 @@ +package org.jfrog.artifactory.client.model.repository.settings; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public interface HelmOciRepositorySettings extends DockerRepositorySettings { + +} diff --git a/services/src/main/java/org/jfrog/artifactory/client/impl/jackson/RepositorySettingsMixIn.java b/services/src/main/java/org/jfrog/artifactory/client/impl/jackson/RepositorySettingsMixIn.java index bf5f60e1..91d20b2f 100644 --- a/services/src/main/java/org/jfrog/artifactory/client/impl/jackson/RepositorySettingsMixIn.java +++ b/services/src/main/java/org/jfrog/artifactory/client/impl/jackson/RepositorySettingsMixIn.java @@ -41,6 +41,7 @@ @JsonSubTypes.Type(value = CondaRepositorySettingsImpl.class, name = "conda"), @JsonSubTypes.Type(value = PuppetRepositorySettingsImpl.class, name = "puppet"), @JsonSubTypes.Type(value = HelmRepositorySettingsImpl.class, name = "helm"), + @JsonSubTypes.Type(value = HelmOciRepositorySettingsImpl.class, name = "helmoci"), @JsonSubTypes.Type(value = GoRepositorySettingsImpl.class, name = "go"), @JsonSubTypes.Type(value = CargoRepositorySettingsImpl.class, name = "cargo"), @JsonSubTypes.Type(value = TerraformRepositorySettingsImpl.class, name = "terraform"), diff --git a/services/src/main/java/org/jfrog/artifactory/client/model/impl/FederatedRepositoryBuilderImpl.java b/services/src/main/java/org/jfrog/artifactory/client/model/impl/FederatedRepositoryBuilderImpl.java index d74a1525..36bb7ea8 100644 --- a/services/src/main/java/org/jfrog/artifactory/client/model/impl/FederatedRepositoryBuilderImpl.java +++ b/services/src/main/java/org/jfrog/artifactory/client/model/impl/FederatedRepositoryBuilderImpl.java @@ -16,7 +16,7 @@ */ public class FederatedRepositoryBuilderImpl extends NonVirtualRepositoryBuilderBase implements FederatedRepositoryBuilder { private static Set federatedRepositorySupportedTypes = new HashSet<>(Arrays.asList( - bower, cocoapods, cran, conda, debian, docker, gems, generic, gitlfs, gradle, ivy, maven, npm, nuget, opkg, pypi, sbt, vagrant, yum, rpm, composer, conan, chef, puppet, helm, go, cargo, terraform, oci + bower, cocoapods, cran, conda, debian, docker, gems, generic, gitlfs, gradle, ivy, maven, npm, nuget, opkg, pypi, sbt, vagrant, yum, rpm, composer, conan, chef, puppet, helm, helmoci, go, cargo, terraform, oci )); protected List members = new ArrayList<>(); diff --git a/services/src/main/java/org/jfrog/artifactory/client/model/impl/LocalRepositoryBuilderImpl.java b/services/src/main/java/org/jfrog/artifactory/client/model/impl/LocalRepositoryBuilderImpl.java index d06590f8..2e69ee3c 100644 --- a/services/src/main/java/org/jfrog/artifactory/client/model/impl/LocalRepositoryBuilderImpl.java +++ b/services/src/main/java/org/jfrog/artifactory/client/model/impl/LocalRepositoryBuilderImpl.java @@ -17,7 +17,7 @@ */ public class LocalRepositoryBuilderImpl extends NonVirtualRepositoryBuilderBase implements LocalRepositoryBuilder { private static Set localRepositorySupportedTypes = new HashSet(Arrays.asList( - bower, cocoapods, cran, conda, debian, docker, gems, generic, gitlfs, gradle, ivy, maven, npm, nuget, opkg, pypi, sbt, vagrant, yum, rpm, composer, conan, chef, puppet, helm, go, cargo, terraform, oci + bower, cocoapods, cran, conda, debian, docker, gems, generic, gitlfs, gradle, ivy, maven, npm, nuget, opkg, pypi, sbt, vagrant, yum, rpm, composer, conan, chef, puppet, helm, helmoci, go, cargo, terraform, oci )); protected LocalRepositoryBuilderImpl() { diff --git a/services/src/main/java/org/jfrog/artifactory/client/model/impl/PackageTypeImpl.java b/services/src/main/java/org/jfrog/artifactory/client/model/impl/PackageTypeImpl.java index b78bf385..7011ff4c 100644 --- a/services/src/main/java/org/jfrog/artifactory/client/model/impl/PackageTypeImpl.java +++ b/services/src/main/java/org/jfrog/artifactory/client/model/impl/PackageTypeImpl.java @@ -31,6 +31,7 @@ public enum PackageTypeImpl implements PackageType { chef, puppet, helm, + helmoci, go, cargo, terraform, diff --git a/services/src/main/java/org/jfrog/artifactory/client/model/impl/RemoteRepositoryBuilderImpl.java b/services/src/main/java/org/jfrog/artifactory/client/model/impl/RemoteRepositoryBuilderImpl.java index 1031005f..b4c06cd4 100644 --- a/services/src/main/java/org/jfrog/artifactory/client/model/impl/RemoteRepositoryBuilderImpl.java +++ b/services/src/main/java/org/jfrog/artifactory/client/model/impl/RemoteRepositoryBuilderImpl.java @@ -17,7 +17,7 @@ */ public class RemoteRepositoryBuilderImpl extends NonVirtualRepositoryBuilderBase implements RemoteRepositoryBuilder { private static Set remoteRepositorySupportedTypes = new HashSet(Arrays.asList( - bower, cocoapods, cran, conda, debian, docker, gems, generic, gitlfs, gradle, ivy, maven, npm, nuget, opkg, p2, pypi, sbt, vcs, yum, rpm, composer, conan, chef, puppet, helm, go, cargo, terraform, oci + bower, cocoapods, cran, conda, debian, docker, gems, generic, gitlfs, gradle, ivy, maven, npm, nuget, opkg, p2, pypi, sbt, vcs, yum, rpm, composer, conan, chef, puppet, helm, helmoci, go, cargo, terraform, oci )); private String url; diff --git a/services/src/main/java/org/jfrog/artifactory/client/model/impl/VirtualRepositoryBuilderImpl.java b/services/src/main/java/org/jfrog/artifactory/client/model/impl/VirtualRepositoryBuilderImpl.java index eff46cf2..0f3d388b 100644 --- a/services/src/main/java/org/jfrog/artifactory/client/model/impl/VirtualRepositoryBuilderImpl.java +++ b/services/src/main/java/org/jfrog/artifactory/client/model/impl/VirtualRepositoryBuilderImpl.java @@ -15,7 +15,7 @@ */ public class VirtualRepositoryBuilderImpl extends RepositoryBuilderBase implements VirtualRepositoryBuilder { private static Set virtualRepositorySupportedTypes = new HashSet(Arrays.asList( - bower, cran, conda, docker, debian, gems, generic, gitlfs, gradle, ivy, maven, npm, nuget, p2, pypi, sbt, yum, rpm, composer, conan, chef, puppet, helm, go, terraform, oci + bower, cran, conda, docker, debian, gems, generic, gitlfs, gradle, ivy, maven, npm, nuget, p2, pypi, sbt, yum, rpm, composer, conan, chef, puppet, helm, helmoci, go, terraform, oci )); private Collection repositories = Collections.emptyList(); diff --git a/services/src/main/java/org/jfrog/artifactory/client/model/repository/settings/impl/HelmOciRepositorySettingsImpl.java b/services/src/main/java/org/jfrog/artifactory/client/model/repository/settings/impl/HelmOciRepositorySettingsImpl.java new file mode 100644 index 00000000..84c61840 --- /dev/null +++ b/services/src/main/java/org/jfrog/artifactory/client/model/repository/settings/impl/HelmOciRepositorySettingsImpl.java @@ -0,0 +1,21 @@ +package org.jfrog.artifactory.client.model.repository.settings.impl; + +import org.jfrog.artifactory.client.model.PackageType; +import org.jfrog.artifactory.client.model.impl.PackageTypeImpl; +import org.jfrog.artifactory.client.model.repository.settings.OciRepositorySettings; + +public class HelmOciRepositorySettingsImpl extends DockerRepositorySettingsImpl implements OciRepositorySettings { + public static String defaultLayout = "simple-default"; + + public PackageType getPackageType() { + return PackageTypeImpl.helmoci; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof HelmOciRepositorySettingsImpl)) { + return false; + } + return super.equals(o); + } +} diff --git a/services/src/main/resources/artifactory.client.release.properties b/services/src/main/resources/artifactory.client.release.properties index e4e9e90b..d5a6863c 100644 --- a/services/src/main/resources/artifactory.client.release.properties +++ b/services/src/main/resources/artifactory.client.release.properties @@ -1 +1 @@ -version=2.18.0 \ No newline at end of file +version=2.18.x-SNAPSHOT \ No newline at end of file diff --git a/services/src/test/groovy/org/jfrog/artifactory/client/HelmOciPackageTypeRepositoryTests.groovy b/services/src/test/groovy/org/jfrog/artifactory/client/HelmOciPackageTypeRepositoryTests.groovy new file mode 100644 index 00000000..df297892 --- /dev/null +++ b/services/src/test/groovy/org/jfrog/artifactory/client/HelmOciPackageTypeRepositoryTests.groovy @@ -0,0 +1,129 @@ +package org.jfrog.artifactory.client + +import org.hamcrest.CoreMatchers +import org.jfrog.artifactory.client.model.RepositoryType +import org.jfrog.artifactory.client.model.repository.settings.RepositorySettings +import org.jfrog.artifactory.client.model.repository.settings.docker.DockerApiVersion +import org.jfrog.artifactory.client.model.repository.settings.impl.HelmOciRepositorySettingsImpl +import org.testng.annotations.BeforeMethod +import org.testng.annotations.Test + +/** + * test that client correctly sends and receives repository configuration with `helmoci` package type + * + */ +class HelmOciPackageTypeRepositoryTests extends BaseRepositoryTests { + + HelmOciPackageTypeRepositoryTests() { + remoteRepoUrl = "https://registry-1.docker.io" + } + + @Override + RepositorySettings getRepositorySettings(RepositoryType repositoryType) { + def settings = new HelmOciRepositorySettingsImpl() + + settings.with { + // local + dockerApiVersion = DockerApiVersion.V2 + dockerTagRetention = Math.abs(rnd.nextInt()) + + // remote + enableTokenAuthentication = rnd.nextBoolean() + listRemoteFolderItems = rnd.nextBoolean() + } + + return settings + } + + @BeforeMethod + protected void setUp() { + storeArtifactsLocallyInRemoteRepo = true + super.setUp() + } + + @Test(groups = "helmOciPackageTypeRepo") + void testOciLocalRepo() { + artifactory.repositories().create(0, localRepo) + def expectedSettings = localRepo.repositorySettings + + def resp = artifactory.repository(localRepo.getKey()).get() + assertThat(resp, CoreMatchers.notNullValue()) + assertThat(resp.repoLayoutRef, CoreMatchers.is(HelmOciRepositorySettingsImpl.defaultLayout)) + resp.getRepositorySettings().with { + assertThat(packageType, CoreMatchers.is(expectedSettings.getPackageType())) + assertThat(repoLayout, CoreMatchers.is(expectedSettings.getRepoLayout())) + + // local + assertThat(dockerApiVersion, CoreMatchers.is(expectedSettings.getDockerApiVersion())) + assertThat(dockerTagRetention, CoreMatchers.is(expectedSettings.getDockerTagRetention())) + + // remote + assertThat(enableTokenAuthentication, CoreMatchers.is(CoreMatchers.nullValue())) + assertThat(listRemoteFolderItems, CoreMatchers.is(CoreMatchers.nullValue())) + } + } + + @Test(groups = "helmOciPackageTypeRepo") + void testOciFederatedRepo() { + artifactory.repositories().create(0, federatedRepo) + def expectedSettings = federatedRepo.repositorySettings + + def resp = artifactory.repository(federatedRepo.getKey()).get() + assertThat(resp, CoreMatchers.notNullValue()) + assertThat(resp.repoLayoutRef, CoreMatchers.is(HelmOciRepositorySettingsImpl.defaultLayout)) + resp.getRepositorySettings().with { + assertThat(packageType, CoreMatchers.is(expectedSettings.getPackageType())) + assertThat(repoLayout, CoreMatchers.is(expectedSettings.getRepoLayout())) + + // local + assertThat(dockerApiVersion, CoreMatchers.is(expectedSettings.getDockerApiVersion())) + + // remote + assertThat(enableTokenAuthentication, CoreMatchers.is(CoreMatchers.nullValue())) + assertThat(listRemoteFolderItems, CoreMatchers.is(CoreMatchers.nullValue())) + } + } + + @Test(groups = "helmOciPackageTypeRepo") + void testOciRemoteRepo() { + artifactory.repositories().create(0, remoteRepo) + def expectedSettings = remoteRepo.repositorySettings + + def resp = artifactory.repository(remoteRepo.getKey()).get() + assertThat(resp, CoreMatchers.notNullValue()) + assertThat(resp.repoLayoutRef, CoreMatchers.is(HelmOciRepositorySettingsImpl.defaultLayout)) + resp.getRepositorySettings().with { + assertThat(packageType, CoreMatchers.is(expectedSettings.getPackageType())) + assertThat(repoLayout, CoreMatchers.is(expectedSettings.getRepoLayout())) + + // local + assertThat(dockerApiVersion, CoreMatchers.is(expectedSettings.getDockerApiVersion())) + // always in resp payload + + // remote + assertThat(enableTokenAuthentication, CoreMatchers.is(expectedSettings.getEnableTokenAuthentication())) + assertThat(listRemoteFolderItems, CoreMatchers.is(expectedSettings.getListRemoteFolderItems())) + } + } + + @Test(groups = "helmOciPackageTypeRepo") + void testDockerVirtualRepo() { + artifactory.repositories().create(0, virtualRepo) + def expectedSettings = virtualRepo.repositorySettings + + def resp = artifactory.repository(virtualRepo.getKey()).get() + assertThat(resp, CoreMatchers.notNullValue()) + assertThat(resp.repoLayoutRef, CoreMatchers.is(HelmOciRepositorySettingsImpl.defaultLayout)) + resp.getRepositorySettings().with { + assertThat(packageType, CoreMatchers.is(expectedSettings.getPackageType())) + assertThat(repoLayout, CoreMatchers.is(expectedSettings.getRepoLayout())) + + // local + assertThat(dockerApiVersion, CoreMatchers.is(expectedSettings.getDockerApiVersion())) + + // remote + assertThat(enableTokenAuthentication, CoreMatchers.is(CoreMatchers.nullValue())) + assertThat(listRemoteFolderItems, CoreMatchers.is(CoreMatchers.nullValue())) + } + } +}