-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Terraform package type #354
- Loading branch information
Showing
10 changed files
with
287 additions
and
11 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...a/org/jfrog/artifactory/client/model/repository/settings/TerraformRepositorySettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jfrog.artifactory.client.model.repository.settings; | ||
|
||
import org.jfrog.artifactory.client.model.repository.settings.vcs.VcsGitProvider; | ||
import org.jfrog.artifactory.client.model.repository.settings.vcs.VcsType; | ||
|
||
public interface TerraformRepositorySettings extends RepositorySettings{ | ||
|
||
// local and federated settings | ||
enum TerraformType { | ||
module, | ||
provider | ||
} | ||
|
||
// local and federated settings | ||
TerraformType getTerraformType(); | ||
|
||
// remote settings | ||
|
||
// url is already declared in RemoteRepo | ||
|
||
VcsType getVcsType(); | ||
|
||
VcsGitProvider getVcsGitProvider(); | ||
|
||
String getTerraformRegistryUrl(); | ||
|
||
String getTerraformProvidersUrl(); | ||
|
||
String getRemoteRepoLayoutRef(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...og/artifactory/client/model/repository/settings/impl/TerraformRepositorySettingsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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.AbstractRepositorySettings; | ||
import org.jfrog.artifactory.client.model.repository.settings.TerraformRepositorySettings; | ||
import org.jfrog.artifactory.client.model.repository.settings.vcs.VcsGitProvider; | ||
import org.jfrog.artifactory.client.model.repository.settings.vcs.VcsType; | ||
|
||
public class TerraformRepositorySettingsImpl extends AbstractRepositorySettings implements TerraformRepositorySettings { | ||
|
||
public static String defaultLayout = "simple-default"; | ||
public static String moduleLayout = "terraform-module-default"; | ||
public static String providerLayout = "terraform-provider-default"; | ||
private TerraformType terraformType; | ||
private String terraformRegistryUrl; | ||
private String terraformProvidersUrl; | ||
private VcsType vcsType; | ||
private VcsGitProvider vcsGitProvider; | ||
private String remoteRepoLayoutRef; | ||
|
||
public TerraformRepositorySettingsImpl() { | ||
super(defaultLayout); | ||
} | ||
|
||
@Override | ||
public PackageType getPackageType() { | ||
return PackageTypeImpl.terraform; | ||
} | ||
|
||
@Override | ||
public TerraformType getTerraformType() { | ||
return terraformType; | ||
} | ||
|
||
@Override | ||
public VcsType getVcsType() { | ||
return vcsType; | ||
} | ||
|
||
@Override | ||
public VcsGitProvider getVcsGitProvider() { | ||
return vcsGitProvider; | ||
} | ||
|
||
@Override | ||
public String getTerraformRegistryUrl() { | ||
return terraformRegistryUrl; | ||
} | ||
|
||
@Override | ||
public String getTerraformProvidersUrl() { | ||
return terraformProvidersUrl; | ||
} | ||
|
||
@Override | ||
public String getRemoteRepoLayoutRef() { | ||
return remoteRepoLayoutRef; | ||
} | ||
|
||
public void setTerraformType(TerraformType terraformType) { | ||
this.terraformType = terraformType; | ||
} | ||
|
||
public void setVcsType(VcsType vcsType) { | ||
this.vcsType = vcsType; | ||
} | ||
|
||
public void setVcsGitProvider(VcsGitProvider vcsGitProvider) { | ||
this.vcsGitProvider = vcsGitProvider; | ||
} | ||
|
||
public void setTerraformRegistryUrl(String terraformRegistryUrl) { | ||
this.terraformRegistryUrl = terraformRegistryUrl; | ||
} | ||
|
||
public void setTerraformProvidersUrl(String terraformProvidersUrl) { | ||
this.terraformProvidersUrl = terraformProvidersUrl; | ||
} | ||
|
||
public void setRemoteRepoLayoutRef(String remoteRepoLayoutRef) { | ||
this.remoteRepoLayoutRef = remoteRepoLayoutRef; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
...s/src/test/groovy/org/jfrog/artifactory/client/TerraformPackageTypeRepositoryTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package org.jfrog.artifactory.client | ||
|
||
import org.hamcrest.CoreMatchers | ||
import org.jfrog.artifactory.client.model.RepositoryType | ||
import org.jfrog.artifactory.client.model.impl.RepositoryTypeImpl | ||
import org.jfrog.artifactory.client.model.repository.settings.RepositorySettings | ||
import org.jfrog.artifactory.client.model.repository.settings.TerraformRepositorySettings | ||
import org.jfrog.artifactory.client.model.repository.settings.impl.TerraformRepositorySettingsImpl | ||
import org.jfrog.artifactory.client.model.repository.settings.vcs.VcsGitProvider | ||
import org.jfrog.artifactory.client.model.repository.settings.vcs.VcsType | ||
import org.testng.annotations.BeforeMethod | ||
import org.testng.annotations.Test | ||
|
||
class TerraformPackageTypeRepositoryTests extends BaseRepositoryTests { | ||
|
||
TerraformPackageTypeRepositoryTests() { | ||
remoteRepoUrl = "https://github.com" | ||
} | ||
|
||
@Override | ||
RepositorySettings getRepositorySettings(RepositoryType repositoryType) { | ||
|
||
if (repositoryType == RepositoryTypeImpl.REMOTE) { | ||
def settings = new TerraformRepositorySettingsImpl() | ||
settings.with { | ||
repoLayout = defaultLayout | ||
vcsType = VcsType.GIT | ||
vcsGitProvider = VcsGitProvider.GITHUB | ||
terraformRegistryUrl = "https://registry.terraform.io" | ||
terraformProvidersUrl = "https://releases.hashicorp.com" | ||
remoteRepoLayoutRef = defaultLayout | ||
} | ||
return settings | ||
} | ||
|
||
if (repositoryType == RepositoryTypeImpl.VIRTUAL) { | ||
def settings = new TerraformRepositorySettingsImpl() | ||
settings.with { | ||
repoLayout = moduleLayout | ||
} | ||
return settings | ||
} | ||
|
||
if (repositoryType == RepositoryTypeImpl.FEDERATED) { | ||
def settings = new TerraformRepositorySettingsImpl() | ||
settings.with { | ||
terraformType = TerraformRepositorySettings.TerraformType.module | ||
repoLayout = moduleLayout | ||
} | ||
return settings | ||
} | ||
|
||
return null | ||
} | ||
|
||
@BeforeMethod | ||
protected void setUp() { | ||
super.setUp() | ||
} | ||
|
||
@Test(groups = "terraformPackageTypeRepo") | ||
void testTerraformLocalRepoModule() { | ||
def mySettings = new TerraformRepositorySettingsImpl() | ||
mySettings.with { | ||
terraformType = TerraformRepositorySettings.TerraformType.module | ||
repoLayout = moduleLayout | ||
} | ||
|
||
testLocalRepoWithSettings(mySettings) | ||
} | ||
|
||
@Test(groups = "terraformPackageTypeRepo") | ||
void testTerraformLocalRepoProvider() { | ||
def mySettings = new TerraformRepositorySettingsImpl() | ||
mySettings.with { | ||
terraformType = TerraformRepositorySettings.TerraformType.provider | ||
repoLayout = providerLayout | ||
} | ||
|
||
testLocalRepoWithSettings(mySettings) | ||
} | ||
|
||
@Test(groups = "terraformPackageTypeRepo") | ||
void testTerraformRemoteRepo() { | ||
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(expectedSettings.repoLayout)) | ||
assertThat(resp.url, CoreMatchers.is(remoteRepoUrl)) | ||
resp.getRepositorySettings().with { | ||
assertThat(packageType, CoreMatchers.is(expectedSettings.getPackageType())) | ||
|
||
// remote | ||
assertThat(vcsType, CoreMatchers.is(expectedSettings.vcsType)) | ||
assertThat(vcsGitProvider, CoreMatchers.is(expectedSettings.vcsGitProvider)) | ||
assertThat(terraformRegistryUrl, CoreMatchers.is(expectedSettings.terraformRegistryUrl)) | ||
assertThat(terraformProvidersUrl, CoreMatchers.is(expectedSettings.terraformProvidersUrl)) | ||
assertThat(remoteRepoLayoutRef, CoreMatchers.is(expectedSettings.remoteRepoLayoutRef)) | ||
} | ||
} | ||
|
||
@Test(groups = "terraformPackageTypeRepo") | ||
void testTerraformVirtualRepo() { | ||
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(expectedSettings.repoLayout)) | ||
|
||
resp.getRepositorySettings().with { | ||
assertThat(packageType, CoreMatchers.is(expectedSettings.getPackageType())) | ||
} | ||
} | ||
|
||
@Test(groups = "terraformPackageTypeRepo") | ||
void testTerraformFederatedRepo() { | ||
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(expectedSettings.repoLayout)) | ||
|
||
resp.getRepositorySettings().with { | ||
assertThat(packageType, CoreMatchers.is(expectedSettings.getPackageType())) | ||
} | ||
} | ||
|
||
private void testLocalRepoWithSettings(TerraformRepositorySettingsImpl mySettings) { | ||
String id = Long.toString(repoUniqueId) | ||
def myLocalRepo = artifactory.repositories().builders().localRepositoryBuilder() | ||
.key("$REPO_NAME_PREFIX-local-$id") | ||
.description("local-$id") | ||
.notes("notes-${rnd.nextInt()}") | ||
.archiveBrowsingEnabled(rnd.nextBoolean()) | ||
.blackedOut(rnd.nextBoolean()) | ||
.excludesPattern("org/${rnd.nextInt()}/**") | ||
.includesPattern("org/${rnd.nextInt()}/**") | ||
.propertySets(Collections.emptyList()) // no property sets configured | ||
.repositorySettings(mySettings) | ||
.xraySettings(xraySettings) | ||
.customProperties(customProperties) | ||
.build() | ||
artifactory.repositories().create(0, myLocalRepo) | ||
def expectedSettings = myLocalRepo.repositorySettings | ||
|
||
def resp = artifactory.repository(myLocalRepo.getKey()).get() | ||
assertThat(resp, CoreMatchers.notNullValue()) | ||
assertThat(resp.repoLayoutRef, CoreMatchers.is(expectedSettings.repoLayout)) | ||
|
||
resp.getRepositorySettings().with { | ||
assertThat(packageType, CoreMatchers.is(expectedSettings.packageType)) | ||
assertThat(terraformType, CoreMatchers.is(expectedSettings.terraformType)) | ||
} | ||
} | ||
} |