MCPcopy
hub / github.com/elastic/go-elasticsearch / addrFromCloudID

Function addrFromCloudID

elasticsearch.go:732–750  ·  view source on GitHub ↗

addrFromCloudID extracts the Elasticsearch URL from CloudID. See: https://www.elastic.co/guide/en/cloud/current/ec-cloud-id.html

(input string)

Source from the content-addressed store, hash-verified

730// addrFromCloudID extracts the Elasticsearch URL from CloudID.
731// See: https://www.elastic.co/guide/en/cloud/current/ec-cloud-id.html
732func 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
752func initUserAgent() string {
753 var b strings.Builder

Callers 3

resolveOptionsFunction · 0.85
newTransportFunction · 0.85
TestCloudIDFunction · 0.85

Calls 1

SplitMethod · 0.45

Tested by 1

TestCloudIDFunction · 0.68