private DockerInfo createDockerInfo(String dockerImage, Map<String, String> dockerCredentials) { if (dockerImage == null) { return null; } DockerInfo dockerInfo = new DockerInfo(dockerImage); String username = dockerCredentials.get("username"); String password = dockerCredentials.get("password"); if (username == null || password == null) { return dockerInfo; } DockerCredentials credentials = new DockerCredentials(username, password); dockerInfo.setDockerCredentials(credentials); return dockerInfo; }
@Test public void testWithValidImageAndCredentials() { List<Map<String, Object>> parameters = new ArrayList<>(); Map<String, Object> moduleParameters = new HashMap<>(); Map<String, String> dockerParameters = new HashMap<>(); String sampleImage = "cloudfoundry/test-app"; String username = "someUsername"; String password = "somePassword"; dockerParameters.put("image", sampleImage); dockerParameters.put("username", username); dockerParameters.put("password", password); moduleParameters.put("docker", dockerParameters); parameters.add(moduleParameters); DockerInfo actualDockerInfo = dockerInfoParser.parse(parameters); DockerInfo expectedDockerInfo = new DockerInfo(sampleImage); expectedDockerInfo.setDockerCredentials(new DockerCredentials(username, password)); assertEquals(expectedDockerInfo.getImage(), actualDockerInfo.getImage()); assertEquals(expectedDockerInfo.getDockerCredentials() .getUsername(), actualDockerInfo.getDockerCredentials() .getUsername()); assertEquals(expectedDockerInfo.getDockerCredentials() .getPassword(), actualDockerInfo.getDockerCredentials() .getPassword()); }
@Test public void testWithValidImageWithoutUserCredentials() { List<Map<String, Object>> parameters = new ArrayList<>(); Map<String, Object> moduleParameters = new HashMap<>(); Map<String, String> dockerParameters = new HashMap<>(); String sampleImage = "cloudfoundry/test-app"; dockerParameters.put("image", sampleImage); moduleParameters.put("docker", dockerParameters); parameters.add(moduleParameters); DockerInfo actualDockerInfo = dockerInfoParser.parse(parameters); DockerInfo expectedDockerInfo = new DockerInfo(sampleImage); assertEquals(expectedDockerInfo.getImage(), actualDockerInfo.getImage()); assertEquals(expectedDockerInfo.getDockerCredentials(), actualDockerInfo.getDockerCredentials()); }
appRequest.put("docker_image", dockerInfo.getImage()); if (dockerInfo.getDockerCredentials() != null) { appRequest.put("docker_credentials", dockerInfo.getDockerCredentials());
private Map<String, Object> createStagingParameters(Staging staging) { Map<String, Object> stagingParameters = new HashMap<>(); if (staging.getBuildpackUrl() != null) { stagingParameters.put(BUILDPACK_PARAMETER, staging.getBuildpackUrl()); } if (staging.getCommand() != null) { stagingParameters.put(COMMAND_PARAMETER, staging.getCommand()); } if (staging.getHealthCheckTimeout() != null) { stagingParameters.put(HEALTH_CHECK_TIMEOUT_PARAMETER, staging.getHealthCheckTimeout()); } if (staging.getHealthCheckType() != null) { stagingParameters.put(HEALTH_CHECK_TYPE_PARAMETER, staging.getHealthCheckType()); } if (staging.getHealthCheckHttpEndpoint() != null) { stagingParameters.put(HEALTH_CHECK_HTTP_ENDPOINT_PARAMETER, staging.getHealthCheckHttpEndpoint()); } if (staging.isSshEnabled() != null) { stagingParameters.put(ENABLE_SSH_PARAMETER, staging.isSshEnabled()); } if (staging.getDockerInfo() != null) { stagingParameters.put(DOCKER_IMAGE, staging.getDockerInfo().getImage()); if (staging.getDockerInfo().getDockerCredentials() != null) { stagingParameters.put(DOCKER_CREDENTIALS, staging.getDockerInfo().getDockerCredentials()); } } return stagingParameters; }
.getImage()); if (staging.getDockerInfo() .getDockerCredentials() != null) { appRequest.put("docker_credentials", staging.getDockerInfo() .getDockerCredentials());
private DockerInfo getDockerInfo(Map<String, String> docker) { if (docker == null) { return null; } String image = docker.get("image"); if (image == null) { return null; } DockerInfo dockerInfo = new DockerInfo(image); String username = docker.get("username"); String password = docker.get("password"); if (username == null || password == null) { return dockerInfo; } DockerCredentials dockerCredentials = new DockerCredentials(username, password); dockerInfo.setDockerCredentials(dockerCredentials); return dockerInfo; }
execution.getStepLogger() .info(Messages.CREATING_APP_FROM_DOCKER_IMAGE, app.getName(), app.getDockerInfo() .getImage());
execution.getStepLogger() .info(Messages.CREATING_APP_FROM_DOCKER_IMAGE, app.getName(), app.getDockerInfo() .getImage());