(ctx *cli.Context, caURL string)
| 669 | } |
| 670 | |
| 671 | func parseCaURL(ctx *cli.Context, caURL string) (string, error) { |
| 672 | if !strings.Contains(caURL, "://") { |
| 673 | caURL = "https://" + caURL |
| 674 | } |
| 675 | u, err := url.Parse(caURL) |
| 676 | if err != nil { |
| 677 | return "", errs.InvalidFlagValueMsg(ctx, "ca-url", caURL, "invalid URL") |
| 678 | } |
| 679 | if u.Scheme != "https" { |
| 680 | return "", errs.InvalidFlagValueMsg(ctx, "ca-url", caURL, "must have https scheme") |
| 681 | } |
| 682 | |
| 683 | hostname := u.Hostname() |
| 684 | host := hostname |
| 685 | if u.Port() != "" { |
| 686 | host += ":" + u.Port() |
| 687 | } |
| 688 | _, _, err = net.SplitHostPort(host) |
| 689 | // if host represents a valid IPv6 address, ensure that it contains brackets |
| 690 | if err != nil && strings.Contains(err.Error(), "too many colons in address") { |
| 691 | // this is most probably an IPv6 without brackets, e.g. ::1, 2001:0db8:85a3:0000:0000:8a2e:0370:7334 |
| 692 | // in case a port was appended to this wrong format, we try to extract the port, then check if it's |
| 693 | // still a valid IPv6: 2001:0db8:85a3:0000:0000:8a2e:0370:7334:8443 (8443 is the port). If none of |
| 694 | // these cases, then the input dns is not changed. |
| 695 | lastIndex := strings.LastIndex(host, ":") |
| 696 | hostPart, portPart := host[:lastIndex], host[lastIndex+1:] |
| 697 | if ip := net.ParseIP(hostPart); ip != nil { |
| 698 | hostname = "[" + hostPart + "]:" + portPart |
| 699 | } else if ip := net.ParseIP(host); ip != nil { |
| 700 | hostname = "[" + host + "]" |
| 701 | } |
| 702 | u.Host = hostname |
| 703 | } |
| 704 | |
| 705 | return fmt.Sprintf("%s://%s", u.Scheme, u.Host), nil |
| 706 | } |
| 707 | |
| 708 | // FirstStringOf returns the value of the first defined flag from the input list. |
| 709 | // If no defined flags, returns first flag with non-empty default value. |
searching dependent graphs…