Esempio n. 1
0
        public void TestParse_dockerHub_user()
        {
            const string   imageReferenceString = "someuser/someimage";
            ImageReference imageReference       = ImageReference.Parse(imageReferenceString);

            Assert.AreEqual("registry-1.docker.io", imageReference.GetRegistry());
            Assert.AreEqual("someuser/someimage", imageReference.GetRepository());
            Assert.AreEqual("latest", imageReference.GetTag());
        }
Esempio n. 2
0
        public void TestParse_dockerHub_official()
        {
            const string   imageReferenceString = "busybox";
            ImageReference imageReference       = ImageReference.Parse(imageReferenceString);

            Assert.AreEqual("registry-1.docker.io", imageReference.GetRegistry());
            Assert.AreEqual("library/busybox", imageReference.GetRepository());
            Assert.AreEqual("latest", imageReference.GetTag());
        }
Esempio n. 3
0
        public async Task TestAuthenticateAsync()
        {
            ImageReference        dockerHubImageReference = ImageReference.Parse("library/busybox");
            RegistryAuthenticator registryAuthenticator   =
                await RegistryClient.CreateFactory(
                    EventHandlers.NONE,
                    dockerHubImageReference.GetRegistry(),
                    dockerHubImageReference.GetRepository())
                .NewRegistryClient()
                .GetRegistryAuthenticatorAsync().ConfigureAwait(false);

            Assert.IsNotNull(registryAuthenticator);
            Authorization authorization = await registryAuthenticator.AuthenticatePullAsync(null).ConfigureAwait(false);

            // Checks that some token was received.
            Assert.IsTrue(0 < authorization.GetToken().Length);
        }
Esempio n. 4
0
        private void VerifyParse(string registry, string repository, string tagSeparator, string tag)
        {
            // Gets the expected parsed components.
            string expectedRegistry = registry;

            if (string.IsNullOrEmpty(expectedRegistry))
            {
                expectedRegistry = "registry-1.docker.io";
            }
            string expectedRepository = repository;

            if ("registry-1.docker.io" == expectedRegistry && repository.IndexOf('/', StringComparison.Ordinal) < 0)
            {
                expectedRepository = "library/" + expectedRepository;
            }
            string expectedTag = tag;

            if (string.IsNullOrEmpty(expectedTag))
            {
                expectedTag = "latest";
            }

            // Builds the image reference to parse.
            StringBuilder imageReferenceBuilder = new StringBuilder();

            if (!string.IsNullOrEmpty(registry))
            {
                imageReferenceBuilder.Append(registry).Append('/');
            }
            imageReferenceBuilder.Append(repository);
            if (!string.IsNullOrEmpty(tag))
            {
                imageReferenceBuilder.Append(tagSeparator).Append(tag);
            }

            ImageReference imageReference = ImageReference.Parse(imageReferenceBuilder.ToString());

            Assert.AreEqual(expectedRegistry, imageReference.GetRegistry());
            Assert.AreEqual(expectedRepository, imageReference.GetRepository());
            Assert.AreEqual(expectedTag, imageReference.GetTag());
        }
Esempio n. 5
0
        /**
         * Creates a new {@link CredentialRetriever} for retrieving credentials via a Docker credential
         * helper, such as {@code docker-credential-gcr}.
         *
         * @param credentialHelper the credential helper executable
         * @return a new {@link CredentialRetriever}
         * @see <a
         *     href="https://github.com/docker/docker-credential-helpers#development">https://github.com/docker/docker-credential-helpers#development</a>
         */
        public CredentialRetriever DockerCredentialHelper(SystemPath credentialHelper)
        {
            return(() =>
            {
                logger(LogEvent.Info("Checking credentials from " + credentialHelper));

                try
                {
                    return Maybe.Of(RetrieveFromDockerCredentialHelper(credentialHelper));
                }
                catch (CredentialHelperUnhandledServerUrlException)
                {
                    logger(
                        LogEvent.Info(
                            "No credentials for " + imageReference.GetRegistry() + " in " + credentialHelper));
                    return Maybe.Empty <Credential>();
                }
                catch (IOException ex)
                {
                    throw new CredentialRetrievalException(ex);
                }
            });
        }