Skip to content

Commit 246f648

Browse files
committed
Fix issues
1 parent 9336bc7 commit 246f648

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlobContent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ internal void GetBlobContent(CloudBlobContainer container, string blobName, stri
281281

282282
private bool IsSasTokenWithOAuth(CloudBlobContainer container)
283283
{
284-
if (container.ServiceClient.Credentials.IsSAS) //SAS
284+
if (container != null && container.ServiceClient != null && container.ServiceClient.Credentials != null && container.ServiceClient.Credentials.IsSAS) //SAS
285285
{
286-
if (Channel.StorageContext.Track2OauthToken != null)
286+
if (Channel.StorageContext != null && Channel.StorageContext.Track2OauthToken != null)
287287
{
288288
return true;
289289
}

src/Storage/Storage/DatalakeGen2/Cmdlet/GetAzDataLakeGen2FileContent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public override void ExecuteCmdlet()
323323
throw new ArgumentException(String.Format("The input FileSystem '{0}', path '{1}' point to a Directory, can't download it.", this.FileSystem, this.Path));
324324
}
325325

326-
if (Channel.StorageContext.Track2OauthToken != null)
326+
if (Channel != null && Channel.StorageContext != null &&Channel.StorageContext.Track2OauthToken != null)
327327
{
328328
var blobServiceClient = Channel.GetBlobServiceClient();
329329
track2Blob = blobServiceClient.GetBlobContainerClient(this.FileSystem).GetBlockBlobClient(this.Path);
@@ -342,7 +342,7 @@ public override void ExecuteCmdlet()
342342
Channel.StorageContext.StorageAccount.Credentials != null && Channel.StorageContext.StorageAccount.Credentials.IsSAS)
343343
{
344344
// For SAS, the Uri already contains the sas token, so can't repeatedly inout the credential
345-
if (Channel.StorageContext.Track2OauthToken != null)
345+
if (Channel != null && Channel.StorageContext != null && Channel.StorageContext.Track2OauthToken != null)
346346
{
347347
track2Blob = new BlockBlobClient(InputObject.File.Uri, Channel.StorageContext.Track2OauthToken);
348348
}

src/Storage/Storage/File/Cmdlet/SetAzureStorageFileContent.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ public override void ExecuteCmdlet()
136136
bool isDirectory;
137137
string[] path = NamingUtil.ValidatePath(this.Path, out isDirectory);
138138

139-
var cloudFileToBeUploaded =
140-
BuildCloudFileInstanceFromPathAsync(localFile.Name, path, isDirectory).ConfigureAwait(false).GetAwaiter().GetResult();
141139
var fileClientToBeUploaded = BuildShareFileClientInstanceFromPathAsync(localFile.Name, path, isDirectory).ConfigureAwait(false).GetAwaiter().GetResult();
142140

143141

@@ -147,7 +145,9 @@ public override void ExecuteCmdlet()
147145
&& !WithOauthCredential()
148146
&& (this.DisAllowTrailingDot.IsPresent || !Util.PathContainsTrailingDot(fileClientToBeUploaded.Path))
149147
&& this.FileMode == null && this.Owner == null && this.Group == null)
150-
{
148+
{
149+
var cloudFileToBeUploaded =
150+
BuildCloudFileInstanceFromPathAsync(localFile.Name, path, isDirectory).ConfigureAwait(false).GetAwaiter().GetResult();
151151
if (ShouldProcess(cloudFileToBeUploaded.Name, "Set file content"))
152152
{
153153
var progressRecord = new ProgressRecord(
@@ -179,7 +179,6 @@ await DataMovementTransferHelper.DoTransfer(() =>
179179
}
180180
else // use Track2 SDK
181181
{
182-
183182
if (ShouldProcess(fileClientToBeUploaded.Path, "Set file content"))
184183
{
185184
var progressRecord = new ProgressRecord(

src/Storage/Storage/Model/Contract/StorageBlobManagement.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@
1414

1515
namespace Microsoft.WindowsAzure.Commands.Storage.Model.Contract
1616
{
17-
using Microsoft.WindowsAzure.Commands.Common.Storage;
18-
using Microsoft.WindowsAzure.Commands.Storage.Common;
17+
using global::Azure.Storage;
18+
using global::Azure.Storage.Blobs;
19+
using Microsoft.Azure.Cosmos.Table;
1920
using Microsoft.Azure.Storage;
20-
using XSCL = Microsoft.Azure.Storage;
2121
using Microsoft.Azure.Storage.Blob;
2222
using Microsoft.Azure.Storage.File;
2323
using Microsoft.Azure.Storage.File.Protocol;
2424
using Microsoft.Azure.Storage.Queue;
25-
using XSCLProtocol = Microsoft.Azure.Storage.Shared.Protocol;
26-
using XTable = Microsoft.Azure.Cosmos.Table;
27-
using Microsoft.Azure.Cosmos.Table;
25+
using Microsoft.OData.UriParser;
26+
using Microsoft.WindowsAzure.Commands.Common.Storage;
27+
using Microsoft.WindowsAzure.Commands.Storage.Common;
2828
using System;
2929
using System.Collections.Generic;
3030
using System.Threading;
3131
using System.Threading.Tasks;
32-
using global::Azure.Storage.Blobs;
33-
using global::Azure.Storage;
32+
using XSCL = Microsoft.Azure.Storage;
33+
using XSCLProtocol = Microsoft.Azure.Storage.Shared.Protocol;
34+
using XTable = Microsoft.Azure.Cosmos.Table;
3435

3536
/// <summary>
3637
/// Blob management
@@ -183,13 +184,24 @@ public BlobServiceClient GetBlobServiceClient(BlobClientOptions options = null)
183184
}
184185
else //sas, Anonymous
185186
{
187+
string blobEndpointWithSas = this.StorageContext.StorageAccount.BlobEndpoint.ToString();
188+
if (this.StorageContext.StorageAccount.Credentials.SASToken != null)
189+
{
190+
string sasToken = this.StorageContext.StorageAccount.Credentials.SASToken;
191+
if (!string.IsNullOrEmpty(sasToken) && !sasToken.StartsWith("?"))
192+
{
193+
sasToken = "?" + sasToken;
194+
}
195+
blobEndpointWithSas += sasToken;
196+
}
197+
186198
if (this.StorageContext != null && this.StorageContext.Track2OauthToken != null)
187199
{
188-
blobServiceClient = new BlobServiceClient(this.StorageContext.StorageAccount.BlobEndpoint, this.StorageContext.Track2OauthToken, options);
200+
blobServiceClient = new BlobServiceClient(new Uri(blobEndpointWithSas), this.StorageContext.Track2OauthToken, options);
189201
}
190202
else
191203
{
192-
blobServiceClient = new BlobServiceClient(this.StorageContext.StorageAccount.BlobEndpoint, options);
204+
blobServiceClient = new BlobServiceClient(new Uri(blobEndpointWithSas), options);
193205
}
194206
}
195207
}

0 commit comments

Comments
 (0)