Skip to content

Commit 487184c

Browse files
author
root
committed
Adding sample script for CA migration api's
1 parent bf694a4 commit 487184c

File tree

8 files changed

+876
-0
lines changed

8 files changed

+876
-0
lines changed

snippets/curl/activate_migration.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/sh
2+
3+
#####################n#####################################################
4+
5+
# This script demonstrates how to initiate CA migration.
6+
# To initiate the CA migration, a user needs to have proper permissions.
7+
8+
# This script requires jq command-line JSON parser
9+
# if your system does not have jq installed, this will not work.
10+
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
11+
12+
###########################################################################
13+
14+
port=1556
15+
master_server=""
16+
login_username=""
17+
login_password=""
18+
login_domainname=""
19+
login_domaintype=""
20+
force=0
21+
reason=""
22+
23+
showHelp()
24+
{
25+
echo ""
26+
echo "Invalid command parameters"
27+
echo "Usage:"
28+
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]"
29+
echo "-nbmaster : Name of the NetBackup master server"
30+
echo "-login_username : User name of the user performing action"
31+
echo "-login_password : Password of the user performing action"
32+
echo "-login_domainname : Domain name of the user performing action"
33+
echo "-login_domaintype : Domain type of the user performing action"
34+
echo "-reason | -r : Reason for activation of the new CA"
35+
echo "-force | -f : Forcefully activate the new CA"
36+
echo ""
37+
exit 1
38+
}
39+
40+
parseArguments()
41+
{
42+
if [ $# -lt 10 ] && [ $# -gt 14 ]; then
43+
showHelp
44+
fi
45+
46+
while [ "$1" != "" ]; do
47+
case $1 in
48+
-nbmaster)
49+
master_server=$2
50+
;;
51+
-login_username)
52+
login_username=$2
53+
;;
54+
-login_password)
55+
login_password=$2
56+
;;
57+
-login_domainname)
58+
login_domainname=$2
59+
;;
60+
-login_domaintype)
61+
login_domaintype=$2
62+
;;
63+
-force|-f)
64+
force=1
65+
;;
66+
-reason|-r)
67+
reason=$2
68+
;;
69+
*)
70+
showHelp
71+
;;
72+
esac
73+
shift 2
74+
done
75+
76+
if [ -z "$master_server" ] || [ -z "$login_username" ] || [ -z "$login_password" ] || [ -z "$login_domainname" ] || [ -z "$login_domaintype" ]; then
77+
showHelp
78+
fi
79+
80+
if [ "${login_domaintype^^}" = "WINDOWS" ] || [ "${login_domaintype^^}" = "NT" ]; then
81+
login_domaintype="nt"
82+
fi
83+
}
84+
85+
###############main############
86+
87+
parseArguments "$@"
88+
89+
basepath="https://$master_server:$port/netbackup"
90+
content_header='content-type:application/json'
91+
92+
##############login#############
93+
94+
uri="$basepath/login"
95+
96+
data=$(jq --arg name $login_username --arg pass $login_password --arg dname $login_domainname --arg dtype $login_domaintype \
97+
--null-input '{userName: $name, password: $pass, domainName: $dname, domainType: $dtype}')
98+
99+
jwt=$(curl --silent -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token')
100+
101+
##############jobs##############
102+
auth_header="authorization:$jwt"
103+
content_header='content-type:application/vnd.netbackup+json;version=4.0'
104+
uri="$basepath/security/certificate-authorities/activate"
105+
106+
# Construct request body
107+
request_body="{"
108+
request_body="${request_body}\"data\": {"
109+
request_body="${request_body}\"type\": \"nbcaMigrationActivateRequest\","
110+
request_body="${request_body}\"attributes\": {"
111+
if [ $force == 1 ]; then
112+
request_body="${request_body}\"force\" : \"TRUE\""
113+
fi
114+
request_body="${request_body}}}}"
115+
116+
if [ -z $reason ]; then
117+
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -d "$request_body" | jq
118+
else
119+
audit_reason="X-NetBackup-Audit-Reason:$reason";
120+
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -H "$audit_reason" -d "$request_body" | jq
121+
fi
122+
123+
exit 0

snippets/curl/complete_migration.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/sh
2+
3+
#####################n#####################################################
4+
5+
# This script demonstrates how to complete the CA migration.
6+
7+
# This script requires jq command-line JSON parser
8+
# if your system does not have jq installed, this will not work.
9+
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
10+
11+
###########################################################################
12+
13+
port=1556
14+
master_server=""
15+
login_username=""
16+
login_password=""
17+
login_domainname=""
18+
login_domaintype=""
19+
reason=""
20+
force=0
21+
22+
showHelp()
23+
{
24+
echo ""
25+
echo "Invalid command parameters"
26+
echo "Usage:"
27+
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]"
28+
echo "-nbmaster : Name of the NetBackup master server"
29+
echo "-login_username : User name of the user performing action"
30+
echo "-login_password : Password of the user performing action"
31+
echo "-login_domainname : Domain name of the user performing action"
32+
echo "-login_domaintype : Domain type of the user performing action"
33+
echo "-reason | -r : Reason for completing the CA migration"
34+
echo "-force | -f : Forcefully complete the CA migration"
35+
echo ""
36+
exit 1
37+
}
38+
39+
parseArguments()
40+
{
41+
if [ $# -ne 10 ] && [ $# -ne 11 ] && [ $# -ne 12 ] && [ $# -ne 13 ]; then
42+
showHelp
43+
fi
44+
45+
while [ "$1" != "" ]; do
46+
case $1 in
47+
-nbmaster)
48+
master_server=$2
49+
;;
50+
-login_username)
51+
login_username=$2
52+
;;
53+
-login_password)
54+
login_password=$2
55+
;;
56+
-login_domainname)
57+
login_domainname=$2
58+
;;
59+
-login_domaintype)
60+
login_domaintype=$2
61+
;;
62+
-force|-f)
63+
force=1
64+
;;
65+
-reason|-r)
66+
reason=$2
67+
;;
68+
*)
69+
showHelp
70+
;;
71+
esac
72+
shift 2
73+
done
74+
75+
if [ -z "$master_server" ] || [ -z "$login_username" ] || [ -z "$login_password" ] || [ -z "$login_domainname" ] || [ -z "$login_domaintype" ]; then
76+
showHelp
77+
fi
78+
79+
if [ "${login_domaintype^^}" = "WINDOWS" ] || [ "${login_domaintype^^}" = "NT" ]; then
80+
login_domaintype="nt"
81+
fi
82+
}
83+
84+
###############main############
85+
86+
parseArguments "$@"
87+
88+
basepath="https://$master_server:$port/netbackup"
89+
content_header='content-type:application/json'
90+
91+
##############login#############
92+
93+
uri="$basepath/login"
94+
95+
data=$(jq --arg name $login_username --arg pass $login_password --arg dname $login_domainname --arg dtype $login_domaintype \
96+
--null-input '{userName: $name, password: $pass, domainName: $dname, domainType: $dtype}')
97+
98+
jwt=$(curl --silent -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token')
99+
100+
##############jobs##############
101+
auth_header="authorization:$jwt"
102+
content_header='content-type:application/vnd.netbackup+json;version=4.0'
103+
uri="$basepath/security/certificate-authorities/migration-complete"
104+
105+
# Construct request body
106+
request_body="{"
107+
request_body="${request_body}\"data\": {"
108+
request_body="${request_body}\"type\": \"nbcaMigrationCompleteRequest\","
109+
request_body="${request_body}\"attributes\": {"
110+
if [ $force == 1 ]; then
111+
request_body="${request_body}\"force\" : \"TRUE\""
112+
fi
113+
request_body="${request_body}}}}"
114+
115+
if [ -z $reason ]; then
116+
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -d "$request_body" | jq
117+
else
118+
audit_reason="X-NetBackup-Audit-Reason:$reason";
119+
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -H "$audit_reason" -d "$request_body" | jq
120+
fi
121+
122+
exit 0

snippets/curl/initiate_migration.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/sh
2+
3+
#####################n#####################################################
4+
5+
# This script demonstrates how to initiate CA migration.
6+
# To initiate the CA migration, a user needs to have proper permissions.
7+
8+
# This script requires jq command-line JSON parser
9+
# if your system does not have jq installed, this will not work.
10+
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
11+
12+
###########################################################################
13+
14+
port=1556
15+
master_server=""
16+
login_username=""
17+
login_password=""
18+
login_domainname=""
19+
login_domaintype=""
20+
keysize=""
21+
reason=""
22+
23+
showHelp()
24+
{
25+
echo ""
26+
echo "Invalid command parameters"
27+
echo "Usage:"
28+
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>]"
29+
echo "-nbmaster : Name of the NetBackup master server"
30+
echo "-login_username : User name of the user performing action"
31+
echo "-login_password : Password of the user performing action"
32+
echo "-login_domainname : Domain name of the user performing action"
33+
echo "-login_domaintype : Domain type of the user performing action"
34+
echo "-keysize | -k : NetBackup CA key strength"
35+
echo "-reason | -r : Reason for initiating CA migration"
36+
echo ""
37+
exit 1
38+
}
39+
40+
parseArguments()
41+
{
42+
if [ $# -ne 12 ] && [ $# -ne 14 ]; then
43+
showHelp
44+
fi
45+
46+
while [ "$1" != "" ]; do
47+
case $1 in
48+
-nbmaster)
49+
master_server=$2
50+
;;
51+
-login_username)
52+
login_username=$2
53+
;;
54+
-login_password)
55+
login_password=$2
56+
;;
57+
-login_domainname)
58+
login_domainname=$2
59+
;;
60+
-login_domaintype)
61+
login_domaintype=$2
62+
;;
63+
-keysize | -k)
64+
keysize=$2
65+
;;
66+
-reason | -r)
67+
reason=$2
68+
;;
69+
*)
70+
showHelp
71+
;;
72+
esac
73+
shift 2
74+
done
75+
76+
if [ -z "$master_server" ] || [ -z "$login_username" ] || [ -z "$login_password" ] || [ -z "$login_domainname" ] || [ -z "$login_domaintype" ] || [ -z "$keysize" ]; then
77+
showHelp
78+
fi
79+
80+
if [ "${login_domaintype^^}" = "WINDOWS" ] || [ "${login_domaintype^^}" = "NT" ]; then
81+
login_domaintype="nt"
82+
fi
83+
}
84+
85+
###############main############
86+
87+
parseArguments "$@"
88+
89+
basepath="https://$master_server:$port/netbackup"
90+
content_header='content-type:application/json'
91+
92+
##############login#############
93+
94+
uri="$basepath/login"
95+
96+
data=$(jq --arg name $login_username --arg pass $login_password --arg dname $login_domainname --arg dtype $login_domaintype \
97+
--null-input '{userName: $name, password: $pass, domainName: $dname, domainType: $dtype}')
98+
99+
jwt=$(curl --silent -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token')
100+
101+
##############jobs##############
102+
auth_header="authorization:$jwt"
103+
content_header='content-type:application/vnd.netbackup+json;version=4.0'
104+
uri="$basepath/security/certificate-authorities/initiate-migration"
105+
106+
# Construct request body
107+
request_body="{"
108+
request_body="${request_body}\"data\": {"
109+
request_body="${request_body}\"type\": \"initiateCAMigrationRequest\","
110+
request_body="${request_body}\"attributes\": {"
111+
request_body="${request_body}\"keySize\" : \"${keysize}\""
112+
request_body="${request_body}}}}"
113+
114+
if [ -z $reason ]; then
115+
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -d "$request_body" | jq
116+
else
117+
audit_reason="X-NetBackup-Audit-Reason:$reason";
118+
curl --silent -k -X POST "$uri" -H "$content_header" -H "$auth_header" -H "$audit_reason" -d "$request_body" | jq
119+
fi
120+
121+
exit 0

snippets/perl/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,15 @@ API key Details:
126126

127127
- Use the following command to use API key instead of JWT to trigger a NetBackup REST API on your NetBackup Master server:
128128
- `perl apikey_usage.pl -nbmaster <master_server> -apikey <apikey> [--verbose]`
129+
130+
CA Migration Details:
131+
132+
- Use the following command to initiate the NetBackup CA migration on your NetBackup Master server:
133+
- `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]`
134+
135+
- Use the following command to activate the new NetBackup CA on your NetBackup Master server:
136+
- `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]`
137+
138+
- Use the following command to complete the NetBackup CA migration on your NetBackup Master server:
139+
- `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]`
140+

0 commit comments

Comments
 (0)