addrFromCloudID extracts the Elasticsearch URL from CloudID. See: https://www.elastic.co/guide/en/cloud/current/ec-cloud-id.html
(input string)
| 730 | // addrFromCloudID extracts the Elasticsearch URL from CloudID. |
| 731 | // See: https://www.elastic.co/guide/en/cloud/current/ec-cloud-id.html |
| 732 | func addrFromCloudID(input string) (string, error) { |
| 733 | var scheme = "https://" |
| 734 | |
| 735 | values := strings.Split(input, ":") |
| 736 | if len(values) != 2 { |
| 737 | return "", fmt.Errorf("unexpected format: %q", input) |
| 738 | } |
| 739 | data, err := base64.StdEncoding.DecodeString(values[1]) |
| 740 | if err != nil { |
| 741 | return "", err |
| 742 | } |
| 743 | parts := strings.Split(string(data), "$") |
| 744 | |
| 745 | if len(parts) < 2 { |
| 746 | return "", fmt.Errorf("invalid encoded value: %s", parts) |
| 747 | } |
| 748 | |
| 749 | return fmt.Sprintf("%s%s.%s", scheme, parts[1], parts[0]), nil |
| 750 | } |
| 751 | |
| 752 | func initUserAgent() string { |
| 753 | var b strings.Builder |