-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathConfig_trust_management_crud_operation.ps1
More file actions
239 lines (199 loc) · 7.48 KB
/
Config_trust_management_crud_operation.ps1
File metadata and controls
239 lines (199 loc) · 7.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<#
.SYNOPSIS
This sample script demonstrates the use of NetBackup Trust Management APIs.
.DESCRIPTION
The script can be run using NetBackup 8.2 or higher.
It updates the exclude list configuration on the specified client. The exclude list is specified within the script below.
.EXAMPLE
./Config_trust_management_crud_operation.ps1 -MasterServer <masterServer> -UserName <username> -Password <password> -TrustedMasterServerName <Trusted master Server Name> [-DomainName <domainName> -DomainType <domainType>]
#>
#Requires -Version 4.0
Param (
[string]$MasterServer = $(Throw "Please specify the name of the NetBackup Master Server using the -MasterServer parameter."),
[string]$UserName = $(Throw "Please specify the user name using the -UserName parameter."),
[string]$Password = $(Throw "Please specify the password using the -Password parameter."),
[string]$TrustedMasterServerName = $(Throw "Please specify the name of the NetBackup remote Master Server using the -TrustedMasterServerName parameter."),
[string]$DomainName,
[string]$DomainType
)
###############################################################
# Setup to allow self-signed certificates and enable TLS v1.2
###############################################################
Function Setup()
{
# Allow self-signed certificates
if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy')
{
Add-Type -TypeDefinition @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy
}
# Force TLS v1.2
try {
if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}
}
catch {
Write-Host "`n"$_.Exception.InnerException.Message
}
}
####################
# Global Variables
####################
$port = 1556
$basepath = "https://" + $MasterServer + ":" + $port + "/netbackup"
$contentType = "application/vnd.netbackup+json;version=4.0"
$hostName = $client
######################################
# Login to the NetBackup webservices
######################################
Function Login()
{
$uri = $basepath + "/login"
$body = @{
userName=$UserName
password=$Password
}
if ($DomainName -ne "") {
$body.add("domainName", $DomainName)
}
if ($DomainType -ne "") {
$body.add("domainType", $DomainType)
}
Write-Host "`nSending a POST request to login to the NetBackup webservices...`n"
$response = Invoke-WebRequest `
-Uri $uri `
-Method POST `
-Body (ConvertTo-Json -InputObject $body) `
-ContentType $contentType
if ($response.StatusCode -ne 201)
{
throw "Unable to connect to the NetBackup Master Server"
}
Write-Host "Login successful.`n"
$content = (ConvertFrom-Json -InputObject $response)
return $content
}
#####################################################################
# POST NetBackup Storage server
#####################################################################
Function CreateTrust()
{
$base_uri = $basepath + "/config/servers/trusted-master-servers"
$json = '{
"data": {
"type": "trustedMasterServer",
"attributes": {
"trustedMasterServerName": "'+$TrustedMasterServerName+'",
"rootCAType": "NBCA",
"authenticationType": "CREDENTIAL",
"domainName": "DOMAIN",
"userName": "USER",
"password": "PASSWORD",
"fingerprint": "FINGERPRINT"
}
}
}
'
$response_create_trust = Invoke-WebRequest `
-Uri $base_uri `
-Method POST `
-Body ($json) `
-ContentType $contentType `
-Headers $headers
if ($response_create_trust.StatusCode -ne 201)
{
throw "Unable to create trust between master servers."
}
Write-Host "Trust between master servers created successfully.`n"
echo $response_create_trust
Write-Host $response_create_trust
$response_create_trust = (ConvertFrom-Json -InputObject $response_create_trust)
}
#####################################################################
# GET NetBackup Trusted Master Server
#####################################################################
Function GetTrustedMaster()
{
$base_uri = $basepath + "/config/servers/trusted-master-servers/" + $TrustedMasterServerName
$response_get = Invoke-WebRequest `
-Uri $base_uri `
-Method GET `
-ContentType $contentType `
-Headers $headers
if ($response_get.StatusCode -ne 200)
{
throw "Unable to fetch scpecified trusted master server"
}
Write-Host "Scpecified trusted master server fetched successfully.`n"
Write-Host $response_get
$response_get = (ConvertFrom-Json -InputObject $response_get)
}
#####################################################################
# PATCH NetBackup trust between master servers
#####################################################################
Function UpdateTrust()
{
$base_uri = $basepath + "/config/servers/trusted-master-servers/" + $TrustedMasterServerName
$json = '{
"data": {
"type": "trustedMasterServer",
"attributes": {
"trustedMasterServerName": "'+$TrustedMasterServerName+'",
"rootCAType": "ECA"
}
}
}
'
$response_update = Invoke-WebRequest `
-Uri $base_uri `
-Method PATCH `
-Body ($json) `
-ContentType $contentType `
-Headers $headers
if ($response_update.StatusCode -ne 200)
{
throw "Unable to update trust between masters."
}
Write-Host "Trust between masters updated successfully.`n"
echo $response_update
Write-Host $response_update
$response_update = (ConvertFrom-Json -InputObject $response_update)
}
#####################################################################
# Delete NetBackup Trust between master Server
#####################################################################
Function DeleteTrust()
{
$base_uri = $basepath + "/config/servers/trusted-master-servers/" + $TrustedMasterServerName
$response_delete = Invoke-WebRequest `
-Uri $base_uri `
-Method DELETE `
-ContentType $contentType `
-Headers $headers
if ($response_delete.StatusCode -ne 204 )
{
throw "Unable to delete trust between masters."
}
Write-Host "Trust between masters deleted successfully.`n"
Write-Host $response_delete
$response_delete = (ConvertFrom-Json -InputObject $response_delete)
}
###########################################################################
Setup
$loginResponse = Login
$headers = @{"Authorization" = $loginResponse.token}
CreateTrust
GetTrustedMaster
UpdateTrust
DeleteTrust