Search in sources :

Example 1 with RegistryServerConfiguration

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();
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) RegistryServerConfiguration(org.eclipse.jkube.kit.common.RegistryServerConfiguration)

Example 2 with RegistryServerConfiguration

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");
}
Also used : ArrayList(java.util.ArrayList) AwsSdkAuthConfigFactory(org.eclipse.jkube.kit.build.service.docker.auth.ecr.AwsSdkAuthConfigFactory) AuthConfig(org.eclipse.jkube.kit.build.api.auth.AuthConfig) RegistryServerConfiguration(org.eclipse.jkube.kit.common.RegistryServerConfiguration) Test(org.junit.Test)

Example 3 with RegistryServerConfiguration

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");
}
Also used : ArrayList(java.util.ArrayList) AuthConfig(org.eclipse.jkube.kit.build.api.auth.AuthConfig) RegistryServerConfiguration(org.eclipse.jkube.kit.common.RegistryServerConfiguration) Test(org.junit.Test)

Example 4 with RegistryServerConfiguration

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);
    }
}
Also used : HelmServiceUtil.selectHelmRepository(org.eclipse.jkube.kit.resource.helm.HelmServiceUtil.selectHelmRepository) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) RegistryServerConfiguration(org.eclipse.jkube.kit.common.RegistryServerConfiguration)

Example 5 with RegistryServerConfiguration

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()));
        }
    }
}
Also used : RegistryServerConfiguration(org.eclipse.jkube.kit.common.RegistryServerConfiguration)

Aggregations

RegistryServerConfiguration (org.eclipse.jkube.kit.common.RegistryServerConfiguration)6 ArrayList (java.util.ArrayList)2 AuthConfig (org.eclipse.jkube.kit.build.api.auth.AuthConfig)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 AwsSdkAuthConfigFactory (org.eclipse.jkube.kit.build.service.docker.auth.ecr.AwsSdkAuthConfigFactory)1 JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)1 HelmServiceUtil.selectHelmRepository (org.eclipse.jkube.kit.resource.helm.HelmServiceUtil.selectHelmRepository)1