Skip to content

Commit 2a354ee

Browse files
committed
Rewrote Replace-SGWAccount
1 parent 7368366 commit 2a354ee

1 file changed

Lines changed: 37 additions & 26 deletions

File tree

src/StorageGRID-Webscale.psm1

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -536,16 +536,24 @@ function Global:Replace-SGWAccount {
536536
ValueFromPipeline=$True,
537537
ValueFromPipelineByPropertyName=$True)][String[]]$Id,
538538
[parameter(
539-
Mandatory=$True,
539+
Mandatory=$False,
540540
Position=1,
541541
HelpMessage="Comma separated list of capabilities of the account. Can be swift, S3 and management (e.g. swift,s3 or s3,management ...).")][String[]]$Capabilities,
542542
[parameter(
543-
Mandatory=$True,
543+
Mandatory=$False,
544544
Position=2,
545545
HelpMessage="New name of the StorageGRID Webscale Account.")][String]$Name,
546546
[parameter(
547547
Mandatory=$False,
548548
Position=3,
549+
HelpMessage="Use account identity source (supported since StorageGRID 10.4).")][Boolean]$UseAccountIdentitySource=$true,
550+
[parameter(
551+
Mandatory=$False,
552+
Position=4,
553+
HelpMessage="Quota for tenant in bytes.")][Long]$Quota,
554+
[parameter(
555+
Mandatory=$False,
556+
Position=5,
549557
HelpMessage="StorageGRID Webscale Management Server object. If not specified, global CurrentSGWServer object will be used.")][PSCustomObject]$Server
550558
)
551559

@@ -556,38 +564,41 @@ function Global:Replace-SGWAccount {
556564
if (!$Server) {
557565
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
558566
}
559-
560-
if ($Capabilities) {
561-
$Capabilities = '"' + ($Capabilities -split ',' -join '","') + '"'
567+
568+
if ($Server.APIVersion -lt 2 -and ($Quota -or $Password)) {
569+
Write-Warning "Quota and password will be ignored in API Version $($Server.APIVersion)"
562570
}
563571
}
564572

565573
Process {
566-
$Id = @($Id)
567-
foreach ($Id in $Id) {
568-
$Uri = $Server.BaseURI + "/grid/accounts/$id"
569-
$Method = "PUT"
574+
$Body = @{}
575+
if ($Name) {
576+
$Body.name = $Name
577+
}
578+
if ($Capabilities) {
579+
$Body.capabilities = $Capabilities
580+
}
570581

571-
$Body = @"
572-
{
573-
"id": "$id",
574-
"name": "$Name",
575-
"capabilities": [ $Capabilities ]
576-
}
577-
"@
582+
if ($Server.APIVersion -ge 2) {
583+
$Body.policy = @{"useAccountIdentitySource"=$UseAccountIdentitySource}
584+
if ($Quota) {
585+
$Body.policy.quotaObjectBytes = $Quota
586+
}
587+
}
578588

579-
Write-Verbose $Body
589+
$Body = $Body | ConvertTo-Json
580590

581-
try {
582-
$Result = Invoke-RestMethod -WebSession $Server.Session -Method $Method -Uri $Uri -Headers $Server.Headers -Body $Body -ContentType "application/json"
583-
}
584-
catch {
585-
$ResponseBody = ParseExceptionBody $_.Exception.Response
586-
Write-Error "$Method to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
587-
}
588-
589-
Write-Output $Result.data
591+
Write-Verbose "Body: $Body"
592+
593+
try {
594+
$Result = Invoke-RestMethod -WebSession $Server.Session -Method $Method -Uri $Uri -Headers $Server.Headers -Body $Body -ContentType "application/json"
590595
}
596+
catch {
597+
$ResponseBody = ParseExceptionBody $_.Exception.Response
598+
Write-Error "$Method to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
599+
}
600+
601+
Write-Output $Result.data
591602
}
592603
}
593604

0 commit comments

Comments
 (0)