Skip to content

Commit

Permalink
Enhance project prerequisites
Browse files Browse the repository at this point in the history
  • Loading branch information
bbertolani committed Feb 17, 2024
1 parent 0c0c4ea commit 3acc9af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sudo cp swo.sh /usr/local/bin/swo
```

Create a file `swo_config` on `$HOME/.config/switchOrchestrator`

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

```bash
Expand All @@ -40,6 +41,13 @@ HASH_PASS="XXXXXXXXXXXXXXXX"
SWITCH_IP="0.0.0.0"
```

#### Password Hash

In terminal go to a new folder.
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)

``` ➜ echo -n "REPLACEYOURPASSEHRE" | openssl rsautl -encrypt -pubin -inkey ./public_key.pem | base64```

#### Auth

This command will save a token used to make the API calls
Expand Down
21 changes: 15 additions & 6 deletions swo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ switchOrchestrator loads configuration variables from:
}

createConf() {
if [ ! -d "$SWITCH_CF_FOLDER" ]; then
echo "Creating config folder in ${SWITCH_CF_FOLDER}..."
exec mkdir $SWITCH_CF_FOLDER
fi
# if [ ! -d "$SWITCH_CF_FOLDER" ]; then
# echo "Creating config folder in ${SWITCH_CF_FOLDER}..."
# exec mkdir $SWITCH_CF_FOLDER
# fi
mkdir -p "$SWITCH_CF_FOLDER"

cd $SWITCH_CF_FOLDER

if [ -f "$SWITCH_CF_FILE" ]; then
echo "$SWITCH_CF_FILE exists."
read -p "Are you sure that wanna replace your config? [Yy][Nn]" -n 1 -r
read -p "Are you sure you want to replace your config? [Yy][Nn]" -n 1 -r
if [[ $REPLY =~ [^Yy]$ ]]; then
echo "Install failed"
break
Expand Down Expand Up @@ -72,14 +73,15 @@ auth() {
truncate -s 0 $SAVED_TOKEN
echo "$TOKEN" >> $SAVED_TOKEN
echo "Login Sucessful | SWITCH: $SWITCH_IP"
checkRequirements
exit 0
}

searchJob() {
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)
status=$(jq '.status' <<< $JSON)
if [ "$status" == "success" ]; then
echo "Search failed"
echo "Search failed OR you're not logged, try to auth again"
exit 1
fi
messages=$(jq '.messages' <<< $JSON)
Expand All @@ -101,6 +103,13 @@ validateSearchJob() {
searchJob $JOB_NUMBER
}

checkRequirements() {
if ! command -v jq &> /dev/null; then
echo "jq is not installed. Please install it before running this script."
exit 1
fi
}

############################################################
# Main program #
############################################################
Expand Down

0 comments on commit 3acc9af

Please sign in to comment.