예제 #1
0
        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
 private string GetFromImage()
 {
     return(FromImage.HasValue() ? FromImage.Value() : FromImageAlias.Value());
 }