use of org.eclipse.jkube.kit.common.RegistryServerConfiguration in project jkube by eclipse.
the class JKubeEnricherContext method getDockerJsonConfigString.
// Method used in MOJO
public String getDockerJsonConfigString(final List<RegistryServerConfiguration> settings, final String serverId) {
RegistryServerConfiguration server = RegistryServerConfiguration.getServer(settings, serverId);
if (server == null) {
return "";
}
JsonObject auth = new JsonObject();
auth.add("username", new JsonPrimitive(server.getUsername()));
auth.add("password", new JsonPrimitive(server.getPassword()));
String mail = getConfigurationValue(server, "email");
if (!StringUtils.isBlank(mail)) {
auth.add("email", new JsonPrimitive(mail));
}
JsonObject json = new JsonObject();
json.add(serverId, auth);
return json.toString();
}
use of org.eclipse.jkube.kit.common.RegistryServerConfiguration in project jkube by eclipse.
the class AuthConfigFactoryTest method testGetStandardAuthConfigFromMavenSettings.
@Test
public void testGetStandardAuthConfigFromMavenSettings(@Mocked KitLogger logger) throws IOException {
// Given
List<RegistryServerConfiguration> settings = new ArrayList<>();
settings.add(RegistryServerConfiguration.builder().id("testregistry.io").username("testuser").password("testpass").build());
// When
AuthConfigFactory authConfigFactory = new AuthConfigFactory(logger);
AuthConfig authConfig = authConfigFactory.createAuthConfig(true, true, Collections.emptyMap(), settings, "testuser", "testregistry.io", s -> s);
// Then
assertAuthConfig(authConfig, "testuser", "testpass");
}
use of org.eclipse.jkube.kit.common.RegistryServerConfiguration in project jkube by eclipse.
the class AuthConfigFactoryTest method testGetAuthConfigFromSettings.
@Test
public void testGetAuthConfigFromSettings() {
// Given
List<RegistryServerConfiguration> settings = new ArrayList<>();
settings.add(RegistryServerConfiguration.builder().id("testregistry.io").username("testuser").password("testpass").build());
// When
AuthConfig authConfig = AuthConfigFactory.getAuthConfigFromSettings(settings, "testuser", "testregistry.io", s -> s);
// Then
assertAuthConfig(authConfig, "testuser", "testpass");
}
use of org.eclipse.jkube.kit.common.RegistryServerConfiguration in project jkube by eclipse.
the class HelmService method uploadHelmChart.
/**
* Uploads the charts defined in the provided {@link HelmConfig} to the applicable configured repository.
*
* <p> For Charts with versions ending in "-SNAPSHOT" the {@link HelmConfig#getSnapshotRepository()} is used.
* {@link HelmConfig#getStableRepository()} is used for other versions.
*
* @param helm Configuration for which to generate the Charts.
* @throws BadUploadException in case the chart cannot be uploaded.
* @throws IOException in case of any I/O exception when .
*/
public void uploadHelmChart(HelmConfig helm) throws BadUploadException, IOException {
final HelmRepository helmRepository = selectHelmRepository(helm);
if (isRepositoryValid(helmRepository)) {
final List<RegistryServerConfiguration> registryServerConfigurations = Optional.ofNullable(jKubeConfiguration).map(JKubeConfiguration::getRegistryConfig).map(RegistryConfig::getSettings).orElse(Collections.emptyList());
final UnaryOperator<String> passwordDecryptor = Optional.ofNullable(jKubeConfiguration).map(JKubeConfiguration::getRegistryConfig).map(RegistryConfig::getPasswordDecryptionMethod).orElse(s -> s);
setAuthentication(helmRepository, logger, registryServerConfigurations, passwordDecryptor);
uploadHelmChart(helm, helmRepository);
} else {
String error = "No repository or invalid repository configured for upload";
logger.error(error);
throw new IllegalStateException(error);
}
}
use of org.eclipse.jkube.kit.common.RegistryServerConfiguration in project jkube by eclipse.
the class HelmServiceUtil method setAuthentication.
static void setAuthentication(HelmRepository repository, KitLogger logger, List<RegistryServerConfiguration> registryServerConfigurations, UnaryOperator<String> passwordDecrypter) {
final String id = repository.getName();
final String REPO = "Repo ";
if (repository.getUsername() != null) {
if (repository.getPassword() == null) {
throw new IllegalArgumentException(REPO + id + " has a username but no password defined.");
}
logger.debug(REPO + id + " has credentials defined, skip searching in server list.");
} else {
RegistryServerConfiguration server = registryServerConfigurations.stream().filter(r -> r.getId().equals(id)).findAny().orElse(null);
if (server == null) {
throw new IllegalArgumentException("No credentials found for " + id + " in configuration or settings.xml server list.");
} else {
logger.debug("Use credentials from server list for " + id + ".");
if (server.getUsername() == null || server.getPassword() == null) {
throw new IllegalArgumentException("Repo " + id + " was found in server list but has no username/password.");
}
repository.setUsername(server.getUsername());
repository.setPassword(passwordDecrypter.apply(server.getPassword()));
}
}
}
Aggregations