Skip to content

[Storage Dataplane] - Remove Validation Set and move to track2 SDK for accesstier #20554

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 2 commits into from
Jan 18, 2023
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
8 changes: 6 additions & 2 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
- Additional information about change #1
-->
## Upcoming Release
* Removed the ValidateSet of StandardBlobTier parameter
- `Copy-AzStorageBlob`
- `Set-AzStorageBlobContent`
- `Start-AzStorageBlobCopy`

## Version 5.3.0
* Return ListBlobProperties in blob list result
* Returned ListBlobProperties in blob list result
- `Get-AzStorageBlob`
* Output AllowedCopyScope in get account result
* Returned AllowedCopyScope in get account result
- `Get-AzStorageAccount`

## Version 5.2.0
Expand Down
19 changes: 9 additions & 10 deletions src/Storage/Storage.Management/help/Copy-AzStorageBlob.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,38 @@ The **Copy-AzStorageBlob** cmdlet copies a blob synchronously, currently only su

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

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

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

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

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

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.

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

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

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

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

Required: False
Position: Named
Expand Down
19 changes: 11 additions & 8 deletions src/Storage/Storage.Management/help/Set-AzStorageBlobContent.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ The **Set-AzStorageBlobContent** cmdlet uploads a local file to an Azure Storage

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

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

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

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.
The **Set-AzStorageBlobContent** cmdlet uploads the files to the container named ContosoUploads.

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

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.
Expand All @@ -76,16 +76,16 @@ If you confirm the command, the cmdlet overwrites the existing blob.

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

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.
The command uploads the file that is named ContosoPlanning as Planning2015.

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

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

### Example 6: Upload a file to blob with specified blob properties, and set StandardBlobTier as Cool
<!-- Skip: Output cannot be splitted from code -->


```
PS C:\> $filepath = "c:\temp\index.html"
PS C:\> Set-AzStorageBlobContent -File $filepath -Container "contosouploads" -Properties @{"ContentType" = [System.Web.MimeMapping]::GetMimeMapping($filepath); "ContentMD5" = "i727sP7HigloQDsqadNLHw=="} -StandardBlobTier Cool
Expand All @@ -110,6 +112,8 @@ This command gets ContentType value set to blob properties by [System.Web.MimeMa

### Example 7: Upload a file to a blob with Encryption Scope
<!-- Skip: Output cannot be splitted from code -->


```
PS C:\> $blob = Set-AzStorageBlobContent -File "mylocalfile" -Container "mycontainer" -Blob "myblob" -EncryptionScope "myencryptscope"

Expand Down Expand Up @@ -419,7 +423,6 @@ See detail in https://docs.microsoft.com/azure/storage/blobs/storage-blob-storag
Type: System.String
Parameter Sets: (All)
Aliases:
Accepted values: Hot, Cool, Archive

Required: False
Position: Named
Expand Down Expand Up @@ -492,7 +495,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
19 changes: 9 additions & 10 deletions src/Storage/Storage.Management/help/Start-AzStorageBlobCopy.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ The **Start-AzStorageBlobCopy** cmdlet starts to copy a blob.

### Example 1: Copy a named blob
```
C:\PS>Start-AzStorageBlobCopy -SrcBlob "ContosoPlanning2015" -DestContainer "ContosoArchives" -SrcContainer "ContosoUploads"
Start-AzStorageBlobCopy -SrcBlob "ContosoPlanning2015" -DestContainer "ContosoArchives" -SrcContainer "ContosoUploads"
```

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

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

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.
Expand All @@ -140,17 +140,17 @@ The *DestContainer* parameter specifies ContosoArchives as the destination conta

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

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.
That cmdlet starts the copy operation of the blobs to the container named ContosoArchives.

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

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

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

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

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

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
Expand Down Expand Up @@ -614,7 +614,6 @@ See detail in https://docs.microsoft.com/azure/storage/blobs/storage-blob-storag
Type: System.String
Parameter Sets: (All)
Aliases:
Accepted values: Hot, Cool, Archive

Required: False
Position: Named
Expand Down
39 changes: 23 additions & 16 deletions src/Storage/Storage/Blob/Cmdlet/CopyAzureStorageBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
using Azure.Commands.Common.Authentication.Abstractions;
using Commands.Common.Storage.ResourceModel;
using global::Azure.Storage.Blobs;
using global::Azure.Storage.Blobs.Models;
using global::Azure.Storage.Blobs.Specialized;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Storage.Blob;
Expand Down Expand Up @@ -99,28 +100,30 @@ public string SrcContainer
public string DestBlobType { get; set; }

[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)]
[ValidateNotNullOrEmpty]
[PSArgumentCompleter("Hot", "Cool", "Archive")]
[ValidateSet("Hot", "Cool", "Archive", IgnoreCase = true)]
public string StandardBlobTier
{
get
{
return standardBlobTier is null ? null : standardBlobTier.Value.ToString();
return accesstier?.ToString();
}

set
{
if (value != null)
{
standardBlobTier = ((StandardBlobTier)Enum.Parse(typeof(StandardBlobTier), value, true));
accesstier = new AccessTier(value);
isBlockBlobAccessTier = true;
}
else
{
standardBlobTier = null;
accesstier = null;
}
}
}
private StandardBlobTier? standardBlobTier = null;
private bool? isBlockBlobAccessTier = null;
private AccessTier? accesstier = null;

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

if (destBlobType != null)
{
ValidateBlobTier(Util.convertBlobType_Track2ToTrack1(destBlobType), null, standardBlobTier, rehydratePriority);
ValidateBlobTier(Util.convertBlobType_Track2ToTrack1(destBlobType), null, isBlockBlobAccessTier, rehydratePriority);
if (this.rehydratePriority != null && this.accesstier == null)
{
throw new ArgumentException("RehydratePriority should only be specified when StandardBlobTier is specified.");
}
}

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

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

// Set rehydrate priority
if (rehydratePriority != null)
if (rehydratePriority != null && accesstier != null)
{
destBlobClient.SetAccessTier(Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier) == null ? null : (Track2Models.AccessTier)Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier),
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
destBlobClient.SetAccessTier(accesstier.Value,
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
}
break;
}
Expand All @@ -510,9 +517,9 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
commitBlockListOptions.Metadata = srcProperties.Metadata;
commitBlockListOptions.Tags = blobTags ?? null;

if (standardBlobTier != null)
if (accesstier != null)
{
commitBlockListOptions.AccessTier = Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier);
commitBlockListOptions.AccessTier = accesstier;
}

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

// Set rehydrate priority
if (rehydratePriority != null)
if (rehydratePriority != null && accesstier != null)
{
destBlockBlob.SetAccessTier(Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier) == null ? null : (Track2Models.AccessTier)Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier),
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
destBlockBlob.SetAccessTier(accesstier.Value,
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
}
break;
}
Expand Down
Loading