default SELF from(String dockerImageName) { new DockerImageName(dockerImageName).assertValid(); return ((SELF) this).withStatement(new SingleArgumentStatement("FROM", dockerImageName)); } }
private String effectiveRegistryName(DockerImageName dockerImageName) { return StringUtils.defaultIfEmpty(dockerImageName.getRegistry(), DEFAULT_REGISTRY_NAME); }
@Override protected final String resolve() { Logger logger = DockerLoggerFactory.getLogger(imageName.toString()); listImagesCmd = listImagesCmd.withImageNameFilter(imageName.toString()); final PullImageResultCallback callback = new PullImageResultCallback(); dockerClient .pullImageCmd(imageName.getUnversionedPart()) .withTag(imageName.getVersionPart()) .exec(callback); callback.awaitCompletion(); return imageName.toString(); } catch (DockerClientException e) { throw new ContainerFetchException("Failed to get Docker client for " + imageName, e);
public RemoteDockerImage(String dockerImageName) { imageName = new DockerImageName(dockerImageName); }
@Override public String toString() { if (versioning == null) { return getUnversionedPart(); } else { return getUnversionedPart() + versioning.getSeparator() + versioning.toString(); } }
public RemoteDockerImage(@NonNull String repository, @NonNull String tag) { imageName = new DockerImageName(repository, tag); }
private void testValid(String s) { new DockerImageName(s).assertValid(); }
public AuthConfig effectiveAuthConfig(String imageName) { // allow docker-java auth config to be used as a fallback AuthConfig fallbackAuthConfig; try { fallbackAuthConfig = delegate.effectiveAuthConfig(imageName); } catch (Exception e) { log.debug("Delegate call to effectiveAuthConfig failed with cause: '{}'. " + "Resolution of auth config will continue using RegistryAuthLocator.", e.getMessage()); fallbackAuthConfig = new AuthConfig(); } // try and obtain more accurate auth config using our resolution final DockerImageName parsed = new DockerImageName(imageName); final AuthConfig effectiveAuthConfig = RegistryAuthLocator.instance() .lookupAuthConfig(parsed, fallbackAuthConfig); log.debug("Effective auth config [{}]", toSafeString(effectiveAuthConfig)); return effectiveAuthConfig; }
@Override protected final String resolve() { Logger logger = DockerLoggerFactory.getLogger(imageName.toString()); DockerClient dockerClient = DockerClientFactory.instance().client(); try { listImagesCmd = listImagesCmd.withImageNameFilter(imageName.toString()); dockerClient.pullImageCmd(imageName.getUnversionedPart()).withTag(imageName.getVersionPart()).exec(callback); callback.awaitCompletion(); AVAILABLE_IMAGE_NAME_CACHE.add(imageName);
@java.lang.Override @java.lang.SuppressWarnings("all") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof DockerImageName)) return false; final DockerImageName other = (DockerImageName) o; final java.lang.Object this$registry = this.getRegistry(); final java.lang.Object other$registry = other.getRegistry(); if (this$registry == null ? other$registry != null : !this$registry.equals(other$registry)) return false; final java.lang.Object this$repo = this.repo; final java.lang.Object other$repo = other.repo; if (this$repo == null ? other$repo != null : !this$repo.equals(other$repo)) return false; final java.lang.Object this$versioning = this.versioning; final java.lang.Object other$versioning = other.versioning; if (this$versioning == null ? other$versioning != null : !this$versioning.equals(other$versioning)) return false; return true; }
private void testInvalid(String myname) { try { new DockerImageName(myname).assertValid(); fail(); } catch (IllegalArgumentException expected) { } } }
@Test public void lookupAuthConfigWithCredentialsNotFound() throws URISyntaxException { Map<String, String> notFoundMessagesReference = new HashMap<>(); final RegistryAuthLocator authLocator = createTestAuthLocator("config-with-store.json", notFoundMessagesReference); DockerImageName dockerImageName = new DockerImageName("registry2.example.com/org/repo"); final AuthConfig authConfig = authLocator.lookupAuthConfig(dockerImageName, new AuthConfig()); assertNull("No username should have been obtained from a credential store", authConfig.getUsername()); assertNull("No secret should have been obtained from a credential store", authConfig.getPassword()); assertEquals("Should have one 'credentials not found' message discovered", 1, notFoundMessagesReference.size()); String discoveredMessage = notFoundMessagesReference.values().iterator().next(); assertEquals( "Not correct message discovered", "Fake credentials not found on credentials store 'https://not.a.real.registry/url'", discoveredMessage); }
@java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { final int PRIME = 59; int result = 1; final java.lang.Object $registry = this.getRegistry(); result = result * PRIME + ($registry == null ? 43 : $registry.hashCode()); final java.lang.Object $repo = this.repo; result = result * PRIME + ($repo == null ? 43 : $repo.hashCode()); final java.lang.Object $versioning = this.versioning; result = result * PRIME + ($versioning == null ? 43 : $versioning.hashCode()); return result; } }
default SELF from(String dockerImageName) { new DockerImageName(dockerImageName).assertValid(); return ((SELF) this).withStatement(new SingleArgumentStatement("FROM", dockerImageName)); } }
@Test public void testThatAuthLocatorIsUsed() throws Exception { final DockerImageName expectedName = new DockerImageName(testImageNameWithTag); final AuthConfig authConfig = new AuthConfig() .withUsername("testuser") .withPassword("notasecret") .withRegistryAddress("http://" + testRegistryAddress); // Replace the RegistryAuthLocator singleton with our mock, for the duration of this test final RegistryAuthLocator mockAuthLocator = Mockito.mock(RegistryAuthLocator.class); RegistryAuthLocator.setInstance(mockAuthLocator); when(mockAuthLocator.lookupAuthConfig(eq(expectedName), any())) .thenReturn(authConfig); // a push will use the auth locator for authentication, although that isn't the goal of this test putImageInRegistry(); // actually start a container, which will require an authenticated pull try (final GenericContainer container = new GenericContainer<>(testImageNameWithTag) .withCommand("/bin/sh", "-c", "sleep 10")) { container.start(); assertTrue("container started following an authenticated pull", container.isRunning()); } }
private String effectiveRegistryName(DockerImageName dockerImageName) { return StringUtils.defaultIfEmpty(dockerImageName.getRegistry(), DEFAULT_REGISTRY_NAME); }
@Test public void lookupAuthConfigWithoutCredentials() throws URISyntaxException { final RegistryAuthLocator authLocator = createTestAuthLocator("config-empty.json"); final AuthConfig authConfig = authLocator.lookupAuthConfig(new DockerImageName("unauthenticated.registry.org/org/repo"), new AuthConfig()); assertEquals("Default docker registry URL is set on auth config", "https://index.docker.io/v1/", authConfig.getRegistryAddress()); assertNull("No username is set", authConfig.getUsername()); assertNull("No password is set", authConfig.getPassword()); }
@Test public void lookupUsingHelperEmptyAuth() throws URISyntaxException { final RegistryAuthLocator authLocator = createTestAuthLocator("config-empty-auth-with-helper.json"); final AuthConfig authConfig = authLocator.lookupAuthConfig(new DockerImageName("registry.example.com/org/repo"), new AuthConfig()); assertEquals("Correct server URL is obtained from a credential store", "url", authConfig.getRegistryAddress()); assertEquals("Correct username is obtained from a credential store", "username", authConfig.getUsername()); assertEquals("Correct secret is obtained from a credential store", "secret", authConfig.getPassword()); }
@Test public void lookupAuthConfigUsingHelper() throws URISyntaxException { final RegistryAuthLocator authLocator = createTestAuthLocator("config-with-helper.json"); final AuthConfig authConfig = authLocator.lookupAuthConfig(new DockerImageName("registry.example.com/org/repo"), new AuthConfig()); assertEquals("Correct server URL is obtained from a credential store", "url", authConfig.getRegistryAddress()); assertEquals("Correct username is obtained from a credential store", "username", authConfig.getUsername()); assertEquals("Correct secret is obtained from a credential store", "secret", authConfig.getPassword()); }
@Test public void lookupNonEmptyAuthWithHelper() throws URISyntaxException { final RegistryAuthLocator authLocator = createTestAuthLocator("config-existing-auth-with-helper.json"); final AuthConfig authConfig = authLocator.lookupAuthConfig(new DockerImageName("registry.example.com/org/repo"), new AuthConfig()); assertEquals("Correct server URL is obtained from a credential helper", "url", authConfig.getRegistryAddress()); assertEquals("Correct username is obtained from a credential helper", "username", authConfig.getUsername()); assertEquals("Correct password is obtained from a credential helper", "secret", authConfig.getPassword()); }