fix usage of H1 header
change to while loop use global variable for loop fix if statement to be sh compliant shfmtpull/6487/head
parent
5b02e86334
commit
fdb1e8c2e4
|
@ -20,8 +20,8 @@
|
||||||
# The script will automatically generate a new API key if
|
# The script will automatically generate a new API key if
|
||||||
# no key is found, or if a saved key has expired or is invalid.
|
# no key is found, or if a saved key has expired or is invalid.
|
||||||
|
|
||||||
|
_COMMIT_WAIT_INTERVAL=30 # query commit status every 30 seconds
|
||||||
|
_COMMIT_WAIT_ITERATIONS=20 # query commit status 20 times (20*30 = 600 seconds = 10 minutes)
|
||||||
|
|
||||||
# This function is to parse the XML response from the firewall
|
# This function is to parse the XML response from the firewall
|
||||||
parse_response() {
|
parse_response() {
|
||||||
|
@ -59,11 +59,11 @@ deployer() {
|
||||||
content=""
|
content=""
|
||||||
type=$1 # Types are keytest, keygen, cert, key, commit, job_status, push
|
type=$1 # Types are keytest, keygen, cert, key, commit, job_status, push
|
||||||
panos_url="https://$_panos_host/api/"
|
panos_url="https://$_panos_host/api/"
|
||||||
|
export _H1="Content-Type: application/x-www-form-urlencoded"
|
||||||
|
|
||||||
#Test API Key by performing a lookup
|
#Test API Key by performing a lookup
|
||||||
if [ "$type" = 'keytest' ]; then
|
if [ "$type" = 'keytest' ]; then
|
||||||
_debug "**** Testing saved API Key ****"
|
_debug "**** Testing saved API Key ****"
|
||||||
_H1="Content-Type: application/x-www-form-urlencoded"
|
|
||||||
# Get Version Info to test key
|
# Get Version Info to test key
|
||||||
content="type=version&key=$_panos_key"
|
content="type=version&key=$_panos_key"
|
||||||
## Exclude all scopes for the empty commit
|
## Exclude all scopes for the empty commit
|
||||||
|
@ -74,7 +74,6 @@ deployer() {
|
||||||
# Generate API Key
|
# Generate API Key
|
||||||
if [ "$type" = 'keygen' ]; then
|
if [ "$type" = 'keygen' ]; then
|
||||||
_debug "**** Generating new API Key ****"
|
_debug "**** Generating new API Key ****"
|
||||||
_H1="Content-Type: application/x-www-form-urlencoded"
|
|
||||||
content="type=keygen&user=$_panos_user&password=$_panos_pass"
|
content="type=keygen&user=$_panos_user&password=$_panos_pass"
|
||||||
# content="$content${nl}--$delim${nl}Content-Disposition: form-data; type=\"keygen\"; user=\"$_panos_user\"; password=\"$_panos_pass\"${nl}Content-Type: application/octet-stream${nl}${nl}"
|
# content="$content${nl}--$delim${nl}Content-Disposition: form-data; type=\"keygen\"; user=\"$_panos_user\"; password=\"$_panos_pass\"${nl}Content-Type: application/octet-stream${nl}${nl}"
|
||||||
fi
|
fi
|
||||||
|
@ -99,7 +98,7 @@ deployer() {
|
||||||
fi
|
fi
|
||||||
if [ "$_panos_vsys" ]; then
|
if [ "$_panos_vsys" ]; then
|
||||||
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"target-tpl-vsys\"\r\n\r\n$_panos_vsys"
|
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"target-tpl-vsys\"\r\n\r\n$_panos_vsys"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "$type" = 'key' ]; then
|
if [ "$type" = 'key' ]; then
|
||||||
panos_url="${panos_url}?type=import"
|
panos_url="${panos_url}?type=import"
|
||||||
|
@ -114,7 +113,7 @@ deployer() {
|
||||||
fi
|
fi
|
||||||
if [ "$_panos_vsys" ]; then
|
if [ "$_panos_vsys" ]; then
|
||||||
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"target-tpl-vsys\"\r\n\r\n$_panos_vsys"
|
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"target-tpl-vsys\"\r\n\r\n$_panos_vsys"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
#Close multipart
|
#Close multipart
|
||||||
content="$content${nl}--$delim--${nl}${nl}"
|
content="$content${nl}--$delim--${nl}${nl}"
|
||||||
|
@ -125,7 +124,6 @@ deployer() {
|
||||||
# Commit changes
|
# Commit changes
|
||||||
if [ "$type" = 'commit' ]; then
|
if [ "$type" = 'commit' ]; then
|
||||||
_debug "**** Committing changes ****"
|
_debug "**** Committing changes ****"
|
||||||
export _H1="Content-Type: application/x-www-form-urlencoded"
|
|
||||||
#Check for force commit - will commit ALL uncommited changes to the firewall. Use with caution!
|
#Check for force commit - will commit ALL uncommited changes to the firewall. Use with caution!
|
||||||
if [ "$FORCE" ]; then
|
if [ "$FORCE" ]; then
|
||||||
_debug "Force switch detected. Committing ALL changes to the firewall."
|
_debug "Force switch detected. Committing ALL changes to the firewall."
|
||||||
|
@ -140,7 +138,6 @@ deployer() {
|
||||||
# Query job status
|
# Query job status
|
||||||
if [ "$type" = 'job_status' ]; then
|
if [ "$type" = 'job_status' ]; then
|
||||||
echo "**** Querying job $_commit_job_id status ****"
|
echo "**** Querying job $_commit_job_id status ****"
|
||||||
H1="Content-Type: application/x-www-form-urlencoded"
|
|
||||||
cmd=$(printf "%s" "<show><jobs><id>$_commit_job_id</id></jobs></show>" | _url_encode)
|
cmd=$(printf "%s" "<show><jobs><id>$_commit_job_id</id></jobs></show>" | _url_encode)
|
||||||
content="type=op&key=$_panos_key&cmd=$cmd"
|
content="type=op&key=$_panos_key&cmd=$cmd"
|
||||||
fi
|
fi
|
||||||
|
@ -148,7 +145,6 @@ deployer() {
|
||||||
# Push changes
|
# Push changes
|
||||||
if [ "$type" = 'push' ]; then
|
if [ "$type" = 'push' ]; then
|
||||||
echo "**** Pushing changes ****"
|
echo "**** Pushing changes ****"
|
||||||
H1="Content-Type: application/x-www-form-urlencoded"
|
|
||||||
cmd=$(printf "%s" "<commit-all><template-stack><name>$_panos_template_stack</name><admin><member>$_panos_user</member></admin></template-stack></commit-all>" | _url_encode)
|
cmd=$(printf "%s" "<commit-all><template-stack><name>$_panos_template_stack</name><admin><member>$_panos_user</member></admin></template-stack></commit-all>" | _url_encode)
|
||||||
content="type=commit&action=all&key=$_panos_key&cmd=$cmd"
|
content="type=commit&action=all&key=$_panos_key&cmd=$cmd"
|
||||||
fi
|
fi
|
||||||
|
@ -288,13 +284,15 @@ panos_deploy() {
|
||||||
deployer commit
|
deployer commit
|
||||||
if [ "$_panos_template_stack" ]; then
|
if [ "$_panos_template_stack" ]; then
|
||||||
# try to get job status for 20 times in 30 sec interval
|
# try to get job status for 20 times in 30 sec interval
|
||||||
for ((i = 0 ; i < 20 ; i++ )); do
|
i=0
|
||||||
deployer job_status
|
while [ "$i" -lt $_COMMIT_WAIT_ITERATIONS ]; do
|
||||||
if [[ "$_commit_job_status" == "OK" ]]; then
|
deployer job_status
|
||||||
echo "Commit finished!"
|
if [ "$_commit_job_status" = "OK" ]; then
|
||||||
break
|
echo "Commit finished!"
|
||||||
fi
|
break
|
||||||
sleep 30
|
fi
|
||||||
|
sleep $_COMMIT_WAIT_INTERVAL
|
||||||
|
i=$((i + 1))
|
||||||
done
|
done
|
||||||
deployer push
|
deployer push
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue