public void TestGetImageConfiguration_registryImage() { CredentialRetriever credentialRetriever = Mock.Of <CredentialRetriever>(); Containerizer containerizer = Containerizer.To( RegistryImage.Named("registry/image").AddCredentialRetriever(credentialRetriever)); ImageConfiguration imageConfiguration = containerizer.GetImageConfiguration(); Assert.AreEqual("registry/image", imageConfiguration.GetImage().ToString()); Assert.AreEqual( new[] { credentialRetriever }, imageConfiguration.GetCredentialRetrievers()); }
/** * Adds {@link CredentialRetriever} to fetch push/pull credentials for the image. Credential * retrievers are attempted in the order in which they are specified until credentials are * successfully retrieved. * * <p>Example usage: * * <pre>{@code * .addCredentialRetriever(() => { * if (!Files.exists("secret.txt") { * return Optional.empty(); * } * try { * string password = fetchPasswordFromFile("secret.txt"); * return Credential.basic("myaccount", password); * * } catch (IOException ex) { * throw new CredentialRetrievalException("Failed to load password", ex); * } * }) * }</pre> * * @param credentialRetriever the {@link CredentialRetriever} to add * @return this */ public RegistryImage AddCredentialRetriever(CredentialRetriever credentialRetriever) { credentialRetrievers.Add(credentialRetriever); return(this); }
/** * Fetches the credentials. <b>Implementations must be thread-safe.</b> * * <p>Implementations should return {@link Optional#empty} if no credentials could be fetched with * this {@link CredentialRetriever} (and so other credential retrieval methods may be tried), or * throw an exception something went wrong when fetching the credentials. * * @return the fetched credentials or {@link Optional#empty} if no credentials could be fetched * with this provider * @throws CredentialRetrievalException if the credential retrieval encountered an exception */ public static Maybe <Credential> Retrieve(this CredentialRetriever c) { c = c ?? throw new ArgumentNullException(nameof(c)); return(c()); }