-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_faker_asset.sh
executable file
·77 lines (58 loc) · 1.98 KB
/
create_faker_asset.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
73
#!/bin/bash
#
#
# 2016 (c) IxorTalk CVBA
# All Rights Reserved.
#
# NOTICE: All information contained herein is, and remains
# the property of IxorTalk CVBA
#
# The intellectual and technical concepts contained
# herein are proprietary to IxorTalk CVBA
# and may be covered by U.S. and Foreign Patents,
# patents in process, and are protected by trade secret or copyright law.
#
# Dissemination of this information or reproduction of this material
# is strictly forbidden unless prior written permission is obtained
# from IxorTalk CVBA.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.
#
serverUrl=http://ixortalk-gateway:8888
ASSET_HOSTNAME=${1}
ASSET_PORT=${2}
echo "Retrieving creds from $IXORTALK_CONFIG_SERVER_PATH/oauth2.txt"
CREDS=`curl ${IXORTALK_CONFIG_SERVER_PATH}/oauth2.txt`
echo "Retrieving token using ${CREDS} from ${serverUrl}/uaa/oauth/token"
RESP=`curl -X POST -u ${CREDS} -H "Content-Type: application/x-www-form-urlencoded" -d 'grant_type=client_credentials' "${serverUrl}/uaa/oauth/token"`
echo "Found RESP = $RESP"
BEARER_TOKEN=`echo ${RESP:17:36}`
ASSETS_LENGTH=`curl -H "Authorization: Bearer $BEARER_TOKEN" ${serverUrl}/assetmgmt/assets/search/property/assetId/$ASSET_HOSTNAME | jqn --color false 'size'`
echo "Found ASSETS_LENGTH [$ASSETS_LENGTH]"
if [ $ASSETS_LENGTH -eq 0 ]; then
echo "Creating asset "
BODY=`cat << EOF
{
"assetProperties": {
"properties": {
"assetId": "$ASSET_HOSTNAME",
"hostname": "$ASSET_HOSTNAME",
"port": $ASSET_PORT
}
}
}
EOF`
echo $BODY
echo "Launching request...."
curl -X POST \
${serverUrl}/assetmgmt/assets \
-H "Authorization: Bearer $BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d "$BODY"
exit;
else
echo "Not creating asset - already exists"
fi