@@ -271,22 +271,22 @@ function Global:New-SGWAccount {
271271 [parameter (
272272 Mandatory = $True ,
273273 Position = 1 ,
274- HelpMessage = " Comma separated list of capabilities of the account. Can be swift, S3 and management (e.g. swift,s3 or s3,management ...)." )][String ]$Capabilities ,
274+ HelpMessage = " Comma separated list of capabilities of the account. Can be swift, S3 and management (e.g. swift,s3 or s3,management ...)." )][String [] ]$Capabilities ,
275275 [parameter (
276276 Mandatory = $False ,
277277 Position = 2 ,
278278 HelpMessage = " Use account identity source (supported since StorageGRID 10.4)." )][Boolean ]$UseAccountIdentitySource = $true ,
279279 [parameter (
280280 Mandatory = $False ,
281281 Position = 3 ,
282- HelpMessage = " Quota for tenant in bytes." )][Int ]$Quota ,
282+ HelpMessage = " Quota for tenant in bytes." )][Long ]$Quota ,
283283 [parameter (
284284 Mandatory = $False ,
285285 Position = 4 ,
286286 HelpMessage = " Tenant root password." )][String ]$Password ,
287287 [parameter (
288288 Mandatory = $False ,
289- Position = 4 ,
289+ Position = 5 ,
290290 HelpMessage = " StorageGRID Webscale Management Server object. If not specified, global CurrentSGWServer object will be used." )][PSCustomObject ]$Server
291291 )
292292
@@ -300,50 +300,33 @@ function Global:New-SGWAccount {
300300 if ($Server.APIVersion -ge 2 -and ! $Password ) {
301301 Throw " Password required"
302302 }
303+ if ($Server.APIVersion -lt 2 -and ($Quota -or $Password )) {
304+ Write-Warning " Quota and password will be ignored in API Version $ ( $Server.APIVersion ) "
305+ }
303306
304- $Capabilities = ' " ' + ($Capabilities -split ' ,' -join ' "," ' ) + ' " '
307+ $Capabilities = @ ($Capabilities -split ' ,' )
305308 }
306309
307310 Process {
308311 $Uri = $Server.BaseURI + " /grid/accounts"
309312 $Method = " POST"
310313
311- if ($Server.APIVersion -lt 2 ) {
312- $Body = @"
313- {
314- "name": "$Name ",
315- "capabilities": [ $Capabilities ]
316- }
317- "@
318- }
319- else {
314+ $Body = @ {}
315+ $Body.name = $Name [0 ]
316+ $Body.capabilities = $Capabilities
317+
318+ if ($Server.APIVersion -ge 2 ) {
319+ $Body.password = $Password
320+ $Body.policy = @ {" useAccountIdentitySource" = $UseAccountIdentitySource }
320321 if ($Quota ) {
321- $Body = @"
322- {
323- "name": "$Name ",
324- "capabilities": [ $Capabilities ]
325- "policy": {
326- "useAccountIdentitySource": $UseAccountIdentitySource ,
327- "quotaObjectBytes": $Quota
328- },
329- "password": "$Password "
330- }
331- "@
332- }
333- else {
334- $Body = @"
335- {
336- "name": "$Name ",
337- "capabilities": [ $Capabilities ]
338- "policy": {
339- "useAccountIdentitySource": $UseAccountIdentitySource
340- },
341- "password": "$Password "
342- }
343- "@
322+ $Body.policy.quotaObjectBytes = $Quota
344323 }
345324 }
346325
326+ $Body = $Body | ConvertTo-Json
327+
328+ Write-Verbose " Body: $Body "
329+
347330 try {
348331 $Result = Invoke-RestMethod - WebSession $Server.Session - Method $Method - Uri $Uri - Headers $Server.Headers - Body $Body - ContentType " application/json"
349332 }
@@ -479,6 +462,14 @@ function Global:Update-SGWAccount {
479462 [parameter (
480463 Mandatory = $False ,
481464 Position = 3 ,
465+ HelpMessage = " Use account identity source (supported since StorageGRID 10.4)." )][Boolean ]$UseAccountIdentitySource = $true ,
466+ [parameter (
467+ Mandatory = $False ,
468+ Position = 4 ,
469+ HelpMessage = " Quota for tenant in bytes." )][Long ]$Quota ,
470+ [parameter (
471+ Mandatory = $False ,
472+ Position = 5 ,
482473 HelpMessage = " StorageGRID Webscale Management Server object. If not specified, global CurrentSGWServer object will be used." )][PSCustomObject ]$Server
483474 )
484475
@@ -489,56 +480,48 @@ function Global:Update-SGWAccount {
489480 if (! $Server ) {
490481 Throw " No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
491482 }
483+
484+ if ($Server.APIVersion -lt 2 -and ($Quota -or $Password )) {
485+ Write-Warning " Quota and password will be ignored in API Version $ ( $Server.APIVersion ) "
486+ }
492487
493488 if ($Capabilities ) {
494489 $Capabilities = ' "' + ($Capabilities -split ' ,' -join ' ","' ) + ' "'
495490 }
496491 }
497492
498493 Process {
499- $Id = @ ($Id )
500- foreach ($Id in $Id ) {
501- $Uri = $Server.BaseURI + " /grid/accounts/$id "
502- $Method = " PATCH"
494+ $Uri = $Server.BaseURI + " /grid/accounts/$id "
495+ $Method = " PATCH"
503496
504- if ($Name -and -not $Capabilities ) {
505- $Body = @"
506- {
507- "name": "$Name "
508- }
509- "@
510- }
511- elseif ($Capabilities -and -not $Name ) {
512- $Body = @"
513- {
514- "capabilities": [ $Capabilities ]
515- }
516- "@
517- }
518- elseif ($Capabilities -and $Name ) {
519- $Body = @"
520- {
521- "name": "$Name ",
522- "capabilities": [ $Capabilities ]
523- }
524- "@
525- }
526- else {
527- Write-Error " Name or Capability or both required"
497+ $Body = @ {}
498+ if ($Name ) {
499+ $Body.name = $Name
500+ }
501+ if ($Capabilities ) {
502+ $Body.capabilities = $Capabilities
503+ }
504+
505+ if ($Server.APIVersion -ge 2 ) {
506+ $Body.policy = @ {" useAccountIdentitySource" = $UseAccountIdentitySource }
507+ if ($Quota ) {
508+ $Body.policy.quotaObjectBytes = $Quota
528509 }
510+ }
529511
530- Write-Verbose $Body
512+ $Body = $Body | ConvertTo-Json
531513
532- try {
533- $Result = Invoke-RestMethod - WebSession $Server.Session - Method $Method - Uri $Uri - Headers $Server.Headers - Body $Body - ContentType " application/json"
534- }
535- catch {
536- $ResponseBody = ParseExceptionBody $_.Exception.Response
537- Write-Error " $Method to $Uri failed with Exception $ ( $_.Exception.Message ) `n $responseBody "
538- }
539-
540- Write-Output $Result.data
514+ Write-Verbose " Body: $Body "
515+
516+ try {
517+ $Result = Invoke-RestMethod - WebSession $Server.Session - Method $Method - Uri $Uri - Headers $Server.Headers - Body $Body - ContentType " application/json"
518+ }
519+ catch {
520+ $ResponseBody = ParseExceptionBody $_.Exception.Response
521+ Write-Error " $Method to $Uri failed with Exception $ ( $_.Exception.Message ) `n $responseBody "
541522 }
523+
524+ Write-Output $Result.data
542525 }
543526}
544527
0 commit comments