-
Notifications
You must be signed in to change notification settings - Fork 0
/
kfe
72 lines (59 loc) · 1.38 KB
/
kfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
set -e
. functions
ES_DEFAULT_PORT=9200
ES_SERVICE_NAMESPACE=fleet-system
ES_SERVICE_NAME=fleet-elasticsearch-es-http
ES_SECRET_NAME=fleet-elasticsearch-es-elastic-user
ES_SECRET_KEY=elastic
usage() {
cat <<END
Send HTTP query to Elasticsearch (with curl) through a kube port forward inside a Fleet cluster.
Usage:
$0 [options] <path query> [<curl arg> ...]
Options:
--context, -c <STRING>
Name of the Kubernetes context
--port, -p [<INTEGER>:]<INTEGER>
Elasticsearch HTTP API cluster port number optionnaly preceded by local port forward ($ES_DEFAULT_PORT)
--help, -h
Display this help
END
exit 2
}
context=
port=$ES_DEFAULT_PORT
path=
while [[ $# -gt 0 ]]; do
case $1 in
--context | -c)
context=$2
shift 2 || usage
;;
--port | -p)
port=$2
shift 2 || usage
;;
--help | -h)
usage
;;
--)
shift
break
;;
-*)
error "Unknown option: $1"
;;
*)
break
;;
esac
done
path=$1
shift || usage
args=()
[[ $context ]] && args+=(--context "$context")
args+=(-n fleet-system)
pass_b64=$(kubectl "${args[@]}" get secret "$ES_SECRET_NAME" --template={{.data."$ES_SECRET_KEY"}}) || error "Failed getting password from Elasticsearch secret"
pass=$(base64 -d <<< "$pass_b64") || error "Failed base64 decode password from Elasticsearch secret"
kfh "${args[@]}" svc/$ES_SERVICE_NAME "$port" "$path" -u "$ES_SECRET_KEY:$pass" -H content-type:application/json "$@"