-
Notifications
You must be signed in to change notification settings - Fork 53
Adding sample perl and shell script for CA migration api's #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,123 @@ | ||||||||||||||||||||||||||||||||||
#!/bin/sh | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
#####################n##################################################### | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# This script demonstrates how to activate the new CA. | ||||||||||||||||||||||||||||||||||
# To activate the CA migration, a user needs to have proper permissions. | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# This script requires jq command-line JSON parser | ||||||||||||||||||||||||||||||||||
# if your system does not have jq installed, this will not work. | ||||||||||||||||||||||||||||||||||
# jq can be downloaded from here: https://github.com/stedolan/jq/releases | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
########################################################################### | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
port=1556 | ||||||||||||||||||||||||||||||||||
master_server="" | ||||||||||||||||||||||||||||||||||
login_username="" | ||||||||||||||||||||||||||||||||||
login_password="" | ||||||||||||||||||||||||||||||||||
login_domainname="" | ||||||||||||||||||||||||||||||||||
login_domaintype="" | ||||||||||||||||||||||||||||||||||
force=0 | ||||||||||||||||||||||||||||||||||
reason="" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
showHelp() | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
echo "" | ||||||||||||||||||||||||||||||||||
echo "Invalid command parameters" | ||||||||||||||||||||||||||||||||||
echo "Usage:" | ||||||||||||||||||||||||||||||||||
echo "./activate_migration.sh -nbmaster <master_server> -login_username <login_username> -login_password <login_password> -login_domainname <login_domain_name> -login_domaintype <login_domaintype> [-reason | -r <reason_for_migration>] [-force | -f]" | ||||||||||||||||||||||||||||||||||
echo "-nbmaster : Name of the NetBackup master server" | ||||||||||||||||||||||||||||||||||
echo "-login_username : User name of the user performing action" | ||||||||||||||||||||||||||||||||||
echo "-login_password : Password of the user performing action" | ||||||||||||||||||||||||||||||||||
echo "-login_domainname : Domain name of the user performing action" | ||||||||||||||||||||||||||||||||||
echo "-login_domaintype : Domain type of the user performing action" | ||||||||||||||||||||||||||||||||||
echo "-reason | -r : Reason for activation of the new CA" | ||||||||||||||||||||||||||||||||||
echo "-force | -f : Forcefully activate the new CA" | ||||||||||||||||||||||||||||||||||
echo "" | ||||||||||||||||||||||||||||||||||
exit 1 | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
parseArguments() | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
if [ $# -lt 10 ] && [ $# -gt 14 ]; then | ||||||||||||||||||||||||||||||||||
showHelp | ||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
while [ "$1" != "" ]; do | ||||||||||||||||||||||||||||||||||
case $1 in | ||||||||||||||||||||||||||||||||||
-nbmaster) | ||||||||||||||||||||||||||||||||||
master_server=$2 | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
-login_username) | ||||||||||||||||||||||||||||||||||
login_username=$2 | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
-login_password) | ||||||||||||||||||||||||||||||||||
login_password=$2 | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
-login_domainname) | ||||||||||||||||||||||||||||||||||
login_domainname=$2 | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
-login_domaintype) | ||||||||||||||||||||||||||||||||||
login_domaintype=$2 | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
-force|-f) | ||||||||||||||||||||||||||||||||||
force=1 | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
-reason|-r) | ||||||||||||||||||||||||||||||||||
reason=$2 | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
*) | ||||||||||||||||||||||||||||||||||
showHelp | ||||||||||||||||||||||||||||||||||
;; | ||||||||||||||||||||||||||||||||||
esac | ||||||||||||||||||||||||||||||||||
shift 2 | ||||||||||||||||||||||||||||||||||
done | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if [ -z "$master_server" ] || [ -z "$login_username" ] || [ -z "$login_password" ] || [ -z "$login_domainname" ] || [ -z "$login_domaintype" ]; then | ||||||||||||||||||||||||||||||||||
showHelp | ||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if [ "${login_domaintype^^}" = "WINDOWS" ] || [ "${login_domaintype^^}" = "NT" ]; then | ||||||||||||||||||||||||||||||||||
login_domaintype="nt" | ||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
###############main############ | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
parseArguments "$@" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
basepath="https://$master_server:$port/netbackup" | ||||||||||||||||||||||||||||||||||
content_header='content-type:application/json' | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
##############login############# | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
uri="$basepath/login" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
data=$(jq --arg name $login_username --arg pass $login_password --arg dname $login_domainname --arg dtype $login_domaintype \ | ||||||||||||||||||||||||||||||||||
--null-input '{userName: $name, password: $pass, domainName: $dname, domainType: $dtype}') | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
jwt=$(curl --silent -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token') | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
##############jobs############## | ||||||||||||||||||||||||||||||||||
auth_header="authorization:$jwt" | ||||||||||||||||||||||||||||||||||
content_header='content-type:application/vnd.netbackup+json;version=4.0' | ||||||||||||||||||||||||||||||||||
uri="$basepath/security/certificate-authorities/activate" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# Construct request body | ||||||||||||||||||||||||||||||||||
request_body="{" | ||||||||||||||||||||||||||||||||||
request_body="${request_body}\"data\": {" | ||||||||||||||||||||||||||||||||||
request_body="${request_body}\"type\": \"nbcaMigrationActivateRequest\"," | ||||||||||||||||||||||||||||||||||
request_body="${request_body}\"attributes\": {" | ||||||||||||||||||||||||||||||||||
if [ $force == 1 ]; then | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||||||||||||||||||||||||||||||
request_body="${request_body}\"force\" : \"true\"" | ||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||
request_body="${request_body}}}}" | ||||||||||||||||||||||||||||||||||
Comment on lines
+107
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you already know you have jq, you may as well use it to generate syntactically valid JSON without a bunch of string concatenations.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if [ -z $reason ]; then | ||||||||||||||||||||||||||||||||||
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -d "$request_body" | jq | ||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||
audit_reason="X-NetBackup-Audit-Reason:$reason"; | ||||||||||||||||||||||||||||||||||
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -H "$audit_reason" -d "$request_body" | jq | ||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
exit 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#!/bin/sh | ||
|
||
#####################n##################################################### | ||
|
||
# This script demonstrates how to complete the CA migration. | ||
|
||
# This script requires jq command-line JSON parser | ||
# if your system does not have jq installed, this will not work. | ||
# jq can be downloaded from here: https://github.com/stedolan/jq/releases | ||
|
||
########################################################################### | ||
|
||
port=1556 | ||
master_server="" | ||
login_username="" | ||
login_password="" | ||
login_domainname="" | ||
login_domaintype="" | ||
reason="" | ||
force=0 | ||
|
||
showHelp() | ||
{ | ||
echo "" | ||
echo "Invalid command parameters" | ||
echo "Usage:" | ||
echo "./complete_migration.sh -nbmaster <master_server> -login_username <login_username> -login_password <login_password> -login_domainname <login_domain_name> -login_domaintype <login_domaintype> [-reason | -r <reason_for_migration>] [-force | -f]" | ||
echo "-nbmaster : Name of the NetBackup master server" | ||
echo "-login_username : User name of the user performing action" | ||
echo "-login_password : Password of the user performing action" | ||
echo "-login_domainname : Domain name of the user performing action" | ||
echo "-login_domaintype : Domain type of the user performing action" | ||
echo "-reason | -r : Reason for completing the CA migration" | ||
echo "-force | -f : Forcefully complete the CA migration" | ||
echo "" | ||
exit 1 | ||
} | ||
|
||
parseArguments() | ||
{ | ||
if [ $# -ne 10 ] && [ $# -ne 11 ] && [ $# -ne 12 ] && [ $# -ne 13 ]; then | ||
showHelp | ||
fi | ||
|
||
while [ "$1" != "" ]; do | ||
case $1 in | ||
-nbmaster) | ||
master_server=$2 | ||
;; | ||
-login_username) | ||
login_username=$2 | ||
;; | ||
-login_password) | ||
login_password=$2 | ||
;; | ||
-login_domainname) | ||
login_domainname=$2 | ||
;; | ||
-login_domaintype) | ||
login_domaintype=$2 | ||
;; | ||
-force|-f) | ||
force=1 | ||
Comment on lines
+62
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since You can fix this by using |
||
;; | ||
-reason|-r) | ||
reason=$2 | ||
;; | ||
*) | ||
showHelp | ||
;; | ||
esac | ||
shift 2 | ||
done | ||
|
||
if [ -z "$master_server" ] || [ -z "$login_username" ] || [ -z "$login_password" ] || [ -z "$login_domainname" ] || [ -z "$login_domaintype" ]; then | ||
showHelp | ||
fi | ||
|
||
if [ "${login_domaintype^^}" = "WINDOWS" ] || [ "${login_domaintype^^}" = "NT" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The shebang line says this runs as /bin/sh, but the |
||
login_domaintype="nt" | ||
fi | ||
} | ||
|
||
###############main############ | ||
|
||
parseArguments "$@" | ||
|
||
basepath="https://$master_server:$port/netbackup" | ||
content_header='content-type:application/json' | ||
|
||
##############login############# | ||
|
||
uri="$basepath/login" | ||
|
||
data=$(jq --arg name $login_username --arg pass $login_password --arg dname $login_domainname --arg dtype $login_domaintype \ | ||
--null-input '{userName: $name, password: $pass, domainName: $dname, domainType: $dtype}') | ||
|
||
jwt=$(curl --silent -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token') | ||
|
||
##############jobs############## | ||
auth_header="authorization:$jwt" | ||
content_header='content-type:application/vnd.netbackup+json;version=4.0' | ||
uri="$basepath/security/certificate-authorities/migration-complete" | ||
|
||
# Construct request body | ||
request_body="{" | ||
request_body="${request_body}\"data\": {" | ||
request_body="${request_body}\"type\": \"nbcaMigrationCompleteRequest\"," | ||
request_body="${request_body}\"attributes\": {" | ||
if [ $force == 1 ]; then | ||
request_body="${request_body}\"force\" : \"true\"" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
fi | ||
request_body="${request_body}}}}" | ||
|
||
if [ -z $reason ]; then | ||
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -d "$request_body" | jq | ||
else | ||
audit_reason="X-NetBackup-Audit-Reason:$reason"; | ||
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -H "$audit_reason" -d "$request_body" | jq | ||
fi | ||
|
||
exit 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#!/bin/sh | ||
|
||
#####################n##################################################### | ||
|
||
# This script demonstrates how to initiate CA migration. | ||
# To initiate the CA migration, a user needs to have proper permissions. | ||
|
||
# This script requires jq command-line JSON parser | ||
# if your system does not have jq installed, this will not work. | ||
# jq can be downloaded from here: https://github.com/stedolan/jq/releases | ||
|
||
########################################################################### | ||
|
||
port=1556 | ||
master_server="" | ||
login_username="" | ||
login_password="" | ||
login_domainname="" | ||
login_domaintype="" | ||
keysize="" | ||
reason="" | ||
|
||
showHelp() | ||
{ | ||
echo "" | ||
echo "Invalid command parameters" | ||
echo "Usage:" | ||
echo "./initiate_migration.sh -nbmaster <master_server> -login_username <login_username> -login_password <login_password> -login_domainname <login_domain_name> -login_domaintype <login_domaintype> -keysize | -k <key_size> [-reason | -r <reason_for_migration>]" | ||
echo "-nbmaster : Name of the NetBackup master server" | ||
echo "-login_username : User name of the user performing action" | ||
echo "-login_password : Password of the user performing action" | ||
echo "-login_domainname : Domain name of the user performing action" | ||
echo "-login_domaintype : Domain type of the user performing action" | ||
echo "-keysize | -k : NetBackup CA key strength" | ||
echo "-reason | -r : Reason for initiating CA migration" | ||
echo "" | ||
exit 1 | ||
} | ||
|
||
parseArguments() | ||
{ | ||
if [ $# -ne 12 ] && [ $# -ne 14 ]; then | ||
showHelp | ||
fi | ||
|
||
while [ "$1" != "" ]; do | ||
case $1 in | ||
-nbmaster) | ||
master_server=$2 | ||
;; | ||
-login_username) | ||
login_username=$2 | ||
;; | ||
-login_password) | ||
login_password=$2 | ||
;; | ||
-login_domainname) | ||
login_domainname=$2 | ||
;; | ||
-login_domaintype) | ||
login_domaintype=$2 | ||
;; | ||
-keysize | -k) | ||
keysize=$2 | ||
;; | ||
-reason | -r) | ||
reason=$2 | ||
;; | ||
*) | ||
showHelp | ||
;; | ||
esac | ||
shift 2 | ||
done | ||
|
||
if [ -z "$master_server" ] || [ -z "$login_username" ] || [ -z "$login_password" ] || [ -z "$login_domainname" ] || [ -z "$login_domaintype" ] || [ -z "$keysize" ]; then | ||
showHelp | ||
fi | ||
|
||
if [ "${login_domaintype^^}" = "WINDOWS" ] || [ "${login_domaintype^^}" = "NT" ]; then | ||
login_domaintype="nt" | ||
fi | ||
} | ||
|
||
###############main############ | ||
|
||
parseArguments "$@" | ||
|
||
basepath="https://$master_server:$port/netbackup" | ||
content_header='content-type:application/json' | ||
|
||
##############login############# | ||
|
||
uri="$basepath/login" | ||
|
||
data=$(jq --arg name $login_username --arg pass $login_password --arg dname $login_domainname --arg dtype $login_domaintype \ | ||
--null-input '{userName: $name, password: $pass, domainName: $dname, domainType: $dtype}') | ||
|
||
jwt=$(curl --silent -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token') | ||
|
||
##############jobs############## | ||
auth_header="authorization:$jwt" | ||
content_header='content-type:application/vnd.netbackup+json;version=4.0' | ||
uri="$basepath/security/certificate-authorities/initiate-migration" | ||
|
||
# Construct request body | ||
request_body="{" | ||
request_body="${request_body}\"data\": {" | ||
request_body="${request_body}\"type\": \"initiateCAMigrationRequest\"," | ||
request_body="${request_body}\"attributes\": {" | ||
request_body="${request_body}\"keySize\" : \"${keysize}\"" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
request_body="${request_body}}}}" | ||
|
||
if [ -z $reason ]; then | ||
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -d "$request_body" | jq | ||
else | ||
audit_reason="X-NetBackup-Audit-Reason:$reason"; | ||
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -H "$audit_reason" -d "$request_body" | jq | ||
fi | ||
|
||
exit 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,3 +126,15 @@ API key Details: | |
|
||
- Use the following command to use API key instead of JWT to trigger a NetBackup REST API on your NetBackup Master server: | ||
- `perl apikey_usage.pl -nbmaster <master_server> -apikey <apikey> [--verbose]` | ||
|
||
CA Migration Details: | ||
|
||
- Use the following command to initiate the NetBackup CA migration on your NetBackup Master server: | ||
- `perl initiate-migration.pl -nbmaster <master_server> -login_username <login_username> -login_password <login_password> [-login_domainname <login_domain_name> -login_domaintype <domain_type>] -keysize <keysize> [-reason <reason>] [--verbose]` | ||
|
||
- Use the following command to activate the new NetBackup CA on your NetBackup Master server: | ||
- `perl activate_migration.pl -nbmaster <master_server> -login_username <login_username> -login_password <login_password> [-login_domainname <login_domain_name> -login_domaintype <domain_type>] [-reason <reason>] [--force] [--verbose]` | ||
|
||
- Use the following command to complete the NetBackup CA migration on your NetBackup Master server: | ||
- `perl complete_migration.pl -nbmaster <master_server> -login_username <login_username> -login_password <login_password> [-login_domainname <login_domain_name> -login_domaintype <domain_type>] [-reason <reason>] [--force] [--verbose]` | ||
Comment on lines
+133
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why using single dash for some options and double dash for others? |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote the shell parameters. No idea what crazy characters might be in any of those.