private IEnumerable ResolveIngressesUrls()

in src/library/Client/ManagementClients/KubernetesManagementClient.cs [350:408]


        private IEnumerable<Uri> ResolveIngressesUrls(IEnumerable<V1Ingress> k8sIngresses, CancellationToken cancellationToken, string routingHeaderValue = null)
        {
            if (k8sIngresses == null)
            {
                return null;
            }

            var result = new List<Uri>();
            k8sIngresses.ExecuteForEach(k8sIngress =>
            {
                if (k8sIngress?.Spec?.Rules == null)
                {
                    return;
                }

                k8sIngress.Spec.Rules.ExecuteForEach(rule =>
                {
                    if (rule?.Host == null || rule?.Http?.Paths == null)
                    {
                        return;
                    }

                    var usesHttps = k8sIngress?.Spec?.Tls?.Any(tls => tls?.Hosts?.Any(host => StringComparer.OrdinalIgnoreCase.Equals(host, rule.Host)) == true) == true;
                    var protocol = usesHttps ? "https://" : "http://";

                    rule.Http.Paths.ExecuteForEach(path =>
                    {
                        if (path?.Backend?.Service?.Name == null)
                        {
                            return;
                        }

                        // empty path should default to "/"
                        if (path.Path == null)
                        {
                            path.Path = "/";
                        }

                        // Check if the path is for an ACME challenge in case of HTTPS let's encrypt
                        if (path.Path.Contains(Common.Constants.Https.AcmePath))
                        {
                            return;
                        }

                        var host = string.IsNullOrEmpty(routingHeaderValue) ? $"{protocol}{rule.Host}" : $"{protocol}{routingHeaderValue}.{rule.Host}";

                        try
                        {
                            result.Add(new Uri(new Uri(host), path.Path));
                        }
                        catch (UriFormatException e)
                        {
                            _log.Warning("Failed to create URL for host '{0}' and relativePath '{1}': {2}", host, path.Path, e.Message);
                        }
                    }, cancellationToken);
                }, cancellationToken);
            }, cancellationToken);
            return result;
        }