Skip to content

[Storage] Support MaxPageSize, Include, and Filter for listing encryption scopes #20169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function Test-StorageBlobContainerEncryptionScope
$containerName2 = "container2"+ $rgname
$scopeName = "testscope"
$scopeName2 = "testscope2"
$scopeName3 = "filtertestscope3"

Write-Verbose "RGName: $rgname | Loc: $loc"
New-AzResourceGroup -Name $rgname -Location $loc;
Expand All @@ -190,8 +191,20 @@ function Test-StorageBlobContainerEncryptionScope

#List Scope
New-AzStorageEncryptionScope -ResourceGroupName $rgname -StorageAccountName $stoname -EncryptionScopeName $scopeName2 -StorageEncryption
New-AzStorageEncryptionScope -ResourceGroupName $rgname -StorageAccountName $stoname -EncryptionScopeName $scopeName3 -StorageEncryption
Update-AzStorageEncryptionScope -ResourceGroupName $rgname -StorageAccountName $stoname -EncryptionScopeName $scopeName3 -State Disabled
$scopes = Get-AzStorageEncryptionScope -ResourceGroupName $rgname -StorageAccountName $stoname
Assert-AreEqual 3 $scopes.Count
$scopes = Get-AzStorageEncryptionScope -ResourceGroupName $rgname -StorageAccountName $stoname -MaxPageSize 1 -Include Disabled
Assert-AreEqual 1 $scopes.Count
Assert-AreEqual "Disabled" $scopes[0].State
$scopes = Get-AzStorageEncryptionScope -ResourceGroupName $rgname -StorageAccountName $stoname -Include All -Filter "startswith(name, filter)"
Assert-AreEqual 1 $scopes.Count
Assert-AreEqual $scopeName3 $scopes[0].Name
$scopes = Get-AzStorageEncryptionScope -ResourceGroupName $rgname -StorageAccountName $stoname -Include Enabled
Assert-AreEqual 2 $scopes.Count
Assert-AreEqual "Enabled" $scopes[0].State
Assert-AreEqual "Enabled" $scopes[1].State

#create container
New-AzRmStorageContainer -ResourceGroupName $rgname -StorageAccountName $stoname -Name $containerName -DefaultEncryptionScope $scopename -PreventEncryptionScopeOverride $true
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Additional information about change #1
-->
## Upcoming Release
* Supported MaxPageSize, Include, and Filter parameters for listing encryption scopes
- `Get-AzStorageEncryptionScope`
* Supported excludePrefix, includeDeleted, and many new schema fields in Blob Inventory
- `New-AzStorageBlobInventoryPolicyRule`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ public class GetAzureStorageEncryptionScopeCommand : StorageFileBaseCmdlet
[ValidateNotNullOrEmpty]
public string EncryptionScopeName { get; set; }

[Parameter(Mandatory = false,
HelpMessage = "The maximum number of encryption scopes that will be included in the list response")]
[ValidateNotNullOrEmpty]
public int? MaxPageSize { get; set; }

[Parameter(Mandatory = false,
HelpMessage = "The filter of encryption scope name. When specified, only encryption scope names starting with the filter will be listed. The filter must be in format: startswith(name, <prefix>)")]
[ValidateNotNullOrEmpty]
public string Filter { get; set; }

[Parameter(Mandatory = false,
HelpMessage = "Optional, when specified, will list encryption scopes with the specific state. Defaults to All.")]
[ValidateSet(ListEncryptionScopesInclude.All,
ListEncryptionScopesInclude.Enabled,
ListEncryptionScopesInclude.Disabled)]
[ValidateNotNullOrEmpty]
public string Include { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
Expand All @@ -87,7 +105,7 @@ public override void ExecuteCmdlet()
{
IPage<EncryptionScope> scopes = this.StorageClient.EncryptionScopes.List(
this.ResourceGroupName,
this.StorageAccountName);
this.StorageAccountName, this.MaxPageSize, this.Filter, this.Include);
WriteEncryptionScopeList(scopes);

while (scopes.NextPageLink != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ Get or list encryption scopes from a Storage account.
### AccountName (Default)
```
Get-AzStorageEncryptionScope [-ResourceGroupName] <String> [-StorageAccountName] <String>
[-EncryptionScopeName <String>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
[-EncryptionScopeName <String>] [-MaxPageSize <Int32>] [-Filter <String>] [-Include <String>]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### AccountObject
```
Get-AzStorageEncryptionScope -StorageAccount <PSStorageAccount> [-EncryptionScopeName <String>]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
[-MaxPageSize <Int32>] [-Filter <String>] [-Include <String>] [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -60,6 +62,38 @@ scope2 Enabled Microsoft.Storage

This command lists all encryption scopes of a Storage account.

### Example 3: List all enabled encryption scopes of a Storage account with a max page size of 10 for each request
```powershell
Get-AzStorageEncryptionScope -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -MaxPageSize 10 -Include Enabled
```

```output
ResourceGroupName: myresourcegroup, StorageAccountName: mystorageaccount

Name State Source KeyVaultKeyUri
---- ----- ------ --------------
scope1 Enabled Microsoft.Keyvault https://keyvalutname.vault.azure.net:443/keys/keyname
scope2 Enabled Microsoft.Storage
```
This command lists all enabled encryption scopes of a Storage account, with a max page size of 10 encryption scopes included in each list response.
If there are more than 10 encryption scopes to be listed, the command will still list all the encryption scopes, but with multiple requests sent and responses received.

### Example 4: List all disabled encryption scopes with names starting with "test" of a Storage account
```powershell
Get-AzStorageEncryptionScope -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -Include Disabled -Filter "startswith(name, test)"
```

```output
ResourceGroupName: myresourcegroup, StorageAccountName: mystorageaccount

Name State Source KeyVaultKeyUri
---- ----- ------ --------------
testscope1 Disabled Microsoft.Keyvault https://keyvalutname.vault.azure.net:443/keys/keyname
testscope2 Disabled Microsoft.Storage
```
This command lists all disabled encryption scopes with names starting with "test" of a Storage account.
The parameter "Filter" specifies the prefix of the encryption scopes listed, and it should be in format of �startswith(name, {prefixValue})�.

## PARAMETERS

### -DefaultProfile
Expand Down Expand Up @@ -92,6 +126,52 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Filter
The filter of encryption scope name. When specified, only encryption scope names starting with the filter will be listed.

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Include
The filter of encryption scope name. When specified, only encryption scope names starting with the filter will be listed.

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:
Accepted values: All, Enabled, Disabled

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -MaxPageSize
The maximum number of encryption scopes that will be included in the list response

```yaml
Type: System.Nullable`1[System.Int32]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ResourceGroupName
Resource Group Name.

Expand Down Expand Up @@ -138,7 +218,7 @@ Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

Expand Down