コード例 #1
0
ファイル: BuildCommand.cs プロジェクト: nordseth/Nibbler
        public ValidationResult Validate(ValidationContext context)
        {
            var validationErrors = new List <(string, IEnumerable <string>)>();

            if (!FromImage.HasValue() && !FromImageAlias.HasValue())
            {
                validationErrors.Add(($"--{FromImage.LongName} is required.", new[] { FromImage.LongName }));
            }

            if (!ToImage.HasValue() && !ToImageAlias.HasValue())
            {
                validationErrors.Add(($"--{ToImage.LongName} is required.", new[] { ToImage.LongName }));
            }

#pragma warning disable CS0612 // Type or member is obsolete
            if (!validationErrors.Any() &&
                (Username.HasValue() || Password.HasValue() || Insecure.HasValue() || SkipTlsVerify.HasValue()))
            {
                var srcReg  = ImageHelper.GetRegistryName(GetFromImage());
                var destReg = ImageHelper.GetRegistryName(GetToImage());

                if (srcReg != destReg)
                {
                    var fields = new List <string>();
                    if (Username.HasValue())
                    {
                        fields.Add(Username.LongName);
                    }

                    if (Password.HasValue())
                    {
                        fields.Add(Password.LongName);
                    }

                    if (Insecure.HasValue())
                    {
                        fields.Add(Insecure.LongName);
                    }

                    if (SkipTlsVerify.HasValue())
                    {
                        fields.Add(SkipTlsVerify.LongName);
                    }

                    validationErrors.Add(($"{string.Join(", ", fields)} can only be set if baseImage registry is the same as destination", fields));
                }
            }
#pragma warning restore CS0612 // Type or member is obsolete

            WarnDeprecated();

            if (validationErrors.Any())
            {
                return(new ValidationResult(
                           string.Join(", ", validationErrors.Select(e => e.Item1)),
                           validationErrors.SelectMany(e => e.Item2)));
            }

            return(ValidationResult.Success);
        }
コード例 #2
0
ファイル: BuildCommand.cs プロジェクト: nordseth/Nibbler
        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);
        }