Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
df753e26
Commit
df753e26
authored
Apr 12, 2023
by
sg1888
Browse files
Added functionality to save and reuse API key
parent
cbb7082a
Changes
1
Hide whitespace changes
Inline
Side-by-side
deploy/panos.sh
View file @
df753e26
...
@@ -25,15 +25,27 @@ parse_response() {
...
@@ -25,15 +25,27 @@ parse_response() {
else
else
status
=
$(
echo
"
$1
"
|
sed
's/^.*"\([a-z]*\)".*/\1/g'
)
status
=
$(
echo
"
$1
"
|
sed
's/^.*"\([a-z]*\)".*/\1/g'
)
message
=
$(
echo
"
$1
"
|
sed
's/^.*<result>\(.*\)<\/result.*/\1/g'
)
message
=
$(
echo
"
$1
"
|
sed
's/^.*<result>\(.*\)<\/result.*/\1/g'
)
if
[
"
$type
"
=
'testkey'
]
&&
[
"
$status
"
!=
"success"
]
;
then
_debug
"**** Saved API key is invalid ****"
unset
_panos_key
fi
fi
fi
return
0
return
0
}
}
deployer
()
{
deployer
()
{
content
=
""
content
=
""
type
=
$1
# Types are keygen, cert, key, commit
type
=
$1
# Types are
testkey,
keygen, cert, key, commit
_debug
"**** Deploying
$type
****
*
"
_debug
"**** Deploying
$type
****"
panos_url
=
"https://
$_panos_host
/api/"
panos_url
=
"https://
$_panos_host
/api/"
#Test API Key by performing an empty commit.
if
[
"
$type
"
=
'testkey'
]
;
then
_H1
=
"Content-Type: application/x-www-form-urlencoded"
content
=
"type=commit&cmd=<commit></commit>&key=
$_panos_key
"
fi
# Generate API Key
if
[
"
$type
"
=
'keygen'
]
;
then
if
[
"
$type
"
=
'keygen'
]
;
then
_H1
=
"Content-Type: application/x-www-form-urlencoded"
_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
"
...
@@ -134,8 +146,22 @@ panos_deploy() {
...
@@ -134,8 +146,22 @@ panos_deploy() {
_err
"Please pass username and password and host as env variables PANOS_USER, PANOS_PASS and PANOS_HOST"
_err
"Please pass username and password and host as env variables PANOS_USER, PANOS_PASS and PANOS_HOST"
return
1
return
1
else
else
_debug
"Getting PANOS KEY"
#Check for saved API Key
deployer keygen
_getdeployconf PANOS_KEY
_panos_key
=
$PANOS_KEY
if
[
"
$_panos_key
"
]
;
then
_debug
"**** Testing Saved API KEY ****"
deployer testkey
fi
# Generate a new API key if needed
if
[
-z
"
$_panos_key
"
]
;
then
_debug
"**** Generating new PANOS API KEY ****"
deployer keygen
_savedeployconf PANOS_KEY
"
$_panos_key
"
1
fi
# Recheck the key
if
[
-z
"
$_panos_key
"
]
;
then
if
[
-z
"
$_panos_key
"
]
;
then
_err
"Missing apikey."
_err
"Missing apikey."
return
1
return
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment