Skip to content

Commit

Permalink
Moving the function code of bindApplication to a bash script file
Browse files Browse the repository at this point in the history
Signed-off-by: Charles Moulliard <cmoulliard@redhat.com>
  • Loading branch information
cmoulliard committed Jul 28, 2023
1 parent 65aa111 commit fa53fb9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/atomic-fruits-vault-crossplane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
PRIMAZA_URL: primaza.127.0.0.1.nip.io
PRIMAZA_NAMESPACE: primaza
run: |
./scripts/primaza.sh bindApplication atomic-fruits fruits-claim
./scripts/data/bind_application.sh application_name=atomic-fruits claim_name=fruits-claim
- id: wait-for-atomic-fruits
name: atomic-fruits should now be up and running
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/atomic-fruits-vault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
PRIMAZA_URL: primaza.127.0.0.1.nip.io
PRIMAZA_NAMESPACE: primaza
run: |
./scripts/primaza.sh bindApplication atomic-fruits fruits-claim
./scripts/data/bind_application.sh application_name=atomic-fruits claim_name=fruits-claim
- id: wait-for-atomic-fruits
name: atomic-fruits should now be up and running
Expand Down
60 changes: 60 additions & 0 deletions scripts/data/bind_application.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash

SCRIPTS_DIR="$(cd $(dirname "${BASH_SOURCE}") && pwd)"
source ${SCRIPTS_DIR}/../common.sh

# Parameters to play the script
export TYPE_SPEED=400
NO_WAIT=true

# Default parameter values
DEFAULT_APPLICATION_NAME=""
DEFAULT_CLAIM_NAME=""

# Function to parse named parameters
parse_parameters() {
for arg in "$@"; do
case $arg in
url=*)
PRIMAZA_URL="${arg#*=}"
;;
claim_name=*)
CLAIM_NAME="${arg#*=}"
;;
application_name=*)
APPLICATION_NAME="${arg#*=}"
;;
*)
# Handle any other unrecognized parameters
echo "Unrecognized parameter: $arg"
exit 1
;;
esac
done
}

# Parse the named parameters with defaults
parse_parameters "$@"

APPLICATION_NAME=${APPLICATION_NAME:-DEFAULT_APPLICATION_NAME}
CLAIM_NAME=${CLAIM_NAME:-DEFAULT_CLAIM_NAME}

note "Searching about the application to be bound ..."
note "curl -H 'Accept: application/json' -s $PRIMAZA_URL/applications/name/$APPLICATION_NAME"
APPLICATION=$(curl -H 'Accept: application/json' -s $PRIMAZA_URL/applications/name/$APPLICATION_NAME)
APPLICATION_ID=$(echo "$APPLICATION" | jq -r '.id')
note "Application ID to be bound: $APPLICATION_ID"

note "Searching about the claim ..."
CLAIM=$(curl -H 'Accept: application/json' -s $PRIMAZA_URL/claims/name/$CLAIM_NAME)
CLAIM_ID=$(echo "$CLAIM" | jq -r '.id')
note "Claim ID to be bound: $CLAIM_ID"

note "curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -d \"claimId=$CLAIM_ID\" -s -i $PRIMAZA_URL/applications/claim/$APPLICATION_ID"
RESULT=$(curl -s -k -o response.txt -w '%{http_code}'\
-X POST \
-H 'Content-Type: application/x-www-form-urlencoded'\
-d "claimId=$CLAIM_ID"\
-s -i $PRIMAZA_URL/applications/claim/$APPLICATION_ID)

log_http_response "Application failed to be bound in Primaza: %s" "Application bound in Primaza: %s" "$RESULT"
22 changes: 2 additions & 20 deletions scripts/primaza.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,6 @@ function localDeploy() {

}

function bindApplication() {
APPLICATION_NAME=$1
CLAIM_NAME=$2

APPLICATION=$(curl -H 'Accept: application/json' -s $PRIMAZA_URL/applications/name/$APPLICATION_NAME)
APPLICATION_ID=$(echo "$APPLICATION" | jq -r '.id')
note "Application ID to be bound: $APPLICATION_ID"

CLAIM=$(curl -H 'Accept: application/json' -s $PRIMAZA_URL/claims/name/$CLAIM_NAME)
CLAIM_ID=$(echo "$CLAIM" | jq -r '.id')
note "Claim ID to be bound: $CLAIM_ID"

note "curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -d \"claimId=$CLAIM_ID\" -s -i $PRIMAZA_URL/applications/claim/$APPLICATION_ID"
RESULT=$(curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -d "claimId=$CLAIM_ID" -s -i $PRIMAZA_URL/applications/claim/$APPLICATION_ID)

log_http_response "Application failed to be bound in Primaza: %s" "Application bound in Primaza: %s" "$RESULT"
}

function loadData() {
note "Creating the cluster's record"
${SCRIPTS_DIR}/data/cluster.sh
Expand Down Expand Up @@ -209,6 +191,7 @@ function isAlive() {
warn "Primaza is not yet alive."
sleep $retry_delay
fi
((retry_attempt++))
done
}

Expand All @@ -218,13 +201,12 @@ case $1 in
deploy) "$@"; exit;;
localdeploy) localDeploy; exit;;
loaddata) loadData; exit;;
bindApplication) "$@"; exit;;
isAlive) isAlive; exit;;
remove) "$@"; exit;;
log) log; exit;;
*)
build
localDeploy
loadData
#loadData
exit;;
esac

0 comments on commit fa53fb9

Please sign in to comment.