Skip to content

Commit 46a2608

Browse files
committed
fix: Renamed filaname to certname
- Changed filename to certname to better reflect the actual issue at hand. - Restored _cdomain variable to its original place for clarity.
1 parent 3d3053f commit 46a2608

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

deploy/panos.sh

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# export PANOS_TEMPLATE="" # Template Name of panorama managed devices
1717
# export PANOS_TEMPLATE_STACK="" # set a Template Stack if certificate should also be pushed automatically
1818
# export PANOS_VSYS="Shared" # name of the vsys to import the certificate
19-
# export PANOS_FILENAME="" # use a custom filename to work around Panorama's 31-character limit
19+
# export PANOS_CERTNAME="" # use a custom certificate name to work around Panorama's 31-character limit
2020
#
2121
# The script will automatically generate a new API key if
2222
# no key is found, or if a saved key has expired or is invalid.
@@ -90,7 +90,7 @@ deployer() {
9090
if [ "$type" = 'cert' ]; then
9191
panos_url="${panos_url}?type=import"
9292
content="--$delim${nl}Content-Disposition: form-data; name=\"category\"\r\n\r\ncertificate"
93-
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"certificate-name\"\r\n\r\n$_panos_filename"
93+
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"certificate-name\"\r\n\r\n$_panos_certname"
9494
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"key\"\r\n\r\n$_panos_key"
9595
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"format\"\r\n\r\npem"
9696
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"file\"; filename=\"$(basename "$_cfullchain")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_cfullchain")"
@@ -104,11 +104,11 @@ deployer() {
104104
if [ "$type" = 'key' ]; then
105105
panos_url="${panos_url}?type=import"
106106
content="--$delim${nl}Content-Disposition: form-data; name=\"category\"\r\n\r\nprivate-key"
107-
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"certificate-name\"\r\n\r\n$_panos_filename"
107+
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"certificate-name\"\r\n\r\n$_panos_certname"
108108
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"key\"\r\n\r\n$_panos_key"
109109
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"format\"\r\n\r\npem"
110110
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"passphrase\"\r\n\r\n123456"
111-
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"file\"; filename=\"$(basename "$_panos_filename.key")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_ckey")"
111+
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"file\"; filename=\"$(basename "$_panos_certname.key")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_ckey")"
112112
if [ "$_panos_template" ]; then
113113
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"target-tpl\"\r\n\r\n$_panos_template"
114114
fi
@@ -169,6 +169,7 @@ deployer() {
169169

170170
# This is the main function that will call the other functions to deploy everything.
171171
panos_deploy() {
172+
_cdomain=$(echo "$1" | sed 's/*/WILDCARD_/g') #Wildcard Safe Filename
172173
_ckey="$2"
173174
_cfullchain="$5"
174175

@@ -242,13 +243,13 @@ panos_deploy() {
242243
_getdeployconf PANOS_VSYS
243244
fi
244245

245-
# PANOS_FILENAME
246-
if [ "$PANOS_FILENAME" ]; then
247-
_debug "Detected ENV variable PANOS_FILENAME. Saving to file."
248-
_savedeployconf PANOS_FILENAME "$PANOS_FILENAME" 1
246+
# PANOS_CERTNAME
247+
if [ "$PANOS_CERTNAME" ]; then
248+
_debug "Detected ENV variable PANOS_CERTNAME. Saving to file."
249+
_savedeployconf PANOS_CERTNAME "$PANOS_CERTNAME" 1
249250
else
250-
_debug "Attempting to load variable PANOS_FILENAME from file."
251-
_getdeployconf PANOS_FILENAME
251+
_debug "Attempting to load variable PANOS_CERTNAME from file."
252+
_getdeployconf PANOS_CERTNAME
252253
fi
253254

254255
#Store variables
@@ -258,7 +259,7 @@ panos_deploy() {
258259
_panos_template=$PANOS_TEMPLATE
259260
_panos_template_stack=$PANOS_TEMPLATE_STACK
260261
_panos_vsys=$PANOS_VSYS
261-
_panos_filename=$PANOS_FILENAME
262+
_panos_certname=$PANOS_CERTNAME
262263

263264
#Test API Key if found. If the key is invalid, the variable _panos_key will be unset.
264265
if [ "$_panos_host" ] && [ "$_panos_key" ]; then
@@ -277,10 +278,10 @@ panos_deploy() {
277278
_err "No password found. If this is your first time deploying, please set PANOS_PASS in ENV variables. You can delete it after you have successfully deployed the certs."
278279
return 1
279280
else
280-
# Use filename based on the first domain on the certificate if no custom filename is set
281-
if [ -z "$_panos_filename" ]; then
282-
_panos_filename=$(echo "$1" | sed 's/*/WILDCARD_/g') #Wildcard Safe Filename
283-
_savedeployconf PANOS_FILENAME "$_panos_filename" 1
281+
# Use certificate name based on the first domain on the certificate if no custom certificate name is set
282+
if [ -z "$_panos_certname" ]; then
283+
_panos_certname="$_cdomain"
284+
_savedeployconf PANOS_CERTNAME "$_panos_certname" 1
284285
fi
285286

286287
# Generate a new API key if no valid API key is found

0 commit comments

Comments
 (0)