Skip to content

Commit

Permalink
feat: support --pass-credentials option when adding repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter YOUNGS committed May 30, 2024
1 parent 8eed3e9 commit 9a33c5a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ Parameter | Type | User Property | Required | Description
`<repositoryCache>` | string | helm.repositoryCache | false | path to the file containing cached repository indexes
`<repositoryConfig>` | string | helm.repositoryConfig | false | path to the file containing repository names and URLs
`<repositoryAddForceUpdate>`| boolean | helm.repo.add.force-update | false | If `true`, replaces (overwrite) the repo if they already exists.
`<repositoryAddPassCredentials>`| boolean | helm.repo.add.pass-credentials | false | If `true`, pass credentials to all domains
`<helmExtraRepos>` | list of [HelmRepository](./src/main/java/io/kokuwa/maven/helm/pojo/HelmRepository.java) | | false | adds extra repositories while init
`<uploadRepoStable>`| [HelmRepository](./src/main/java/io/kokuwa/maven/helm/pojo/HelmRepository.java) | | false | Upload repository for stable charts
`<uploadRepoSnapshot>`| [HelmRepository](./src/main/java/io/kokuwa/maven/helm/pojo/HelmRepository.java) | | false | Upload repository for snapshot charts (determined by version postfix 'SNAPSHOT')
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/io/kokuwa/maven/helm/InitMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ public class InitMojo extends AbstractHelmMojo {
@Parameter(property = "helm.repo.add.force-update", defaultValue = "false")
private boolean repositoryAddForceUpdate;

/**
* If <code>true</code>, pass credentials to all domains. Can be also specified on repository level in
* "helmExtraRepos".
*
* @since 6.15.0
*/
@Parameter(property = "helm.repo.add.pass-credentials", defaultValue = "false")
private boolean repositoryAddPassCredentials;

/**
* Download url of helm.
*
Expand Down Expand Up @@ -210,7 +219,8 @@ private void addRepository(HelmRepository repository, boolean authenticationRequ
getLog().info("Adding repo [" + repository + "]");
HelmExecutable helm = helm()
.arguments("repo", "add", repository.getName(), repository.getUrl())
.flag("force-update", repositoryAddForceUpdate || repository.isForceUpdate());
.flag("force-update", repositoryAddForceUpdate || repository.isForceUpdate())
.flag("pass-credentials", repositoryAddPassCredentials || repository.isPassCredentials());
PasswordAuthentication auth = authenticationRequired ? getAuthentication(repository) : null;
if (auth != null) {
helm.flag("username", auth.getUserName()).flag("password", String.valueOf(auth.getPassword()));
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/kokuwa/maven/helm/pojo/HelmRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ public class HelmRepository {
* @since 6.6.0
*/
private boolean forceUpdate = false;

/**
* If <code>true</code>, pass credentials to all domains (useful when the chart archive is on a different domain
* from the index.yaml, for example on a CDN)
*
* @since 6.15.0
*/
private boolean passCredentials = false;
}
38 changes: 38 additions & 0 deletions src/test/java/io/kokuwa/maven/helm/InitMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,44 @@ void allKindsOfRepositories(InitMojo mojo) {
"repo add extra3 https://example.org/extra3");
}

@DisplayName("with flag --pass-credentials")
@Test
void withPassCredentialsForAll(InitMojo mojo) {
mojo.setAddDefaultRepo(true);
mojo.setAddUploadRepos(true);
mojo.setRepositoryAddPassCredentials(true);
mojo.setHelmExtraRepos(new HelmRepository[] { new HelmRepository()
.setName("example")
.setUrl("https://example.org/repo/example")
.setPassCredentials(true) });
mojo.setUploadRepoStable(new HelmRepository()
.setType(RepoType.ARTIFACTORY)
.setName("example-stable")
.setUrl("https://example.org/repo/stable"));
mojo.setUploadRepoSnapshot(new HelmRepository()
.setType(RepoType.ARTIFACTORY)
.setName("example-snapshot")
.setUrl("https://example.org/repo/snapshot"));
assertHelm(mojo,
"repo add stable " + InitMojo.STABLE_HELM_REPO + " --pass-credentials",
"repo add example-stable https://example.org/repo/stable --pass-credentials",
"repo add example-snapshot https://example.org/repo/snapshot --pass-credentials",
"repo add example https://example.org/repo/example --pass-credentials");
}

@DisplayName("with flag --pass-credentials for single repository")
@Test
void withPassCredentialsForSingleRepository(InitMojo mojo) {
mojo.setAddDefaultRepo(true);
mojo.setHelmExtraRepos(new HelmRepository[] { new HelmRepository()
.setName("example")
.setUrl("https://example.org/repo/example")
.setPassCredentials(true) });
assertHelm(mojo,
"repo add stable " + InitMojo.STABLE_HELM_REPO,
"repo add example https://example.org/repo/example --pass-credentials");
}

private File createTempDirectory() {
return assertDoesNotThrow(() -> Files.createTempDirectory("helm-maven-plugin-test")).toFile();
}
Expand Down

0 comments on commit 9a33c5a

Please sign in to comment.