Skip to content

Commit

Permalink
Allow custom port in cloud.id
Browse files Browse the repository at this point in the history
Make it possible for the host section from the cloud.id to contain
a port. If the port is not specified, 443 is used, like before.

This is proposed fix for elastic#7794.
  • Loading branch information
tsg committed Aug 6, 2018
1 parent 551b2a9 commit 1a41f56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 12 additions & 3 deletions libbeat/cloudid/cloudid.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,18 @@ func decodeCloudID(cloudID string) (string, string, error) {
return "", "", errors.Errorf("Expected at least 3 parts in %s", string(decoded))
}

// 4. form the URLs
esURL := url.URL{Scheme: "https", Host: fmt.Sprintf("%s.%s:443", words[1], words[0])}
kibanaURL := url.URL{Scheme: "https", Host: fmt.Sprintf("%s.%s:443", words[2], words[0])}
// 4. extract port from the host
host := words[0]
port := "443"
idx = strings.LastIndex(host, ":")
if idx >= 0 {
port = host[idx+1:]
host = host[:idx]
}

// 5. form the URLs
esURL := url.URL{Scheme: "https", Host: fmt.Sprintf("%s.%s:%s", words[1], host, port)}
kibanaURL := url.URL{Scheme: "https", Host: fmt.Sprintf("%s.%s:%s", words[2], host, port)}

return esURL.String(), kibanaURL.String(), nil
}
Expand Down
5 changes: 5 additions & 0 deletions libbeat/cloudid/cloudid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func TestDecode(t *testing.T) {
expectedEsURL: "https://8a0283af041f195f7729bc04c66a0fce.us-central1.gcp.cloud.es.io:443",
expectedKibanaURL: "https://0cd5cd568eebe53c89eb7cae5bac8b37.us-central1.gcp.cloud.es.io:443",
},
{
cloudID: "custom-port:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvOjkyNDMkYWMzMWViYjkwMjQxNzczMTU3MDQzYzM0ZmQyNmZkNDYkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA=",
expectedEsURL: "https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:9243",
expectedKibanaURL: "https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:9243",
},
}

for _, test := range tests {
Expand Down

0 comments on commit 1a41f56

Please sign in to comment.