-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_applications.sh
executable file
·72 lines (56 loc) · 1.95 KB
/
list_applications.sh
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
#!/bin/bash
# Copyright (C) CampusIoT, - All Rights Reserved
# Written by CampusIoT Dev Team, 2016-2018
# ------------------------------------------------
# List all the applications
# ------------------------------------------------
# Parameters
if [[ $# -ne 1 ]] ; then
echo "Usage: $0 JWT"
exit 1
fi
TOKEN="$1"
AUTH="Grpc-Metadata-Authorization: Bearer $TOKEN"
#sudo npm install -g jwt-cli
#jwt $TOKEN
# Installation
if ! [ -x "$(command -v jq)" ]; then
echo 'jq is not installed. Installing jq ...'
sudo apt-get install -y jq
fi
if ! [ -x "$(command -v curl)" ]; then
echo 'curl is not installed. Installing curl ...'
sudo apt-get install -y curl
fi
# Content-Type
ACCEPT_JSON="Accept: application/json"
ACCEPT_CSV="Accept: text/csv"
CONTENT_JSON="Content-Type: application/json"
CONTENT_CSV="Content-Type: text/csv"
# LOCAL
#PORT=8888
#URL=http://localhost:$PORT
# PROD
PORT=443
URL=https://lns.campusiot.imag.fr:$PORT
# Operations
#CURL="curl --verbose"
#CURL="curl --verbose --insecure"
CURL="curl -s --insecure"
GET="${CURL} -X GET --header \""$ACCEPT_JSON"\""
POST="${CURL} -X POST --header \""$ACCEPT_JSON"\""
PUT="${CURL} -X PUT --header \""$ACCEPT_JSON"\""
DELETE="${CURL} -X DELETE --header \""$ACCEPT_JSON"\""
OPTIONS="${CURL} -X OPTIONS --header \""$ACCEPT_JSON"\""
HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
# https://stedolan.github.io/jq/manual/
echo "============================"
echo "Organizations"
echo "----------------------------"
${GET} --header "$AUTH" --header "$CONTENT_JSON" "${URL}/api/organizations?limit=9999" > .organizations.json
jq '.result[] | ( .id + ": " + .name + " - " + .displayName)' .organizations.json
echo "============================"
echo "Applications"
echo "----------------------------"
${GET} --header "$AUTH" --header "$CONTENT_JSON" "${URL}/api/applications?limit=9999" > .applications.json
jq '.result[] | ( .id + ": " + .name + " - " + .organizationID + " - " + .description)' .applications.json