Skip to content

Commit

Permalink
Adding sample script for CA migration api's
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jun 1, 2020
1 parent bf694a4 commit 487184c
Show file tree
Hide file tree
Showing 8 changed files with 876 additions and 0 deletions.
123 changes: 123 additions & 0 deletions snippets/curl/activate_migration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/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=""
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
request_body="${request_body}\"force\" : \"TRUE\""
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
122 changes: 122 additions & 0 deletions snippets/curl/complete_migration.sh
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
;;
-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/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\""
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
121 changes: 121 additions & 0 deletions snippets/curl/initiate_migration.sh
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}\""
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
12 changes: 12 additions & 0 deletions snippets/perl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]`

Loading

0 comments on commit 487184c

Please sign in to comment.