Skip to content

Commit 3acc9af

Browse files
committed
Enhance project prerequisites
1 parent 0c0c4ea commit 3acc9af

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ sudo cp swo.sh /usr/local/bin/swo
3232
```
3333

3434
Create a file `swo_config` on `$HOME/.config/switchOrchestrator`
35+
3536
Please read the oficial manual of [Enfocus Switch API](https://www.enfocus.com/manuals/DeveloperGuide/WebServices/17/index.html#api-Authentication-LoginQuery) to learn how create a password hash
3637

3738
```bash
@@ -40,6 +41,13 @@ HASH_PASS="XXXXXXXXXXXXXXXX"
4041
SWITCH_IP="0.0.0.0"
4142
```
4243

44+
#### Password Hash
45+
46+
In terminal go to a new folder.
47+
Create a public_key.pem file and copy the PUBLIC KEY offered by Enfocus Switch [Click Here](https://www.enfocus.com/manuals/DeveloperGuide/WebServices/17/index.html#api-Authentication-LoginQuery)
48+
49+
``` ➜ echo -n "REPLACEYOURPASSEHRE" | openssl rsautl -encrypt -pubin -inkey ./public_key.pem | base64```
50+
4351
#### Auth
4452

4553
This command will save a token used to make the API calls

swo.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ switchOrchestrator loads configuration variables from:
3333
}
3434

3535
createConf() {
36-
if [ ! -d "$SWITCH_CF_FOLDER" ]; then
37-
echo "Creating config folder in ${SWITCH_CF_FOLDER}..."
38-
exec mkdir $SWITCH_CF_FOLDER
39-
fi
36+
# if [ ! -d "$SWITCH_CF_FOLDER" ]; then
37+
# echo "Creating config folder in ${SWITCH_CF_FOLDER}..."
38+
# exec mkdir $SWITCH_CF_FOLDER
39+
# fi
40+
mkdir -p "$SWITCH_CF_FOLDER"
4041

4142
cd $SWITCH_CF_FOLDER
4243

4344
if [ -f "$SWITCH_CF_FILE" ]; then
4445
echo "$SWITCH_CF_FILE exists."
45-
read -p "Are you sure that wanna replace your config? [Yy][Nn]" -n 1 -r
46+
read -p "Are you sure you want to replace your config? [Yy][Nn]" -n 1 -r
4647
if [[ $REPLY =~ [^Yy]$ ]]; then
4748
echo "Install failed"
4849
break
@@ -72,14 +73,15 @@ auth() {
7273
truncate -s 0 $SAVED_TOKEN
7374
echo "$TOKEN" >> $SAVED_TOKEN
7475
echo "Login Sucessful | SWITCH: $SWITCH_IP"
76+
checkRequirements
7577
exit 0
7678
}
7779

7880
searchJob() {
7981
JSON=$(curl -s --location --request GET "$SWITCH_ADR/api/v1/messages?type=info&type=error&type=warning&type=debug&message=$JOB_NUMBER&limit=100" -H 'Authorization: Bearer '$TOKEN)
8082
status=$(jq '.status' <<< $JSON)
8183
if [ "$status" == "success" ]; then
82-
echo "Search failed"
84+
echo "Search failed OR you're not logged, try to auth again"
8385
exit 1
8486
fi
8587
messages=$(jq '.messages' <<< $JSON)
@@ -101,6 +103,13 @@ validateSearchJob() {
101103
searchJob $JOB_NUMBER
102104
}
103105

106+
checkRequirements() {
107+
if ! command -v jq &> /dev/null; then
108+
echo "jq is not installed. Please install it before running this script."
109+
exit 1
110+
fi
111+
}
112+
104113
############################################################
105114
# Main program #
106115
############################################################

0 commit comments

Comments
 (0)