forked from TheJumpCloud/Extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJC_CommandTriggerExample.sh
More file actions
executable file
·85 lines (68 loc) · 1.97 KB
/
JC_CommandTriggerExample.sh
File metadata and controls
executable file
·85 lines (68 loc) · 1.97 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#########################################################################################
#
# JC_CommandTriggerExample.sh - An example demonstrating how to call a Command Trigger
# on JumpCloud
#
# If you have any questions or problems with the operation of this script, please
# contact support@jumpcloud.com.
#
# License: This script is made available by JumpCloud under the
# Mozilla Public License v2.0 (https://www.mozilla.org/MPL/2.0/)
#
# Author: James D. Brown (james@jumpcloud.com)
# Created: Mon, Apr 14, 2014
#
# Copyright (c) 2014 JumpCloud, Inc.
#
#########################################################################################
######
# -------------------------- START USER CUSTOMIZATION SECTION --------------------------
######
#
# To obtain your API key, login to the JumpCloud console, and using your user account
# menu in the upper right corner of the screen, select "API Settings".
#
jumpCloudAPIKey="<CHANGE_TO_YOUR_JUMPCLOUD_API_KEY>"
######
# --------------------------- END USER CUSTOMIZATION SECTION ---------------------------
######
triggerNames="${*}"
if [ "$#" -lt 1 ]
then
echo "Usage: $0 <file1> [[<file2>] ... ]"
exit 1
fi
APIKeyIsValid() {
login="${1}"
result=`curl --silent \
-d "{\"filter\": [{\"username\" : \"${login}\"}]}" \
-X 'GET' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: ${jumpCloudAPIKey}" \
"https://console.jumpcloud.com/api/systemusers"`
if [ "${result}" = "Unauthorized" ]
then
return 1
fi
return 0
}
callTriggerByName() {
triggerName="${1}"
curl --silent \
-X 'POST' \
-H "x-api-key: ${jumpCloudAPIKey}" \
"https://console.jumpcloud.com/api/command/trigger/${triggerName}"
}
APIKeyIsValid
if [ ${?} -eq 1 ]
then
echo "ERROR: The API key is unauthorized."
exit 1
fi
for trigger in ${triggerNames}
do
callTriggerByName "${trigger}"
done
exit 0