Skip to content

Commit c15aaf3

Browse files
authored
[Storage Dataplane] - Remove Validation Set and move to track2 SDK for accesstier (#20554)
* [Storage Dataplane] - Remove Validation Set and move to track2 SDK for accesstier * Fix CI failure
1 parent fe9757d commit c15aaf3

File tree

10 files changed

+112
-129
lines changed

10 files changed

+112
-129
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Removed the ValidateSet of StandardBlobTier parameter
22+
- `Copy-AzStorageBlob`
23+
- `Set-AzStorageBlobContent`
24+
- `Start-AzStorageBlobCopy`
2125

2226
## Version 5.3.0
23-
* Return ListBlobProperties in blob list result
27+
* Returned ListBlobProperties in blob list result
2428
- `Get-AzStorageBlob`
25-
* Output AllowedCopyScope in get account result
29+
* Returned AllowedCopyScope in get account result
2630
- `Get-AzStorageAccount`
2731

2832
## Version 5.2.0

src/Storage/Storage.Management/help/Copy-AzStorageBlob.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,38 @@ The **Copy-AzStorageBlob** cmdlet copies a blob synchronously, currently only su
4343

4444
### Example 1: Copy a named blob to another
4545
```
46-
C:\PS> $destBlob = Copy-AzStorageBlob -SrcContainer "sourcecontainername" -SrcBlob "srcblobname" -DestContainer "destcontainername" -DestBlob "destblobname"
46+
$destBlob = Copy-AzStorageBlob -SrcContainer "sourcecontainername" -SrcBlob "srcblobname" -DestContainer "destcontainername" -DestBlob "destblobname"
4747
```
4848

4949
This command copies a blob from source container to the destination container with a new blob name.
5050

5151
### Example 2: Copy blob from a blob object
5252
```
53-
C:\PS> $srcBlob = Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $ctx
54-
C:\PS> $destBlob = $srcBlob | Copy-AzStorageBlob -DestContainer "destcontainername" -DestBlob "destblobname"
53+
$srcBlob = Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $ctx
54+
$destBlob = $srcBlob | Copy-AzStorageBlob -DestContainer "destcontainername" -DestBlob "destblobname"
5555
```
5656

5757
This command copies a blob from source blob object to the destination container with a new blob name.
5858

5959
### Example 3: Copy blob from a blob Uri
6060
```
61-
C:\PS> $srcBlobUri = New-AzStorageBlobSASToken -Container $srcContainerName -Blob $srcBlobName -Permission rt -ExpiryTime (Get-Date).AddDays(7) -FullUri
62-
C:\PS> $destBlob = Copy-AzStorageBlob -AbsoluteUri $srcBlobUri -DestContainer "destcontainername" -DestBlob "destblobname"
61+
$srcBlobUri = New-AzStorageBlobSASToken -Container $srcContainerName -Blob $srcBlobName -Permission rt -ExpiryTime (Get-Date).AddDays(7) -FullUri
62+
$destBlob = Copy-AzStorageBlob -AbsoluteUri $srcBlobUri -DestContainer "destcontainername" -DestBlob "destblobname"
6363
```
6464

6565
The first command creates a blob Uri of the source blob, with sas token of permission "rt". The second command copies from source blob Uri to the destination blob.
6666

6767
### Example 4: Update a block blob encryption scope
6868
```
69-
C:\PS> $blob = Copy-AzStorageBlob -SrcContainer $containerName -SrcBlob $blobname -DestContainer $containername -EncryptionScope $newScopeName -Force
69+
$blob = Copy-AzStorageBlob -SrcContainer $containerName -SrcBlob $blobname -DestContainer $containername -EncryptionScope $newScopeName -Force
7070
```
7171

7272
This command update a block blob encryption scope by copy it to itself with a new encryption scope.
7373

74-
### Example 5: Copy a blob to a new append blob
74+
### Example 5: Copy a blob to a new append blob
7575
```
76-
C:\PS> $srcBlob = Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $ctx
77-
C:\PS> $destBlob = Copy-AzStorageBlob -SrcContainer "sourcecontainername" -SrcBlob "srcblobname" -DestContainer "destcontainername" -DestBlob "destblobname" -DestBlobType "Append" -DestContext $destCtx
76+
$srcBlob = Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $ctx
77+
$destBlob = Copy-AzStorageBlob -SrcContainer "sourcecontainername" -SrcBlob "srcblobname" -DestContainer "destcontainername" -DestBlob "destblobname" -DestBlobType "Append" -DestContext $destCtx
7878
```
7979

8080
## PARAMETERS
@@ -325,7 +325,6 @@ See detail in https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-
325325
Type: System.String
326326
Parameter Sets: (All)
327327
Aliases:
328-
Accepted values: Hot, Cool, Archive
329328

330329
Required: False
331330
Position: Named

src/Storage/Storage.Management/help/Set-AzStorageBlobContent.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ The **Set-AzStorageBlobContent** cmdlet uploads a local file to an Azure Storage
5050

5151
### Example 1: Upload a named file
5252
```
53-
PS C:\>Set-AzStorageBlobContent -Container "ContosoUpload" -File ".\PlanningData" -Blob "Planning2015"
53+
Set-AzStorageBlobContent -Container "ContosoUpload" -File ".\PlanningData" -Blob "Planning2015"
5454
```
5555

5656
This command uploads the file that is named PlanningData to a blob named Planning2015.
5757

5858
### Example 2: Upload all files under the current folder
5959
```
60-
PS C:\>Get-ChildItem -File -Recurse | Set-AzStorageBlobContent -Container "ContosoUploads"
60+
Get-ChildItem -File -Recurse | Set-AzStorageBlobContent -Container "ContosoUploads"
6161
```
6262

6363
This command uses the core Windows PowerShell cmdlet Get-ChildItem to get all the files in the current folder and in subfolders, and then passes them to the current cmdlet by using the pipeline operator.
6464
The **Set-AzStorageBlobContent** cmdlet uploads the files to the container named ContosoUploads.
6565

6666
### Example 3: Overwrite an existing blob
6767
```
68-
PS C:\>Get-AzStorageBlob -Container "ContosoUploads" -Blob "Planning2015" | Set-AzStorageBlobContent -File "ContosoPlanning"
68+
Get-AzStorageBlob -Container "ContosoUploads" -Blob "Planning2015" | Set-AzStorageBlobContent -File "ContosoPlanning"
6969
```
7070

7171
This command gets the blob named Planning2015 in the ContosoUploads container by using the Get-AzStorageBlob cmdlet, and then passes that blob to the current cmdlet.
@@ -76,16 +76,16 @@ If you confirm the command, the cmdlet overwrites the existing blob.
7676

7777
### Example 4: Upload a file to a container by using the pipeline
7878
```
79-
PS C:\>Get-AzStorageContainer -Container "ContosoUpload*" | Set-AzStorageBlobContent -File "ContosoPlanning" -Blob "Planning2015"
79+
Get-AzStorageContainer -Container "ContosoUpload*" | Set-AzStorageBlobContent -File "ContosoPlanning" -Blob "Planning2015"
8080
```
8181

8282
This command gets the container that starts with the string ContosoUpload by using the **Get-AzStorageContainer** cmdlet, and then passes that blob to the current cmdlet.
8383
The command uploads the file that is named ContosoPlanning as Planning2015.
8484

8585
### Example 5: Upload a file to page blob with metadata and PremiumPageBlobTier as P10
8686
```
87-
PS C:\>$Metadata = @{"key" = "value"; "name" = "test"}
88-
PS C:\> Set-AzStorageBlobContent -File "ContosoPlanning" -Container "ContosoUploads" -Metadata $Metadata -BlobType Page -PremiumPageBlobTier P10
87+
$Metadata = @{"key" = "value"; "name" = "test"}
88+
Set-AzStorageBlobContent -File "ContosoPlanning" -Container "ContosoUploads" -Metadata $Metadata -BlobType Page -PremiumPageBlobTier P10
8989
```
9090

9191
The first command creates a hash table that contains metadata for a blob, and stores that hash table in the $Metadata variable.
@@ -94,6 +94,8 @@ The blob includes the metadata stored in $Metadata, and has PremiumPageBlobTier
9494

9595
### Example 6: Upload a file to blob with specified blob properties, and set StandardBlobTier as Cool
9696
<!-- Skip: Output cannot be splitted from code -->
97+
98+
9799
```
98100
PS C:\> $filepath = "c:\temp\index.html"
99101
PS C:\> Set-AzStorageBlobContent -File $filepath -Container "contosouploads" -Properties @{"ContentType" = [System.Web.MimeMapping]::GetMimeMapping($filepath); "ContentMD5" = "i727sP7HigloQDsqadNLHw=="} -StandardBlobTier Cool
@@ -110,6 +112,8 @@ This command gets ContentType value set to blob properties by [System.Web.MimeMa
110112

111113
### Example 7: Upload a file to a blob with Encryption Scope
112114
<!-- Skip: Output cannot be splitted from code -->
115+
116+
113117
```
114118
PS C:\> $blob = Set-AzStorageBlobContent -File "mylocalfile" -Container "mycontainer" -Blob "myblob" -EncryptionScope "myencryptscope"
115119
@@ -419,7 +423,6 @@ See detail in https://docs.microsoft.com/azure/storage/blobs/storage-blob-storag
419423
Type: System.String
420424
Parameter Sets: (All)
421425
Aliases:
422-
Accepted values: Hot, Cool, Archive
423426

424427
Required: False
425428
Position: Named
@@ -492,7 +495,7 @@ Accept wildcard characters: False
492495
```
493496
494497
### CommonParameters
495-
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).
498+
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).
496499
497500
## INPUTS
498501

src/Storage/Storage.Management/help/Start-AzStorageBlobCopy.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ The **Start-AzStorageBlobCopy** cmdlet starts to copy a blob.
123123

124124
### Example 1: Copy a named blob
125125
```
126-
C:\PS>Start-AzStorageBlobCopy -SrcBlob "ContosoPlanning2015" -DestContainer "ContosoArchives" -SrcContainer "ContosoUploads"
126+
Start-AzStorageBlobCopy -SrcBlob "ContosoPlanning2015" -DestContainer "ContosoArchives" -SrcContainer "ContosoUploads"
127127
```
128128

129129
This command starts the copy operation of the blob named ContosoPlanning2015 from the container named ContosoUploads to the container named ContosoArchives.
130130

131131
### Example 2: Get a container to specify blobs to copy
132132
```
133-
C:\PS>Get-AzStorageContainer -Name "ContosoUploads" | Start-AzStorageBlobCopy -SrcBlob "ContosoPlanning2015" -DestContainer "ContosoArchives"
133+
Get-AzStorageContainer -Name "ContosoUploads" | Start-AzStorageBlobCopy -SrcBlob "ContosoPlanning2015" -DestContainer "ContosoArchives"
134134
```
135135

136136
This command gets the container named ContosoUploads, by using the **Get-AzStorageContainer** cmdlet, and then passes the container to the current cmdlet by using the pipeline operator.
@@ -140,17 +140,17 @@ The *DestContainer* parameter specifies ContosoArchives as the destination conta
140140

141141
### Example 3: Get all blobs in a container and copy them
142142
```
143-
C:\PS>Get-AzStorageBlob -Container "ContosoUploads" | Start-AzStorageBlobCopy -DestContainer "ContosoArchives"
143+
Get-AzStorageBlob -Container "ContosoUploads" | Start-AzStorageBlobCopy -DestContainer "ContosoArchives"
144144
```
145145

146146
This command gets the blobs in the container named ContosoUploads, by using the **Get-AzStorageBlob** cmdlet, and then passes the results to the current cmdlet by using the pipeline operator.
147147
That cmdlet starts the copy operation of the blobs to the container named ContosoArchives.
148148

149149
### Example 4: Copy a blob specified as an object
150150
```
151-
C:\PS>$SrcBlob = Get-AzStorageBlob -Container "ContosoUploads" -Blob "ContosoPlanning2015"
152-
C:\PS> $DestBlob = Get-AzStorageBlob -Container "ContosoArchives" -Blob "ContosoPlanning2015Archived"
153-
C:\PS> Start-AzStorageBlobCopy -ICloudBlob $SrcBlob.ICloudBlob -DestICloudBlob $DestBlob.ICloudBlob
151+
$SrcBlob = Get-AzStorageBlob -Container "ContosoUploads" -Blob "ContosoPlanning2015"
152+
$DestBlob = Get-AzStorageBlob -Container "ContosoArchives" -Blob "ContosoPlanning2015Archived"
153+
Start-AzStorageBlobCopy -ICloudBlob $SrcBlob.ICloudBlob -DestICloudBlob $DestBlob.ICloudBlob
154154
```
155155

156156
The first command gets the blob named ContosoPlanning2015 in the container named ContosoUploads.
@@ -162,8 +162,8 @@ The command uses standard dot notation to specify the **ICloudBlob** objects for
162162

163163
### Example 5: Copy a blob from a URI
164164
```
165-
C:\PS>$Context = New-AzStorageContext -StorageAccountName "ContosoGeneral" -StorageAccountKey "< Storage Key for ContosoGeneral ends with == >"
166-
C:\PS> Start-AzStorageBlobCopy -AbsoluteUri "http://www.contosointernal.com/planning" -DestContainer "ContosoArchive" -DestBlob "ContosoPlanning2015" -DestContext $Context
165+
$Context = New-AzStorageContext -StorageAccountName "ContosoGeneral" -StorageAccountKey "< Storage Key for ContosoGeneral ends with == >"
166+
Start-AzStorageBlobCopy -AbsoluteUri "http://www.contosointernal.com/planning" -DestContainer "ContosoArchive" -DestBlob "ContosoPlanning2015" -DestContext $Context
167167
```
168168

169169
This command creates a context for the account named ContosoGeneral that uses the specified key, and then stores that key in the $Context variable.
@@ -173,7 +173,7 @@ There are no source storage context, so the source Uri must have access to the s
173173

174174
### Example 6: Copy a block blob to destination container with a new blob name, and set destination blob StandardBlobTier as Hot, RehydratePriority as High
175175
```
176-
C:\PS>Start-AzStorageBlobCopy -SrcContainer "ContosoUploads" -SrcBlob "BlockBlobName" -DestContainer "ContosoArchives" -DestBlob "NewBlockBlobName" -StandardBlobTier Hot -RehydratePriority High
176+
Start-AzStorageBlobCopy -SrcContainer "ContosoUploads" -SrcBlob "BlockBlobName" -DestContainer "ContosoArchives" -DestBlob "NewBlockBlobName" -StandardBlobTier Hot -RehydratePriority High
177177
```
178178

179179
This command starts the copy operation of a block blob to destination container with a new blob name, and set destination blob StandardBlobTier as Hot, RehydratePriority as High
@@ -614,7 +614,6 @@ See detail in https://docs.microsoft.com/azure/storage/blobs/storage-blob-storag
614614
Type: System.String
615615
Parameter Sets: (All)
616616
Aliases:
617-
Accepted values: Hot, Cool, Archive
618617

619618
Required: False
620619
Position: Named

src/Storage/Storage/Blob/Cmdlet/CopyAzureStorageBlob.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
1818
using Azure.Commands.Common.Authentication.Abstractions;
1919
using Commands.Common.Storage.ResourceModel;
2020
using global::Azure.Storage.Blobs;
21+
using global::Azure.Storage.Blobs.Models;
2122
using global::Azure.Storage.Blobs.Specialized;
2223
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
2324
using Microsoft.Azure.Storage.Blob;
@@ -99,28 +100,30 @@ public string SrcContainer
99100
public string DestBlobType { get; set; }
100101

101102
[Parameter(HelpMessage = "Block Blob Tier, valid values are Hot/Cool/Archive. See detail in https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers", Mandatory = false)]
103+
[ValidateNotNullOrEmpty]
102104
[PSArgumentCompleter("Hot", "Cool", "Archive")]
103-
[ValidateSet("Hot", "Cool", "Archive", IgnoreCase = true)]
104105
public string StandardBlobTier
105106
{
106107
get
107108
{
108-
return standardBlobTier is null ? null : standardBlobTier.Value.ToString();
109+
return accesstier?.ToString();
109110
}
110111

111112
set
112113
{
113114
if (value != null)
114115
{
115-
standardBlobTier = ((StandardBlobTier)Enum.Parse(typeof(StandardBlobTier), value, true));
116+
accesstier = new AccessTier(value);
117+
isBlockBlobAccessTier = true;
116118
}
117119
else
118120
{
119-
standardBlobTier = null;
121+
accesstier = null;
120122
}
121123
}
122124
}
123-
private StandardBlobTier? standardBlobTier = null;
125+
private bool? isBlockBlobAccessTier = null;
126+
private AccessTier? accesstier = null;
124127

125128
[Parameter(HelpMessage = "Block Blob RehydratePriority. Indicates the priority with which to rehydrate an archived blob. Valid values are High/Standard.", Mandatory = false)]
126129
[ValidateSet("Standard", "High", IgnoreCase = true)]
@@ -372,7 +375,11 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
372375

373376
if (destBlobType != null)
374377
{
375-
ValidateBlobTier(Util.convertBlobType_Track2ToTrack1(destBlobType), null, standardBlobTier, rehydratePriority);
378+
ValidateBlobTier(Util.convertBlobType_Track2ToTrack1(destBlobType), null, isBlockBlobAccessTier, rehydratePriority);
379+
if (this.rehydratePriority != null && this.accesstier == null)
380+
{
381+
throw new ArgumentException("RehydratePriority should only be specified when StandardBlobTier is specified.");
382+
}
376383
}
377384

378385
if (!destExist || this.ConfirmOverwrite(srcUri.AbsoluteUri.ToString(), destBlob.Uri.ToString()))
@@ -483,9 +490,9 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
483490
Track2Models.BlobCopyFromUriOptions options = new Track2Models.BlobCopyFromUriOptions();
484491

485492
// The Blob Type and Blob Tier must match, since already checked before
486-
if (standardBlobTier != null || rehydratePriority != null)
493+
if (accesstier != null || rehydratePriority != null)
487494
{
488-
options.AccessTier = Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier);
495+
options.AccessTier = accesstier;
489496
options.RehydratePriority = Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority);
490497
}
491498
options.SourceConditions = this.BlobRequestConditions;
@@ -495,10 +502,10 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
495502
destBlobClient.SyncCopyFromUri(srcUri, options, this.CmdletCancellationToken);
496503

497504
// Set rehydrate priority
498-
if (rehydratePriority != null)
505+
if (rehydratePriority != null && accesstier != null)
499506
{
500-
destBlobClient.SetAccessTier(Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier) == null ? null : (Track2Models.AccessTier)Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier),
501-
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
507+
destBlobClient.SetAccessTier(accesstier.Value,
508+
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
502509
}
503510
break;
504511
}
@@ -510,9 +517,9 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
510517
commitBlockListOptions.Metadata = srcProperties.Metadata;
511518
commitBlockListOptions.Tags = blobTags ?? null;
512519

513-
if (standardBlobTier != null)
520+
if (accesstier != null)
514521
{
515-
commitBlockListOptions.AccessTier = Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier);
522+
commitBlockListOptions.AccessTier = accesstier;
516523
}
517524

518525
long blockLength = GetBlockLength(srcProperties.ContentLength);
@@ -534,10 +541,10 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
534541
destBlockBlob.CommitBlockList(blockIDs, commitBlockListOptions, this.CmdletCancellationToken);
535542

536543
// Set rehydrate priority
537-
if (rehydratePriority != null)
544+
if (rehydratePriority != null && accesstier != null)
538545
{
539-
destBlockBlob.SetAccessTier(Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier) == null ? null : (Track2Models.AccessTier)Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier),
540-
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
546+
destBlockBlob.SetAccessTier(accesstier.Value,
547+
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
541548
}
542549
break;
543550
}

0 commit comments

Comments
 (0)