]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/run-backend-rook-api-request.sh
import 15.2.9
[ceph.git] / ceph / src / pybind / mgr / dashboard / run-backend-rook-api-request.sh
CommitLineData
11fdf7f2
TL
1#!/bin/bash
2
3#
4# Query k8s to determine where the mgr is running and how to reach the
5# dashboard from the local machine. This assumes that the dashboard is being
6# exposed via a nodePort service
7CURR_DIR=`pwd`
8K8S_NAMESPACE='rook-ceph'
9
10HOST=$(kubectl get pods -n $K8S_NAMESPACE -l "app=rook-ceph-mgr" -o json | jq .items[0].spec.nodeName | sed s/\"//g)
11if [ "$HOST" = "minikube" ]; then
12 HOST=$(minikube ip)
13fi
14PORT=$(kubectl get service -n $K8S_NAMESPACE rook-ceph-mgr-dashboard -o yaml | grep nodePort: | awk '{print $2}')
15API_URL="https://${HOST}:${PORT}"
16
17#
18# Rook automagically sets up an "admin" account with a random PW and stuffs
19# that into a k8s secret. This fetches it.
20#
21PASSWD=$(kubectl -n $K8S_NAMESPACE get secret rook-ceph-dashboard-password -o yaml | grep "password:" | awk '{print $2}' | base64 --decode)
22
23if [ "$API_URL" = "null" ]; then
24 echo "Couldn't retrieve API URL, exiting..." >&2
25 exit 1
26fi
27cd $CURR_DIR
28
29TOKEN=`curl --insecure -s -H "Content-Type: application/json" -X POST \
30 -d "{\"username\":\"admin\",\"password\":\"${PASSWD}\"}" $API_URL/api/auth \
31 | jq .token | sed -e 's/"//g'`
32
33echo "METHOD: $1"
34echo "URL: ${API_URL}${2}"
35echo "DATA: $3"
36echo ""
37
38curl --insecure -s -b /tmp/cd-cookie.txt -H "Authorization: Bearer $TOKEN " \
39 -H "Content-Type: application/json" -X $1 -d "$3" ${API_URL}$2 | jq
40