Search in sources :

Example 1 with AuthProperty

use of com.google.cloud.tools.jib.plugins.common.AuthProperty in project jib by GoogleContainerTools.

the class MavenRawConfigurationTest method testGetters.

@Test
public void testGetters() {
    JibPluginConfiguration jibPluginConfiguration = Mockito.mock(JibPluginConfiguration.class);
    EventHandlers eventHandlers = Mockito.mock(EventHandlers.class);
    Server server = Mockito.mock(Server.class);
    Mockito.when(server.getUsername()).thenReturn("maven settings user");
    Mockito.when(server.getPassword()).thenReturn("maven settings password");
    Settings mavenSettings = Mockito.mock(Settings.class);
    Mockito.when(mavenSettings.getServer("base registry")).thenReturn(server);
    MavenSession mavenSession = Mockito.mock(MavenSession.class);
    Mockito.when(mavenSession.getSettings()).thenReturn(mavenSettings);
    FromAuthConfiguration auth = Mockito.mock(FromAuthConfiguration.class);
    Mockito.when(auth.getUsername()).thenReturn("user");
    Mockito.when(auth.getPassword()).thenReturn("password");
    Mockito.when(auth.getAuthDescriptor()).thenReturn("<from><auth>");
    Mockito.when(auth.getUsernameDescriptor()).thenReturn("<from><auth><username>");
    Mockito.when(auth.getPasswordDescriptor()).thenReturn("<from><auth><password>");
    Mockito.when(jibPluginConfiguration.getSession()).thenReturn(mavenSession);
    Mockito.when(jibPluginConfiguration.getBaseImageAuth()).thenReturn(auth);
    Mockito.when(jibPluginConfiguration.getAllowInsecureRegistries()).thenReturn(true);
    Mockito.when(jibPluginConfiguration.getAppRoot()).thenReturn("/app/root");
    Mockito.when(jibPluginConfiguration.getArgs()).thenReturn(Arrays.asList("--log", "info"));
    Mockito.when(jibPluginConfiguration.getBaseImage()).thenReturn("openjdk:15");
    CredHelperConfiguration baseImageCredHelperConfig = Mockito.mock(CredHelperConfiguration.class);
    Mockito.when(baseImageCredHelperConfig.getHelperName()).thenReturn(Optional.of("gcr"));
    Mockito.when(baseImageCredHelperConfig.getEnvironment()).thenReturn(Collections.singletonMap("ENV_VARIABLE", "Value1"));
    Mockito.when(jibPluginConfiguration.getBaseImageCredHelperConfig()).thenReturn(baseImageCredHelperConfig);
    CredHelperConfiguration targetImageCredHelperConfig = Mockito.mock(CredHelperConfiguration.class);
    Mockito.when(targetImageCredHelperConfig.getHelperName()).thenReturn(Optional.of("gcr"));
    Mockito.when(targetImageCredHelperConfig.getEnvironment()).thenReturn(Collections.singletonMap("ENV_VARIABLE", "Value2"));
    Mockito.when(jibPluginConfiguration.getTargetImageCredentialHelperConfig()).thenReturn(targetImageCredHelperConfig);
    Mockito.when(jibPluginConfiguration.getEntrypoint()).thenReturn(Arrays.asList("java", "Main"));
    Mockito.when(jibPluginConfiguration.getEnvironment()).thenReturn(new HashMap<>(ImmutableMap.of("currency", "dollar")));
    Mockito.when(jibPluginConfiguration.getExposedPorts()).thenReturn(Arrays.asList("80/tcp", "0"));
    Mockito.when(jibPluginConfiguration.getJvmFlags()).thenReturn(Arrays.asList("-cp", "."));
    Mockito.when(jibPluginConfiguration.getLabels()).thenReturn(new HashMap<>(ImmutableMap.of("unit", "cm")));
    Mockito.when(jibPluginConfiguration.getMainClass()).thenReturn("com.example.Main");
    Mockito.when(jibPluginConfiguration.getTargetImageAdditionalTags()).thenReturn(new HashSet<>(Arrays.asList("additional", "tags")));
    Mockito.when(jibPluginConfiguration.getUser()).thenReturn("admin:wheel");
    Mockito.when(jibPluginConfiguration.getFilesModificationTime()).thenReturn("2011-12-03T22:42:05Z");
    Mockito.when(jibPluginConfiguration.getDockerClientExecutable()).thenReturn(Paths.get("test"));
    Mockito.when(jibPluginConfiguration.getDockerClientEnvironment()).thenReturn(new HashMap<>(ImmutableMap.of("docker", "client")));
    Mockito.when(jibPluginConfiguration.getDigestOutputPath()).thenReturn(Paths.get("digest/path"));
    Mockito.when(jibPluginConfiguration.getImageIdOutputPath()).thenReturn(Paths.get("id/path"));
    Mockito.when(jibPluginConfiguration.getImageJsonOutputPath()).thenReturn(Paths.get("json/path"));
    Mockito.when(jibPluginConfiguration.getTarOutputPath()).thenReturn(Paths.get("tar/path"));
    MavenRawConfiguration rawConfiguration = new MavenRawConfiguration(jibPluginConfiguration);
    AuthProperty fromAuth = rawConfiguration.getFromAuth();
    Assert.assertEquals("user", fromAuth.getUsername());
    Assert.assertEquals("password", fromAuth.getPassword());
    Assert.assertEquals("<from><auth>", fromAuth.getAuthDescriptor());
    Assert.assertEquals("<from><auth><username>", fromAuth.getUsernameDescriptor());
    Assert.assertEquals("<from><auth><password>", fromAuth.getPasswordDescriptor());
    Assert.assertTrue(rawConfiguration.getAllowInsecureRegistries());
    Assert.assertEquals(Arrays.asList("java", "Main"), rawConfiguration.getEntrypoint().get());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("currency", "dollar")), rawConfiguration.getEnvironment());
    Assert.assertEquals("/app/root", rawConfiguration.getAppRoot());
    Assert.assertEquals("gcr", rawConfiguration.getFromCredHelper().getHelperName().get());
    Assert.assertEquals(Collections.singletonMap("ENV_VARIABLE", "Value1"), rawConfiguration.getFromCredHelper().getEnvironment());
    Assert.assertEquals("gcr", rawConfiguration.getToCredHelper().getHelperName().get());
    Assert.assertEquals(Collections.singletonMap("ENV_VARIABLE", "Value2"), rawConfiguration.getToCredHelper().getEnvironment());
    Assert.assertEquals("openjdk:15", rawConfiguration.getFromImage().get());
    Assert.assertEquals(Arrays.asList("-cp", "."), rawConfiguration.getJvmFlags());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("unit", "cm")), rawConfiguration.getLabels());
    Assert.assertEquals("com.example.Main", rawConfiguration.getMainClass().get());
    Assert.assertEquals(Arrays.asList("80/tcp", "0"), rawConfiguration.getPorts());
    Assert.assertEquals(Arrays.asList("--log", "info"), rawConfiguration.getProgramArguments().get());
    Assert.assertEquals(new HashSet<>(Arrays.asList("additional", "tags")), Sets.newHashSet(rawConfiguration.getToTags()));
    Assert.assertEquals("admin:wheel", rawConfiguration.getUser().get());
    Assert.assertEquals("2011-12-03T22:42:05Z", rawConfiguration.getFilesModificationTime());
    Assert.assertEquals(Paths.get("test"), rawConfiguration.getDockerExecutable().get());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("docker", "client")), rawConfiguration.getDockerEnvironment());
    Assert.assertEquals(Paths.get("digest/path"), jibPluginConfiguration.getDigestOutputPath());
    Assert.assertEquals(Paths.get("id/path"), jibPluginConfiguration.getImageIdOutputPath());
    Assert.assertEquals(Paths.get("json/path"), jibPluginConfiguration.getImageJsonOutputPath());
    Assert.assertEquals(Paths.get("tar/path"), jibPluginConfiguration.getTarOutputPath());
    Mockito.verifyNoMoreInteractions(eventHandlers);
}
Also used : AuthProperty(com.google.cloud.tools.jib.plugins.common.AuthProperty) MavenSession(org.apache.maven.execution.MavenSession) FromAuthConfiguration(com.google.cloud.tools.jib.maven.JibPluginConfiguration.FromAuthConfiguration) Server(org.apache.maven.settings.Server) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) Settings(org.apache.maven.settings.Settings) CredHelperConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.CredHelperConfiguration) Test(org.junit.Test)

Example 2 with AuthProperty

use of com.google.cloud.tools.jib.plugins.common.AuthProperty in project jib by google.

the class GradleRawConfigurationTest method testGetters.

@Test
public void testGetters() {
    JibExtension jibExtension = Mockito.mock(JibExtension.class);
    AuthParameters authParameters = Mockito.mock(AuthParameters.class);
    BaseImageParameters baseImageParameters = Mockito.mock(BaseImageParameters.class);
    TargetImageParameters targetImageParameters = Mockito.mock(TargetImageParameters.class);
    ContainerParameters containerParameters = Mockito.mock(ContainerParameters.class);
    DockerClientParameters dockerClientParameters = Mockito.mock(DockerClientParameters.class);
    OutputPathsParameters outputPathsParameters = Mockito.mock(OutputPathsParameters.class);
    CredHelperParameters fromCredHelperParameters = Mockito.mock(CredHelperParameters.class);
    CredHelperParameters toCredHelperParameters = Mockito.mock(CredHelperParameters.class);
    Mockito.when(authParameters.getUsername()).thenReturn("user");
    Mockito.when(authParameters.getPassword()).thenReturn("password");
    Mockito.when(authParameters.getAuthDescriptor()).thenReturn("from.auth");
    Mockito.when(authParameters.getUsernameDescriptor()).thenReturn("from.auth.username");
    Mockito.when(authParameters.getPasswordDescriptor()).thenReturn("from.auth.password");
    Mockito.when(jibExtension.getFrom()).thenReturn(baseImageParameters);
    Mockito.when(jibExtension.getTo()).thenReturn(targetImageParameters);
    Mockito.when(jibExtension.getContainer()).thenReturn(containerParameters);
    Mockito.when(jibExtension.getDockerClient()).thenReturn(dockerClientParameters);
    Mockito.when(jibExtension.getOutputPaths()).thenReturn(outputPathsParameters);
    Mockito.when(jibExtension.getAllowInsecureRegistries()).thenReturn(true);
    Mockito.when(fromCredHelperParameters.getHelperName()).thenReturn(Optional.of("gcr"));
    Mockito.when(fromCredHelperParameters.getEnvironment()).thenReturn(Collections.singletonMap("ENV_VARIABLE", "Value1"));
    Mockito.when(baseImageParameters.getCredHelper()).thenReturn(fromCredHelperParameters);
    Mockito.when(baseImageParameters.getImage()).thenReturn("openjdk:15");
    Mockito.when(baseImageParameters.getAuth()).thenReturn(authParameters);
    Mockito.when(targetImageParameters.getTags()).thenReturn(new HashSet<>(Arrays.asList("additional", "tags")));
    Mockito.when(toCredHelperParameters.getHelperName()).thenReturn(Optional.of("ecr-login"));
    Mockito.when(toCredHelperParameters.getEnvironment()).thenReturn(Collections.singletonMap("ENV_VARIABLE", "Value2"));
    Mockito.when(targetImageParameters.getCredHelper()).thenReturn(toCredHelperParameters);
    Mockito.when(containerParameters.getAppRoot()).thenReturn("/app/root");
    Mockito.when(containerParameters.getArgs()).thenReturn(Arrays.asList("--log", "info"));
    Mockito.when(containerParameters.getEntrypoint()).thenReturn(Arrays.asList("java", "Main"));
    Mockito.when(containerParameters.getEnvironment()).thenReturn(new HashMap<>(ImmutableMap.of("currency", "dollar")));
    Mockito.when(containerParameters.getJvmFlags()).thenReturn(Arrays.asList("-cp", "."));
    Mockito.when(labels.get()).thenReturn(Collections.singletonMap("unit", "cm"));
    Mockito.when(containerParameters.getLabels()).thenReturn(labels);
    Mockito.when(containerParameters.getMainClass()).thenReturn("com.example.Main");
    Mockito.when(containerParameters.getPorts()).thenReturn(Arrays.asList("80/tcp", "0"));
    Mockito.when(containerParameters.getUser()).thenReturn("admin:wheel");
    Mockito.when(containerParameters.getFilesModificationTime()).thenReturn("2011-12-03T22:42:05Z");
    Mockito.when(dockerClientParameters.getExecutablePath()).thenReturn(Paths.get("test"));
    Mockito.when(dockerClientParameters.getEnvironment()).thenReturn(new HashMap<>(ImmutableMap.of("docker", "client")));
    Mockito.when(outputPathsParameters.getDigestPath()).thenReturn(Paths.get("digest/path"));
    Mockito.when(outputPathsParameters.getImageIdPath()).thenReturn(Paths.get("id/path"));
    Mockito.when(outputPathsParameters.getImageJsonPath()).thenReturn(Paths.get("json/path"));
    Mockito.when(outputPathsParameters.getTarPath()).thenReturn(Paths.get("tar/path"));
    GradleRawConfiguration rawConfiguration = new GradleRawConfiguration(jibExtension);
    AuthProperty fromAuth = rawConfiguration.getFromAuth();
    Assert.assertEquals("user", fromAuth.getUsername());
    Assert.assertEquals("password", fromAuth.getPassword());
    Assert.assertEquals("from.auth", fromAuth.getAuthDescriptor());
    Assert.assertEquals("from.auth.username", fromAuth.getUsernameDescriptor());
    Assert.assertEquals("from.auth.password", fromAuth.getPasswordDescriptor());
    Assert.assertTrue(rawConfiguration.getAllowInsecureRegistries());
    Assert.assertEquals("/app/root", rawConfiguration.getAppRoot());
    Assert.assertEquals(Arrays.asList("java", "Main"), rawConfiguration.getEntrypoint().get());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("currency", "dollar")), rawConfiguration.getEnvironment());
    Assert.assertEquals("gcr", rawConfiguration.getFromCredHelper().getHelperName().get());
    Assert.assertEquals(Collections.singletonMap("ENV_VARIABLE", "Value1"), rawConfiguration.getFromCredHelper().getEnvironment());
    Assert.assertEquals("openjdk:15", rawConfiguration.getFromImage().get());
    Assert.assertEquals(Arrays.asList("-cp", "."), rawConfiguration.getJvmFlags());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("unit", "cm")), rawConfiguration.getLabels());
    Assert.assertEquals("com.example.Main", rawConfiguration.getMainClass().get());
    Assert.assertEquals(Arrays.asList("80/tcp", "0"), rawConfiguration.getPorts());
    Assert.assertEquals(Arrays.asList("--log", "info"), rawConfiguration.getProgramArguments().get());
    Assert.assertEquals(new HashSet<>(Arrays.asList("additional", "tags")), Sets.newHashSet(rawConfiguration.getToTags()));
    Assert.assertEquals("ecr-login", rawConfiguration.getToCredHelper().getHelperName().get());
    Assert.assertEquals(Collections.singletonMap("ENV_VARIABLE", "Value2"), rawConfiguration.getToCredHelper().getEnvironment());
    Assert.assertEquals("admin:wheel", rawConfiguration.getUser().get());
    Assert.assertEquals("2011-12-03T22:42:05Z", rawConfiguration.getFilesModificationTime());
    Assert.assertEquals(Paths.get("test"), rawConfiguration.getDockerExecutable().get());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("docker", "client")), rawConfiguration.getDockerEnvironment());
    Assert.assertEquals(Paths.get("digest/path"), rawConfiguration.getDigestOutputPath());
    Assert.assertEquals(Paths.get("id/path"), rawConfiguration.getImageIdOutputPath());
    Assert.assertEquals(Paths.get("json/path"), rawConfiguration.getImageJsonOutputPath());
    Assert.assertEquals(Paths.get("tar/path"), rawConfiguration.getTarOutputPath());
}
Also used : AuthProperty(com.google.cloud.tools.jib.plugins.common.AuthProperty) Test(org.junit.Test)

Example 3 with AuthProperty

use of com.google.cloud.tools.jib.plugins.common.AuthProperty in project jib by google.

the class MavenSettingsServerCredentials method inferAuth.

/**
 * Retrieves credentials for {@code registry} from Maven settings.
 *
 * @param registry the registry
 * @return the auth info for the registry, or {@link Optional#empty} if none could be retrieved
 */
@Override
public Optional<AuthProperty> inferAuth(String registry) throws InferredAuthException {
    Server server = getServerFromMavenSettings(registry);
    if (server == null) {
        return Optional.empty();
    }
    SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
    SettingsDecryptionResult result = decrypter.decrypt(request);
    // If there are any ERROR or FATAL problems reported, then decryption failed.
    for (SettingsProblem problem : result.getProblems()) {
        if (problem.getSeverity() == SettingsProblem.Severity.ERROR || problem.getSeverity() == SettingsProblem.Severity.FATAL) {
            throw new InferredAuthException("Unable to decrypt server(" + registry + ") info from settings.xml: " + problem);
        }
    }
    Server resultServer = result.getServer();
    String username = resultServer.getUsername();
    String password = resultServer.getPassword();
    return Optional.of(new AuthProperty() {

        @Override
        public String getUsername() {
            return username;
        }

        @Override
        public String getPassword() {
            return password;
        }

        @Override
        public String getAuthDescriptor() {
            return CREDENTIAL_SOURCE;
        }

        @Override
        public String getUsernameDescriptor() {
            return CREDENTIAL_SOURCE;
        }

        @Override
        public String getPasswordDescriptor() {
            return CREDENTIAL_SOURCE;
        }
    });
}
Also used : InferredAuthException(com.google.cloud.tools.jib.plugins.common.InferredAuthException) AuthProperty(com.google.cloud.tools.jib.plugins.common.AuthProperty) Server(org.apache.maven.settings.Server) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionRequest(org.apache.maven.settings.crypto.SettingsDecryptionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Example 4 with AuthProperty

use of com.google.cloud.tools.jib.plugins.common.AuthProperty in project jib by google.

the class MavenRawConfigurationTest method testGetters.

@Test
public void testGetters() {
    JibPluginConfiguration jibPluginConfiguration = Mockito.mock(JibPluginConfiguration.class);
    EventHandlers eventHandlers = Mockito.mock(EventHandlers.class);
    Server server = Mockito.mock(Server.class);
    Mockito.when(server.getUsername()).thenReturn("maven settings user");
    Mockito.when(server.getPassword()).thenReturn("maven settings password");
    Settings mavenSettings = Mockito.mock(Settings.class);
    Mockito.when(mavenSettings.getServer("base registry")).thenReturn(server);
    MavenSession mavenSession = Mockito.mock(MavenSession.class);
    Mockito.when(mavenSession.getSettings()).thenReturn(mavenSettings);
    FromAuthConfiguration auth = Mockito.mock(FromAuthConfiguration.class);
    Mockito.when(auth.getUsername()).thenReturn("user");
    Mockito.when(auth.getPassword()).thenReturn("password");
    Mockito.when(auth.getAuthDescriptor()).thenReturn("<from><auth>");
    Mockito.when(auth.getUsernameDescriptor()).thenReturn("<from><auth><username>");
    Mockito.when(auth.getPasswordDescriptor()).thenReturn("<from><auth><password>");
    Mockito.when(jibPluginConfiguration.getSession()).thenReturn(mavenSession);
    Mockito.when(jibPluginConfiguration.getBaseImageAuth()).thenReturn(auth);
    Mockito.when(jibPluginConfiguration.getAllowInsecureRegistries()).thenReturn(true);
    Mockito.when(jibPluginConfiguration.getAppRoot()).thenReturn("/app/root");
    Mockito.when(jibPluginConfiguration.getArgs()).thenReturn(Arrays.asList("--log", "info"));
    Mockito.when(jibPluginConfiguration.getBaseImage()).thenReturn("openjdk:15");
    CredHelperConfiguration baseImageCredHelperConfig = Mockito.mock(CredHelperConfiguration.class);
    Mockito.when(baseImageCredHelperConfig.getHelperName()).thenReturn(Optional.of("gcr"));
    Mockito.when(baseImageCredHelperConfig.getEnvironment()).thenReturn(Collections.singletonMap("ENV_VARIABLE", "Value1"));
    Mockito.when(jibPluginConfiguration.getBaseImageCredHelperConfig()).thenReturn(baseImageCredHelperConfig);
    CredHelperConfiguration targetImageCredHelperConfig = Mockito.mock(CredHelperConfiguration.class);
    Mockito.when(targetImageCredHelperConfig.getHelperName()).thenReturn(Optional.of("gcr"));
    Mockito.when(targetImageCredHelperConfig.getEnvironment()).thenReturn(Collections.singletonMap("ENV_VARIABLE", "Value2"));
    Mockito.when(jibPluginConfiguration.getTargetImageCredentialHelperConfig()).thenReturn(targetImageCredHelperConfig);
    Mockito.when(jibPluginConfiguration.getEntrypoint()).thenReturn(Arrays.asList("java", "Main"));
    Mockito.when(jibPluginConfiguration.getEnvironment()).thenReturn(new HashMap<>(ImmutableMap.of("currency", "dollar")));
    Mockito.when(jibPluginConfiguration.getExposedPorts()).thenReturn(Arrays.asList("80/tcp", "0"));
    Mockito.when(jibPluginConfiguration.getJvmFlags()).thenReturn(Arrays.asList("-cp", "."));
    Mockito.when(jibPluginConfiguration.getLabels()).thenReturn(new HashMap<>(ImmutableMap.of("unit", "cm")));
    Mockito.when(jibPluginConfiguration.getMainClass()).thenReturn("com.example.Main");
    Mockito.when(jibPluginConfiguration.getTargetImageAdditionalTags()).thenReturn(new HashSet<>(Arrays.asList("additional", "tags")));
    Mockito.when(jibPluginConfiguration.getUser()).thenReturn("admin:wheel");
    Mockito.when(jibPluginConfiguration.getFilesModificationTime()).thenReturn("2011-12-03T22:42:05Z");
    Mockito.when(jibPluginConfiguration.getDockerClientExecutable()).thenReturn(Paths.get("test"));
    Mockito.when(jibPluginConfiguration.getDockerClientEnvironment()).thenReturn(new HashMap<>(ImmutableMap.of("docker", "client")));
    Mockito.when(jibPluginConfiguration.getDigestOutputPath()).thenReturn(Paths.get("digest/path"));
    Mockito.when(jibPluginConfiguration.getImageIdOutputPath()).thenReturn(Paths.get("id/path"));
    Mockito.when(jibPluginConfiguration.getImageJsonOutputPath()).thenReturn(Paths.get("json/path"));
    Mockito.when(jibPluginConfiguration.getTarOutputPath()).thenReturn(Paths.get("tar/path"));
    MavenRawConfiguration rawConfiguration = new MavenRawConfiguration(jibPluginConfiguration);
    AuthProperty fromAuth = rawConfiguration.getFromAuth();
    Assert.assertEquals("user", fromAuth.getUsername());
    Assert.assertEquals("password", fromAuth.getPassword());
    Assert.assertEquals("<from><auth>", fromAuth.getAuthDescriptor());
    Assert.assertEquals("<from><auth><username>", fromAuth.getUsernameDescriptor());
    Assert.assertEquals("<from><auth><password>", fromAuth.getPasswordDescriptor());
    Assert.assertTrue(rawConfiguration.getAllowInsecureRegistries());
    Assert.assertEquals(Arrays.asList("java", "Main"), rawConfiguration.getEntrypoint().get());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("currency", "dollar")), rawConfiguration.getEnvironment());
    Assert.assertEquals("/app/root", rawConfiguration.getAppRoot());
    Assert.assertEquals("gcr", rawConfiguration.getFromCredHelper().getHelperName().get());
    Assert.assertEquals(Collections.singletonMap("ENV_VARIABLE", "Value1"), rawConfiguration.getFromCredHelper().getEnvironment());
    Assert.assertEquals("gcr", rawConfiguration.getToCredHelper().getHelperName().get());
    Assert.assertEquals(Collections.singletonMap("ENV_VARIABLE", "Value2"), rawConfiguration.getToCredHelper().getEnvironment());
    Assert.assertEquals("openjdk:15", rawConfiguration.getFromImage().get());
    Assert.assertEquals(Arrays.asList("-cp", "."), rawConfiguration.getJvmFlags());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("unit", "cm")), rawConfiguration.getLabels());
    Assert.assertEquals("com.example.Main", rawConfiguration.getMainClass().get());
    Assert.assertEquals(Arrays.asList("80/tcp", "0"), rawConfiguration.getPorts());
    Assert.assertEquals(Arrays.asList("--log", "info"), rawConfiguration.getProgramArguments().get());
    Assert.assertEquals(new HashSet<>(Arrays.asList("additional", "tags")), Sets.newHashSet(rawConfiguration.getToTags()));
    Assert.assertEquals("admin:wheel", rawConfiguration.getUser().get());
    Assert.assertEquals("2011-12-03T22:42:05Z", rawConfiguration.getFilesModificationTime());
    Assert.assertEquals(Paths.get("test"), rawConfiguration.getDockerExecutable().get());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("docker", "client")), rawConfiguration.getDockerEnvironment());
    Assert.assertEquals(Paths.get("digest/path"), jibPluginConfiguration.getDigestOutputPath());
    Assert.assertEquals(Paths.get("id/path"), jibPluginConfiguration.getImageIdOutputPath());
    Assert.assertEquals(Paths.get("json/path"), jibPluginConfiguration.getImageJsonOutputPath());
    Assert.assertEquals(Paths.get("tar/path"), jibPluginConfiguration.getTarOutputPath());
    Mockito.verifyNoMoreInteractions(eventHandlers);
}
Also used : AuthProperty(com.google.cloud.tools.jib.plugins.common.AuthProperty) MavenSession(org.apache.maven.execution.MavenSession) FromAuthConfiguration(com.google.cloud.tools.jib.maven.JibPluginConfiguration.FromAuthConfiguration) Server(org.apache.maven.settings.Server) EventHandlers(com.google.cloud.tools.jib.event.EventHandlers) Settings(org.apache.maven.settings.Settings) CredHelperConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.CredHelperConfiguration) Test(org.junit.Test)

Example 5 with AuthProperty

use of com.google.cloud.tools.jib.plugins.common.AuthProperty in project jib by GoogleContainerTools.

the class GradleRawConfigurationTest method testGetters.

@Test
public void testGetters() {
    JibExtension jibExtension = Mockito.mock(JibExtension.class);
    AuthParameters authParameters = Mockito.mock(AuthParameters.class);
    BaseImageParameters baseImageParameters = Mockito.mock(BaseImageParameters.class);
    TargetImageParameters targetImageParameters = Mockito.mock(TargetImageParameters.class);
    ContainerParameters containerParameters = Mockito.mock(ContainerParameters.class);
    DockerClientParameters dockerClientParameters = Mockito.mock(DockerClientParameters.class);
    OutputPathsParameters outputPathsParameters = Mockito.mock(OutputPathsParameters.class);
    CredHelperParameters fromCredHelperParameters = Mockito.mock(CredHelperParameters.class);
    CredHelperParameters toCredHelperParameters = Mockito.mock(CredHelperParameters.class);
    Mockito.when(authParameters.getUsername()).thenReturn("user");
    Mockito.when(authParameters.getPassword()).thenReturn("password");
    Mockito.when(authParameters.getAuthDescriptor()).thenReturn("from.auth");
    Mockito.when(authParameters.getUsernameDescriptor()).thenReturn("from.auth.username");
    Mockito.when(authParameters.getPasswordDescriptor()).thenReturn("from.auth.password");
    Mockito.when(jibExtension.getFrom()).thenReturn(baseImageParameters);
    Mockito.when(jibExtension.getTo()).thenReturn(targetImageParameters);
    Mockito.when(jibExtension.getContainer()).thenReturn(containerParameters);
    Mockito.when(jibExtension.getDockerClient()).thenReturn(dockerClientParameters);
    Mockito.when(jibExtension.getOutputPaths()).thenReturn(outputPathsParameters);
    Mockito.when(jibExtension.getAllowInsecureRegistries()).thenReturn(true);
    Mockito.when(fromCredHelperParameters.getHelperName()).thenReturn(Optional.of("gcr"));
    Mockito.when(fromCredHelperParameters.getEnvironment()).thenReturn(Collections.singletonMap("ENV_VARIABLE", "Value1"));
    Mockito.when(baseImageParameters.getCredHelper()).thenReturn(fromCredHelperParameters);
    Mockito.when(baseImageParameters.getImage()).thenReturn("openjdk:15");
    Mockito.when(baseImageParameters.getAuth()).thenReturn(authParameters);
    Mockito.when(targetImageParameters.getTags()).thenReturn(new HashSet<>(Arrays.asList("additional", "tags")));
    Mockito.when(toCredHelperParameters.getHelperName()).thenReturn(Optional.of("ecr-login"));
    Mockito.when(toCredHelperParameters.getEnvironment()).thenReturn(Collections.singletonMap("ENV_VARIABLE", "Value2"));
    Mockito.when(targetImageParameters.getCredHelper()).thenReturn(toCredHelperParameters);
    Mockito.when(containerParameters.getAppRoot()).thenReturn("/app/root");
    Mockito.when(containerParameters.getArgs()).thenReturn(Arrays.asList("--log", "info"));
    Mockito.when(containerParameters.getEntrypoint()).thenReturn(Arrays.asList("java", "Main"));
    Mockito.when(containerParameters.getEnvironment()).thenReturn(new HashMap<>(ImmutableMap.of("currency", "dollar")));
    Mockito.when(containerParameters.getJvmFlags()).thenReturn(Arrays.asList("-cp", "."));
    Mockito.when(labels.get()).thenReturn(Collections.singletonMap("unit", "cm"));
    Mockito.when(containerParameters.getLabels()).thenReturn(labels);
    Mockito.when(containerParameters.getMainClass()).thenReturn("com.example.Main");
    Mockito.when(containerParameters.getPorts()).thenReturn(Arrays.asList("80/tcp", "0"));
    Mockito.when(containerParameters.getUser()).thenReturn("admin:wheel");
    Mockito.when(containerParameters.getFilesModificationTime()).thenReturn("2011-12-03T22:42:05Z");
    Mockito.when(dockerClientParameters.getExecutablePath()).thenReturn(Paths.get("test"));
    Mockito.when(dockerClientParameters.getEnvironment()).thenReturn(new HashMap<>(ImmutableMap.of("docker", "client")));
    Mockito.when(outputPathsParameters.getDigestPath()).thenReturn(Paths.get("digest/path"));
    Mockito.when(outputPathsParameters.getImageIdPath()).thenReturn(Paths.get("id/path"));
    Mockito.when(outputPathsParameters.getImageJsonPath()).thenReturn(Paths.get("json/path"));
    Mockito.when(outputPathsParameters.getTarPath()).thenReturn(Paths.get("tar/path"));
    GradleRawConfiguration rawConfiguration = new GradleRawConfiguration(jibExtension);
    AuthProperty fromAuth = rawConfiguration.getFromAuth();
    Assert.assertEquals("user", fromAuth.getUsername());
    Assert.assertEquals("password", fromAuth.getPassword());
    Assert.assertEquals("from.auth", fromAuth.getAuthDescriptor());
    Assert.assertEquals("from.auth.username", fromAuth.getUsernameDescriptor());
    Assert.assertEquals("from.auth.password", fromAuth.getPasswordDescriptor());
    Assert.assertTrue(rawConfiguration.getAllowInsecureRegistries());
    Assert.assertEquals("/app/root", rawConfiguration.getAppRoot());
    Assert.assertEquals(Arrays.asList("java", "Main"), rawConfiguration.getEntrypoint().get());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("currency", "dollar")), rawConfiguration.getEnvironment());
    Assert.assertEquals("gcr", rawConfiguration.getFromCredHelper().getHelperName().get());
    Assert.assertEquals(Collections.singletonMap("ENV_VARIABLE", "Value1"), rawConfiguration.getFromCredHelper().getEnvironment());
    Assert.assertEquals("openjdk:15", rawConfiguration.getFromImage().get());
    Assert.assertEquals(Arrays.asList("-cp", "."), rawConfiguration.getJvmFlags());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("unit", "cm")), rawConfiguration.getLabels());
    Assert.assertEquals("com.example.Main", rawConfiguration.getMainClass().get());
    Assert.assertEquals(Arrays.asList("80/tcp", "0"), rawConfiguration.getPorts());
    Assert.assertEquals(Arrays.asList("--log", "info"), rawConfiguration.getProgramArguments().get());
    Assert.assertEquals(new HashSet<>(Arrays.asList("additional", "tags")), Sets.newHashSet(rawConfiguration.getToTags()));
    Assert.assertEquals("ecr-login", rawConfiguration.getToCredHelper().getHelperName().get());
    Assert.assertEquals(Collections.singletonMap("ENV_VARIABLE", "Value2"), rawConfiguration.getToCredHelper().getEnvironment());
    Assert.assertEquals("admin:wheel", rawConfiguration.getUser().get());
    Assert.assertEquals("2011-12-03T22:42:05Z", rawConfiguration.getFilesModificationTime());
    Assert.assertEquals(Paths.get("test"), rawConfiguration.getDockerExecutable().get());
    Assert.assertEquals(new HashMap<>(ImmutableMap.of("docker", "client")), rawConfiguration.getDockerEnvironment());
    Assert.assertEquals(Paths.get("digest/path"), rawConfiguration.getDigestOutputPath());
    Assert.assertEquals(Paths.get("id/path"), rawConfiguration.getImageIdOutputPath());
    Assert.assertEquals(Paths.get("json/path"), rawConfiguration.getImageJsonOutputPath());
    Assert.assertEquals(Paths.get("tar/path"), rawConfiguration.getTarOutputPath());
}
Also used : AuthProperty(com.google.cloud.tools.jib.plugins.common.AuthProperty) Test(org.junit.Test)

Aggregations

AuthProperty (com.google.cloud.tools.jib.plugins.common.AuthProperty)6 Server (org.apache.maven.settings.Server)4 Test (org.junit.Test)4 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)2 FromAuthConfiguration (com.google.cloud.tools.jib.maven.JibPluginConfiguration.FromAuthConfiguration)2 InferredAuthException (com.google.cloud.tools.jib.plugins.common.InferredAuthException)2 CredHelperConfiguration (com.google.cloud.tools.jib.plugins.common.RawConfiguration.CredHelperConfiguration)2 MavenSession (org.apache.maven.execution.MavenSession)2 Settings (org.apache.maven.settings.Settings)2 SettingsProblem (org.apache.maven.settings.building.SettingsProblem)2 DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)2 SettingsDecryptionRequest (org.apache.maven.settings.crypto.SettingsDecryptionRequest)2 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)2