Created
November 16, 2018 20:32
-
-
Save graphaelli/726b1dc49f607f800f54cafe7323751c to your computer and use it in GitHub Desktop.
cloud integration tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ex | |
if [ -z "$4" ]; then | |
echo "usage: $0 <cloud_id> <es_pass> <apm_secret_token> <apm_server_url>" | |
exit 1 | |
fi | |
CLOUD_ID=$1 | |
ES_PASS=$2 | |
APM_SECRET_TOKEN=$3 | |
APM_SERVER_URL=$4 | |
ES_URL=$(cloudid ${CLOUD_ID} ${ES_PASS}) | |
./scripts/compose.py start 6.5 \ | |
--no-elasticsearch \ | |
--no-kibana \ | |
--no-apm-server \ | |
--with-agent-go-net-http \ | |
--with-agent-nodejs-express \ | |
--with-agent-python-django \ | |
--with-agent-python-flask \ | |
--apm-server-url=${APM_SERVER_URL} \ | |
--apm-server-secret-token=${APM_SECRET_TOKEN} | |
ES_URL=${ES_URL} pytest -v tests/agent/test_python.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/base64" | |
"fmt" | |
"net/url" | |
"os" | |
"strings" | |
"github.com/pkg/errors" | |
) | |
const defaultCloudPort = "443" | |
// extractPortFromName takes a string in the form `id:port` and returns the | |
// ID and the port. If there's no `:`, the default port is returned | |
func extractPortFromName(word string, defaultPort string) (id, port string) { | |
idx := strings.LastIndex(word, ":") | |
if idx >= 0 { | |
return word[:idx], word[idx+1:] | |
} | |
return word, defaultPort | |
} | |
// decodeCloudID decodes the cloud.id into elasticsearch-URL and kibana-URL | |
func decodeCloudID(cloudID string, esPass string) (string, string, error) { | |
// 1. Ignore anything before `:`. | |
idx := strings.LastIndex(cloudID, ":") | |
if idx >= 0 { | |
cloudID = cloudID[idx+1:] | |
} | |
// 2. base64 decode | |
decoded, err := base64.StdEncoding.DecodeString(cloudID) | |
if err != nil { | |
return "", "", errors.Wrapf(err, "base64 decoding failed on %s", cloudID) | |
} | |
// 3. separate based on `$` | |
words := strings.Split(string(decoded), "$") | |
if len(words) < 3 { | |
return "", "", errors.Errorf("Expected at least 3 parts in %s", string(decoded)) | |
} | |
// 4. extract port from the ES and Kibana host, or use 443 as the default | |
host, port := extractPortFromName(words[0], defaultCloudPort) | |
esID, esPort := extractPortFromName(words[1], port) | |
kbID, kbPort := extractPortFromName(words[2], port) | |
// 5. form the URLs | |
esURL := url.URL{Scheme: "https", Host: fmt.Sprintf("%s.%s:%s", esID, host, esPort)} | |
kibanaURL := url.URL{Scheme: "https", Host: fmt.Sprintf("%s.%s:%s", kbID, host, kbPort)} | |
if esPass != "" { | |
esURL.User = url.UserPassword("elastic", esPass) | |
} | |
return esURL.String(), kibanaURL.String(), nil | |
} | |
func main() { | |
var cloudId, esPass string | |
switch len(os.Args) { | |
case 1: | |
fmt.Printf("usage: %s <cloudid> [espass]", os.Args[0]) | |
return | |
case 3: | |
esPass = os.Args[2] | |
fallthrough | |
case 2: | |
cloudId = os.Args[1] | |
} | |
if es, _, err := decodeCloudID(cloudId, esPass); err != nil { | |
panic(err) | |
} else { | |
fmt.Println(es) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment