Skip to content

Commit fc6e533

Browse files
committed
Added Compliance Cmdlets
1 parent bd0edd8 commit fc6e533

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

src/StorageGRID-Webscale.psm1

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,130 @@ function global:Disconnect-SgwServer {
25112511
}
25122512
}
25132513

2514+
## compliance ##
2515+
2516+
# complete as of API 2.2
2517+
2518+
<#
2519+
.SYNOPSIS
2520+
Retrieves the global compliance settings
2521+
.DESCRIPTION
2522+
Retrieves the global compliance settings
2523+
.PARAMETER Server
2524+
StorageGRID Webscale Management Server object. If not specified, global CurrentSgwServer object will be used.
2525+
.PARAMETER ProfileName
2526+
StorageGRID Profile to use for connection.
2527+
#>
2528+
function Global:Get-SgwCompliance {
2529+
[CmdletBinding()]
2530+
2531+
PARAM (
2532+
[parameter(Mandatory = $False,
2533+
Position = 0,
2534+
HelpMessage = "StorageGRID Webscale Management Server object. If not specified, global CurrentSgwServer object will be used.")][PSCustomObject]$Server,
2535+
[parameter(Mandatory = $False,
2536+
Position = 1,
2537+
HelpMessage = "StorageGRID Profile to use for connection.")][Alias("Profile")][String]$ProfileName
2538+
)
2539+
2540+
Begin {
2541+
if (!$ProfileName -and !$Server -and !$CurrentSgwServer.Name) {
2542+
$ProfileName = "default"
2543+
}
2544+
if ($ProfileName) {
2545+
$Profile = Get-SgwProfile -ProfileName $ProfileName
2546+
$Server = Connect-SgwServer -Name $Profile.Name -Credential $Profile.Credential -AccountId $Profile.AccountId -SkipCertificateCheck:$Profile.SkipCertificateCheck -DisableAutomaticAccessKeyGeneration:$Profile.disalble_automatic_access_key_generation -TemporaryAccessKeyExpirationTime $Profile.temporary_access_key_expiration_time -S3EndpointUrl $Profile.S3EndpointUrl -SwiftEndpointUrl $Profile.SwiftEndpointUrl -Transient
2547+
}
2548+
2549+
if (!$Server) {
2550+
$Server = $Global:CurrentSgwServer
2551+
}
2552+
if (!$Server) {
2553+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SgwServer to continue."
2554+
}
2555+
}
2556+
2557+
Process {
2558+
$Uri = $Server.BaseURI + "/grid/compliance-global"
2559+
$Method = "GET"
2560+
2561+
try {
2562+
$Response = Invoke-SgwRequest -WebSession $Server.Session -Method $Method -Uri $Uri -Headers $Server.Headers -SkipCertificateCheck:$Server.SkipCertificateCheck
2563+
}
2564+
catch {
2565+
$ResponseBody = ParseErrorForResponseBody $_
2566+
Write-Error "$Method to $Uri failed with Exception $( $_.Exception.Message ) `n $responseBody"
2567+
}
2568+
2569+
Write-Output $Response.Json.data
2570+
}
2571+
}
2572+
2573+
<#
2574+
.SYNOPSIS
2575+
Enable Grid wide compliance
2576+
.DESCRIPTION
2577+
Enable Grid wide compliance
2578+
.PARAMETER Server
2579+
StorageGRID Webscale Management Server object. If not specified, global CurrentSgwServer object will be used.
2580+
.PARAMETER ProfileName
2581+
StorageGRID Profile to use for connection.
2582+
#>
2583+
function Global:Enable-SgwCompliance {
2584+
[CmdletBinding()]
2585+
2586+
PARAM (
2587+
[parameter(Mandatory = $False,
2588+
Position = 0,
2589+
HelpMessage = "StorageGRID Webscale Management Server object. If not specified, global CurrentSgwServer object will be used.")][PSCustomObject]$Server,
2590+
[parameter(Mandatory = $False,
2591+
Position = 1,
2592+
HelpMessage = "StorageGRID Profile to use for connection.")][Alias("Profile")][String]$ProfileName
2593+
)
2594+
2595+
Begin {
2596+
if (!$ProfileName -and !$Server -and !$CurrentSgwServer.Name) {
2597+
$ProfileName = "default"
2598+
}
2599+
if ($ProfileName) {
2600+
$Profile = Get-SgwProfile -ProfileName $ProfileName
2601+
$Server = Connect-SgwServer -Name $Profile.Name -Credential $Profile.Credential -AccountId $Profile.AccountId -SkipCertificateCheck:$Profile.SkipCertificateCheck -DisableAutomaticAccessKeyGeneration:$Profile.disalble_automatic_access_key_generation -TemporaryAccessKeyExpirationTime $Profile.temporary_access_key_expiration_time -S3EndpointUrl $Profile.S3EndpointUrl -SwiftEndpointUrl $Profile.SwiftEndpointUrl -Transient
2602+
}
2603+
2604+
if (!$Server) {
2605+
$Server = $Global:CurrentSgwServer
2606+
}
2607+
if (!$Server) {
2608+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SgwServer to continue."
2609+
}
2610+
}
2611+
2612+
Process {
2613+
$ConfirmComplianceEnabling = $Host.UI.PromptForChoice("Enable Complaince",
2614+
"Cannot disable Grid wide Compliance on $($Server.Name) after it has been enabled. Still continue?",
2615+
@("&Yes", "&No"),
2616+
1)
2617+
if ($ConfirmComplianceEnabling -eq 1) {
2618+
break
2619+
}
2620+
2621+
$Uri = $Server.BaseURI + "/grid/compliance-global"
2622+
$Method = "PUT"
2623+
2624+
$Body = ConvertTo-Json -InputObject @{complianceEnabled=$true}
2625+
2626+
try {
2627+
$Response = Invoke-SgwRequest -WebSession $Server.Session -Method $Method -Uri $Uri -Headers $Server.Headers -Body $Body -SkipCertificateCheck:$Server.SkipCertificateCheck
2628+
}
2629+
catch {
2630+
$ResponseBody = ParseErrorForResponseBody $_
2631+
Write-Error "$Method to $Uri failed with Exception $( $_.Exception.Message ) `n $responseBody"
2632+
}
2633+
2634+
Write-Output $Response.Json.data
2635+
}
2636+
}
2637+
25142638
## config ##
25152639

25162640
# complete as of API 2.1

0 commit comments

Comments
 (0)