Skip to content

Commit

Permalink
feat(cli): support maven repository with basic auth for plugin instal…
Browse files Browse the repository at this point in the history
…l command

close #521
  • Loading branch information
tchiotludo committed Sep 1, 2023
1 parent 2b61a0a commit 0965126
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.kestra.cli.commands.plugins;

import io.micronaut.http.uri.UriBuilder;
import org.apache.commons.io.FilenameUtils;
import io.kestra.cli.AbstractCommand;
import io.kestra.cli.plugins.PluginDownloader;
import io.kestra.cli.plugins.RepositoryConfig;
import io.kestra.core.utils.IdUtils;
import org.apache.http.client.utils.URIBuilder;
import picocli.CommandLine;

import java.net.URI;
Expand All @@ -15,8 +17,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import jakarta.inject.Inject;

import static io.kestra.core.utils.Rethrow.throwConsumer;

@CommandLine.Command(
name = "install",
description = "install a plugin"
Expand Down Expand Up @@ -52,7 +58,28 @@ public Integer call() throws Exception {

if (repositories != null) {
Arrays.stream(repositories)
.forEach(s -> pluginDownloader.addRepository(new RepositoryConfig(IdUtils.create(), "default", s.toString())));
.forEach(throwConsumer(s -> {
URIBuilder uriBuilder = new URIBuilder(s);

RepositoryConfig.RepositoryConfigBuilder builder = RepositoryConfig.builder()
.id(IdUtils.create())
.type("default");

if (uriBuilder.getUserInfo() != null) {
int index = uriBuilder.getUserInfo().indexOf(":");

builder.basicAuth(new RepositoryConfig.BasicAuth(
uriBuilder.getUserInfo().substring(0, index),
uriBuilder.getUserInfo().substring(index + 1)
));

uriBuilder.setUserInfo(null);
}

builder.url(uriBuilder.build().toString());

pluginDownloader.addRepository(builder.build());
}));
}

List<URL> resolveUrl = pluginDownloader.resolve(dependencies);
Expand Down
21 changes: 16 additions & 5 deletions cli/src/main/java/io/kestra/cli/plugins/PluginDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import io.micronaut.core.annotation.Nullable;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import org.eclipse.aether.util.repository.AuthenticationBuilder;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -79,14 +81,23 @@ public List<URL> resolve(List<String> dependencies) throws DependencyResolutionE
private List<RemoteRepository> remoteRepositories() {
return repositoryConfigs
.stream()
.map(repositoryConfig ->
new RemoteRepository.Builder(
.map(repositoryConfig -> {
var build = new RemoteRepository.Builder(
repositoryConfig.getId(),
repositoryConfig.getType(),
repositoryConfig.getUrl()
)
.build()
)
);

if (repositoryConfig.getBasicAuth() != null) {
var authenticationBuilder = new AuthenticationBuilder();
authenticationBuilder.addUsername(repositoryConfig.getBasicAuth().getUsername());
authenticationBuilder.addPassword(repositoryConfig.getBasicAuth().getPassword());

build.setAuthentication(authenticationBuilder.build());
}

return build.build();
})
.collect(Collectors.toList());
}

Expand Down
16 changes: 16 additions & 0 deletions cli/src/main/java/io/kestra/cli/plugins/RepositoryConfig.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
package io.kestra.cli.plugins;

import io.kestra.core.models.annotations.PluginProperty;
import io.micronaut.context.annotation.EachProperty;
import io.micronaut.context.annotation.Parameter;
import io.micronaut.core.annotation.Introspected;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@EachProperty("kestra.plugins.repositories")
@Getter
@AllArgsConstructor
@Builder
public class RepositoryConfig {
String id;

String type = "default";

String url;

BasicAuth basicAuth;

@Getter
@AllArgsConstructor
public static class BasicAuth {
private String username;
private String password;
}

public RepositoryConfig(@Parameter String id) {
this.id = id;
}
Expand Down

0 comments on commit 0965126

Please sign in to comment.