Beispiel #1
0
        internal (Registry from, Registry to) CreateRegistries()
        {
            var registryLogger          = CreateLogger("REGRY");
            var dockerConfigCredentials = new DockerConfigCredentials(DockerConfig.Value());

            var fromUri = ImageHelper.GetRegistryBaseUrl(GetFromImage(), Insecure.HasValue() || FromInsecure.HasValue() || FromInsecureAlias.HasValue());
            var toUri   = ImageHelper.GetRegistryBaseUrl(GetToImage(), Insecure.HasValue() || ToInsecure.HasValue() || ToInsecureAlias.HasValue());

            var fromRegAuthHandler = CreateFromRegistryAuthHandler(registryLogger, dockerConfigCredentials, fromUri == toUri);
            var fromSkipTlsVerify  = FromSkipTlsVerify.HasValue() || FromSkipTlsVerifyAlias.HasValue() || (fromUri == toUri && SkipTlsVerify.HasValue());
            var fromRegistry       = new Registry(fromUri, registryLogger, fromRegAuthHandler, fromSkipTlsVerify);

            registryLogger.LogDebug($"using {fromUri} for pull{(fromSkipTlsVerify ? ", skipTlsVerify" : "")}");

            var toRegAuthHandler = CreateToRegistryAuthHandler(registryLogger, dockerConfigCredentials, fromUri == toUri);
            var toSkipTlsVerify  = ToSkipTlsVerify.HasValue() || ToSkipTlsVerifyAlias.HasValue() || (fromUri == toUri && SkipTlsVerify.HasValue());
            var toRegistry       = new Registry(toUri, registryLogger, toRegAuthHandler, toSkipTlsVerify);

            registryLogger.LogDebug($"using {toUri} for push{(toSkipTlsVerify ? ", skipTlsVerify" : "")}");

            return(fromRegistry, toRegistry);
        }
Beispiel #2
0
        private AuthenticationHandler CreateFromRegistryAuthHandler(ILogger registryLogger, DockerConfigCredentials dockerConfigCredentials, bool sameAsTo)
        {
            var fromRegAuthHandler = new AuthenticationHandler(
                ImageHelper.GetRegistryName(GetFromImage()),
                dockerConfigCredentials,
                registryLogger);

            if (FromUsername.HasValue() && FromPassword.HasValue())
            {
                fromRegAuthHandler.SetCredentials(FromUsername.Value(), FromPassword.Value());
            }
#pragma warning disable CS0612 // Type or member is obsolete
            else if (sameAsTo && Username.HasValue() && Password.HasValue())
            {
                fromRegAuthHandler.SetCredentials(Username.Value(), Password.Value());
            }
#pragma warning restore CS0612 // Type or member is obsolete

            return(fromRegAuthHandler);
        }