Skip to content

Commit

Permalink
[Storage] Refine Track2 file cmdlets migration (#26232)
Browse files Browse the repository at this point in the history
* temp

* temp2

* Move Track1 Blob reference in file copy cmdlet back; add context check for downloading file

* remove warning

* clean up

* update warning message when dest context is missing; update file and directory display format

* clean up code

* Update help files

* Update changelog

* Update file and directory output display
  • Loading branch information
yifanz7 authored Oct 12, 2024
1 parent 6a7f473 commit 68a4cfb
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 78 deletions.
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
* Refined migration of Azure Storgae File dataplane cmdlets from 'Microsoft.Azure.Storage.File 11.2.3' to 'Azure.Storage.Files.Shares 12.16.0'
- `Start-AzStorageFileCopy`

## Version 7.4.0
* Added a warning for an upcoming breaking change for removing references to "Microsoft.Azure.Storage.File"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ This command downloads a file that is named CurrentDataFile in the folder Contos

### Example 2: Downloads the files under sample file share
```powershell
Get-AzStorageFile -ShareName sample | Where-Object {$_.GetType().Name -eq "CloudFile"} | Get-AzStorageFileContent
Get-AzStorageFile -ShareName sample | Where-Object {$_.GetType().Name -eq "AzureStorageFile"} | Get-AzStorageFileContent
```

This example downloads the files under sample file share
Expand Down Expand Up @@ -282,7 +282,7 @@ Accept wildcard characters: False
```
### -ShareClient
CloudFileShare object indicated the share where the file would be downloaded.
ShareClient object indicated the share where the file would be downloaded.
```yaml
Type: Azure.Storage.Files.Shares.ShareClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ New-AzStorageDirectory [-ShareDirectoryClient] <ShareDirectoryClient> [-Path] <S

## DESCRIPTION
The **New-AzStorageDirectory** cmdlet creates a directory.
This cmdlet returns a **CloudFileDirectory** object.
This cmdlet returns a **AzureStorageFileDirectory** object.

## EXAMPLES

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Accept wildcard characters: False
```

### -ShareFileClient
CloudFile instance to represent the file to get SAS token against.
ShareFileClient instance to represent the file to get SAS token against.

```yaml
Type: Azure.Storage.Files.Shares.ShareFileClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Rename-AzStorageDirectory -ShareName myshare -SourcePath testdir1 -DestinationPa
```

```output
Directory: https://myaccount.file.core.windows.net/myshare
AccountName: myaccount, ShareName: myshare
Type Length Name
---- ------ ----
Expand All @@ -60,7 +60,7 @@ Get-AzStorageFile -ShareName myshare -Path testdir1 | Rename-AzStorageDirectory
```

```output
Directory: https://myaccount.file.core.windows.net/myshare
AccountName: myaccount, ShareName: myshare
Type Length Name
---- ------ ----
Expand Down
4 changes: 2 additions & 2 deletions src/Storage/Storage.Management/help/Rename-AzStorageFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Rename-AzStorageFile -SourcePath testfile1 -DestinationPath testfile2 -ShareName
```

```output
Directory: https://myaccount.file.core.windows.net/myshare
AccountName: myaccount, ShareName: myshare
Type Length Name
---- ------ ----
Expand All @@ -68,7 +68,7 @@ Get-AzStorageFile -ShareName myshare -Path testfile1 | Rename-AzStorageFile -Des
```

```output
Directory: https://myaccount.file.core.windows.net/myshare
AccountName: myaccount, ShareName: myshare
Type Length Name
---- ------ ----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Accept wildcard characters: False
```
### -ShareDirectoryClient
CloudFileDirectory object indicated the cloud directory where the file would be uploaded.
ShareDirectoryClient object indicated the directory where the file would be uploaded.
```yaml
Type: Azure.Storage.Files.Shares.ShareDirectoryClient
Expand Down
46 changes: 22 additions & 24 deletions src/Storage/Storage.Management/help/Start-AzStorageFileCopy.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,24 @@ Start-AzStorageFileCopy -SrcBlobName <String> -SrcContainerName <String> -DestSh

### ContainerInstance
```
Start-AzStorageFileCopy -SrcBlobName <String> -SrcContainer <BlobContainerClient> -DestShareName <String>
-DestFilePath <String> [-Context <IStorageContext>] [-DestContext <IStorageContext>] [-Force]
[-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [-WhatIf] [-Confirm]
[<CommonParameters>]
Start-AzStorageFileCopy -SrcBlobName <String> -SrcContainer <CloudBlobContainer> -DestShareName <String>
-DestFilePath <String> [-DestContext <IStorageContext>] [-Force] [-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### BlobInstanceFilePath
```
Start-AzStorageFileCopy -SrcBlob <BlobBaseClient> -DestShareName <String> -DestFilePath <String>
[-Context <IStorageContext>] [-DestContext <IStorageContext>] [-Force] [-ServerTimeoutPerRequest <Int32>]
Start-AzStorageFileCopy -SrcBlob <CloudBlob> -DestShareName <String> -DestFilePath <String>
[-DestContext <IStorageContext>] [-Force] [-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### BlobInstanceFileInstance
```
Start-AzStorageFileCopy -SrcBlob <BlobBaseClient> [-DestShareFileClient <ShareFileClient>]
[-Context <IStorageContext>] [-DestContext <IStorageContext>] [-Force] [-ServerTimeoutPerRequest <Int32>]
Start-AzStorageFileCopy -SrcBlob <CloudBlob> [-DestShareFileClient <ShareFileClient>]
[-DestContext <IStorageContext>] [-Force] [-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```
Expand All @@ -59,24 +58,23 @@ Start-AzStorageFileCopy -SrcFilePath <String> -SrcShareName <String> -DestShareN
### ShareInstance
```
Start-AzStorageFileCopy -SrcFilePath <String> -SrcShare <ShareClient> -DestShareName <String>
-DestFilePath <String> [-Context <IStorageContext>] [-DestContext <IStorageContext>] [-Force]
[-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [-WhatIf] [-Confirm]
[<CommonParameters>]
-DestFilePath <String> [-DestContext <IStorageContext>] [-Force] [-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### FileInstanceToFilePath
```
Start-AzStorageFileCopy -SrcFile <ShareFileClient> -DestShareName <String> -DestFilePath <String>
[-Context <IStorageContext>] [-DestContext <IStorageContext>] [-Force] [-ServerTimeoutPerRequest <Int32>]
[-DestContext <IStorageContext>] [-Force] [-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### FileInstanceToFileInstance
```
Start-AzStorageFileCopy -SrcFile <ShareFileClient> [-DestShareFileClient <ShareFileClient>]
[-Context <IStorageContext>] [-DestContext <IStorageContext>] [-Force] [-ServerTimeoutPerRequest <Int32>]
[-DestContext <IStorageContext>] [-Force] [-ServerTimeoutPerRequest <Int32>]
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```
Expand Down Expand Up @@ -179,7 +177,7 @@ To obtain a context, use the New-AzStorageContext cmdlet.
```yaml
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext
Parameter Sets: ContainerName, ContainerInstance, BlobInstanceFilePath, BlobInstanceFileInstance, ShareName, ShareInstance, FileInstanceToFilePath, FileInstanceToFileInstance
Parameter Sets: ContainerName, ShareName
Aliases: SrcContext

Required: False
Expand Down Expand Up @@ -241,7 +239,7 @@ ShareFileClient object indicated the Dest file.
```yaml
Type: Azure.Storage.Files.Shares.ShareFileClient
Parameter Sets: BlobInstanceFileInstance, FileInstanceToFileInstance, UriToFileInstance
Aliases:
Aliases: DestFile

Required: False
Position: Named
Expand Down Expand Up @@ -330,9 +328,9 @@ Specifies a **CloudBlob** object.
You can create a cloud blob or obtain one by using the Get-AzStorageBlob cmdlet.
```yaml
Type: Azure.Storage.Blobs.Specialized.BlobBaseClient
Type: Microsoft.Azure.Storage.Blob.CloudBlob
Parameter Sets: BlobInstanceFilePath, BlobInstanceFileInstance
Aliases: BlobBaseClient
Aliases: ICloudBlob

Required: True
Position: Named
Expand Down Expand Up @@ -361,9 +359,9 @@ Specifies a cloud blob container object.
You can create cloud blob container object or use the Get-AzStorageContainer cmdlet.
```yaml
Type: Azure.Storage.Blobs.BlobContainerClient
Type: Microsoft.Azure.Storage.Blob.CloudBlobContainer
Parameter Sets: ContainerInstance
Aliases: BlobContainerClient
Aliases:

Required: True
Position: Named
Expand All @@ -388,8 +386,8 @@ Accept wildcard characters: False
```
### -SrcFile
Specifies a **CloudFile** object.
You can create a cloud file or obtain one by using **Get-AzStorageFile**.
Specifies a **ShareFileClient** object.
You can create a ShareFileClient or obtain one by using **Get-AzStorageFile**.
```yaml
Type: Azure.Storage.Files.Shares.ShareFileClient
Expand Down Expand Up @@ -485,7 +483,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## INPUTS
### Azure.Storage.Blobs.Specialized.BlobBaseClient
### Microsoft.Azure.Storage.Blob.CloudBlob
### Azure.Storage.Files.Shares.ShareFileClient
Expand Down
11 changes: 9 additions & 2 deletions src/Storage/Storage/Common/StorageCloudCmdletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ internal AzureStorageContext GetCmdletStorageContext(bool outputErrorMessage = t
return context;
}

internal AzureStorageContext GetCmdletStorageContext(IStorageContext inContext, bool outputErrorMessage = true)
internal AzureStorageContext GetCmdletStorageContext(IStorageContext inContext, bool outputErrorMessage = true, bool isDestContext = false)
{
var context = inContext as AzureStorageContext;

Expand Down Expand Up @@ -304,8 +304,15 @@ internal AzureStorageContext GetCmdletStorageContext(IStorageContext inContext,
}
else
{
throw new InvalidOperationException("Could not get the storage context. Please pass in a storage context with \"-Context\" parameter (can be created with New-AzStorageContext cmdlet), " +
if (isDestContext)
{
throw new InvalidOperationException("Could not get the destination storage context. Please pass in a storage context with \"-DestContext\" parameter (can be created with New-AzStorageContext cmdlet).");
}
else
{
throw new InvalidOperationException("Could not get the storage context. Please pass in a storage context with \"-Context\" parameter (can be created with New-AzStorageContext cmdlet), " +
"or set the current storage context with Set-AzCurrentStorageAccount cmdlet.");
}
}
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public override void ExecuteCmdlet()
string[] path = NamingUtil.ValidatePath(this.Path, true);
switch (this.ParameterSetName)
{
case LocalConstants.FileParameterSetName:
case LocalConstants.FileParameterSetName:
CheckContextForObjectInput((AzureStorageContext)this.Context);
fileClientToBeDownloaded = this.ShareFileClient;
fileToBeDownloaded = AzureStorageFile.GetTrack1FileClient(fileClientToBeDownloaded, ((AzureStorageContext)this.Context).StorageAccount.Credentials);
break;
Expand All @@ -164,11 +165,13 @@ public override void ExecuteCmdlet()
break;

case LocalConstants.ShareParameterSetName:
CheckContextForObjectInput((AzureStorageContext)this.Context);
fileClientToBeDownloaded = this.ShareClient.GetRootDirectoryClient().GetFileClient(this.Path);
fileToBeDownloaded = AzureStorageFile.GetTrack1FileClient(fileClientToBeDownloaded, ((AzureStorageContext)this.Context).StorageAccount.Credentials);
break;

case LocalConstants.DirectoryParameterSetName:
CheckContextForObjectInput((AzureStorageContext)this.Context);
fileClientToBeDownloaded = this.ShareDirectoryClient.GetFileClient(this.Path);
fileToBeDownloaded = AzureStorageFile.GetTrack1FileClient(fileClientToBeDownloaded, ((AzureStorageContext)this.Context).StorageAccount.Credentials);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override void ExecuteCmdlet()

if (Channel.StorageContext != null && Channel.StorageContext.StorageAccount != null && !Channel.StorageContext.StorageAccount.Credentials.IsSharedKey)
{
throw new InvalidOperationException("Create File service SAS only supported with SharedKey credentail.");
throw new InvalidOperationException("Create File service SAS only supported with SharedKey credential.");
}

ShareClient share = Util.GetTrack2ShareReference(this.ShareName,
Expand Down
2 changes: 0 additions & 2 deletions src/Storage/Storage/File/Cmdlet/SetAzureStorageShareQuota.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
using System.Globalization;
using System.Management.Automation;
using System.Security.Permissions;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel;
using Azure.Storage.Files.Shares;
using Azure.Storage.Files.Shares.Models;
using System;

namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet
{
Expand Down
Loading

0 comments on commit 68a4cfb

Please sign in to comment.