Skip to content

Commit 3b5d5f6

Browse files
committed
Merge pull request #4 from dscsolutions/storage-suffix
Fix Storage Endpoint Suffix
2 parents 817d3e0 + 7c8f76c commit 3b5d5f6

File tree

6 files changed

+114
-38
lines changed

6 files changed

+114
-38
lines changed

src/ResourceManager/Compute/Commands.Compute/Extension/DSC/PublishAzureVMDscConfigurationCommand.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO.Compression;
66
using System.Linq;
77
using System.Management.Automation;
8+
using Microsoft.Azure.Common.Authentication.Models;
89
using Microsoft.Azure.Commands.Compute.Common;
910
using Microsoft.WindowsAzure.Storage;
1011
using Microsoft.WindowsAzure.Storage.Auth;
@@ -89,6 +90,16 @@ public class PublishAzureVMDscConfigurationCommand : VirtualMachineDscExtensionB
8990
[ValidateNotNullOrEmpty]
9091
public string OutputArchivePath { get; set; }
9192

93+
/// <summary>
94+
/// Suffix for the storage end point, e.g. core.windows.net
95+
/// </summary>
96+
[Parameter(
97+
ValueFromPipelineByPropertyName = true,
98+
ParameterSetName = UploadArchiveParameterSetName,
99+
HelpMessage = "Suffix for the storage end point, e.g. core.windows.net")]
100+
[ValidateNotNullOrEmpty]
101+
public string StorageEndpointSuffix { get; set; }
102+
92103
/// <summary>
93104
/// By default Publish-AzureVMDscConfiguration will not overwrite any existing blobs.
94105
/// Use -Force to overwrite them.
@@ -204,6 +215,10 @@ protected void ValidateParameters()
204215
{
205216
ContainerName = DefaultContainerName;
206217
}
218+
if (this.StorageEndpointSuffix == null)
219+
{
220+
this.StorageEndpointSuffix = Profile.Context.Environment.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix);
221+
}
207222
}
208223
else if (ParameterSetName == CreateArchiveParameterSetName)
209224
{
@@ -384,7 +399,7 @@ private void UploadConfigurationArchive(string archivePath)
384399

385400
private CloudBlobContainer GetStorageContainer()
386401
{
387-
var storageAccount = new CloudStorageAccount(_storageCredentials, true);
402+
var storageAccount = new CloudStorageAccount(_storageCredentials, this.StorageEndpointSuffix, true);
388403
var blobClient = storageAccount.CreateCloudBlobClient();
389404
CloudBlobContainer containerReference = blobClient.GetContainerReference(ContainerName);
390405
containerReference.CreateIfNotExists();

src/ResourceManager/Compute/Commands.Compute/Extension/DSC/SetAzureVMDscExtensionCommand.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Management.Automation;
66
using System.Text.RegularExpressions;
77
using AutoMapper;
8+
using Microsoft.Azure.Common.Authentication.Models;
89
using Microsoft.Azure.Commands.Compute.Common;
910
using Microsoft.Azure.Commands.Compute.Models;
1011
using Microsoft.Azure.Management.Compute;
@@ -257,6 +258,11 @@ private void ValidateParameters()
257258
ArchiveContainerName = DefaultContainerName;
258259
}
259260

261+
if (this.ArchiveStorageEndpointSuffix == null)
262+
{
263+
this.ArchiveStorageEndpointSuffix = Profile.Context.Environment.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix);
264+
}
265+
260266
if (!(Regex.Match(Version, VersionRegexExpr).Success))
261267
{
262268
ThrowInvalidArgumentError(Properties.Resources.AzureVMDscExtensionInvalidVersion);
@@ -335,12 +341,7 @@ private ConfigurationUris UploadConfigurationDataToBlob()
335341
//
336342
// Get a reference to the container in blob storage
337343
//
338-
var storageAccount = string.IsNullOrEmpty(ArchiveStorageEndpointSuffix)
339-
? new CloudStorageAccount(_storageCredentials, true)
340-
: new CloudStorageAccount(
341-
_storageCredentials,
342-
ArchiveStorageEndpointSuffix,
343-
true);
344+
var storageAccount = new CloudStorageAccount(_storageCredentials, ArchiveStorageEndpointSuffix, true);
344345

345346
var blobClient = storageAccount.CreateCloudBlobClient();
346347

@@ -367,28 +368,28 @@ private ConfigurationUris UploadConfigurationDataToBlob()
367368

368369
if (ConfigurationData != null)
369370
{
371+
var guid = Guid.NewGuid();
372+
// there may be multiple VMs using the same configuration
373+
374+
var configurationDataBlobName = string.Format(
375+
CultureInfo.InvariantCulture,
376+
"{0}-{1}.psd1",
377+
ConfigurationName,
378+
guid);
379+
380+
var configurationDataBlobReference =
381+
containerReference.GetBlockBlobReference(configurationDataBlobName);
382+
370383
ConfirmAction(
371384
true,
372385
string.Empty,
373386
string.Format(
374387
CultureInfo.CurrentUICulture,
375388
Properties.Resources.AzureVMDscUploadToBlobStorageAction,
376389
ConfigurationData),
377-
configurationBlobReference.Uri.AbsoluteUri,
390+
configurationDataBlobReference.Uri.AbsoluteUri,
378391
() =>
379392
{
380-
var guid = Guid.NewGuid();
381-
// there may be multiple VMs using the same configuration
382-
383-
var configurationDataBlobName = string.Format(
384-
CultureInfo.InvariantCulture,
385-
"{0}-{1}.psd1",
386-
ConfigurationName,
387-
guid);
388-
389-
var configurationDataBlobReference =
390-
containerReference.GetBlockBlobReference(configurationDataBlobName);
391-
392393
if (!Force && configurationDataBlobReference.Exists())
393394
{
394395
ThrowTerminatingError(

src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.dll-Help.xml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,14 @@ $ext = Get-AzureVMCustomScriptExtension -ResourceGroupName $rgname -VMName $vmna
30763076
</maml:description>
30773077
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
30783078
</command:parameter>
3079-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
3079+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
3080+
<maml:name>StorageEndpointSuffix</maml:name>
3081+
<maml:description>
3082+
<maml:para>Suffix for the storage end point, e.g. core.windows.net</maml:para>
3083+
</maml:description>
3084+
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
3085+
</command:parameter>
3086+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
30803087
<maml:name>WhatIf</maml:name>
30813088
<maml:description>
30823089
<maml:para>Describes what would happen if you executed the command without actually executing the command.</maml:para>
@@ -3187,7 +3194,20 @@ When this parameter is used, the configuration script is not uploaded to Azure b
31873194
</dev:type>
31883195
<dev:defaultValue></dev:defaultValue>
31893196
</command:parameter>
3190-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
3197+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
3198+
<maml:name>StorageEndpointSuffix</maml:name>
3199+
<maml:description>
3200+
<maml:para>Suffix for the storage end point, e.g. core.windows.net</maml:para>
3201+
3202+
</maml:description>
3203+
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
3204+
<dev:type>
3205+
<maml:name>string</maml:name>
3206+
<maml:uri/>
3207+
</dev:type>
3208+
<dev:defaultValue></dev:defaultValue>
3209+
</command:parameter>
3210+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
31913211
<maml:name>WhatIf</maml:name>
31923212
<maml:description>
31933213
<maml:para>Describes what would happen if you executed the command without actually executing the command.</maml:para>

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/DSC/PublishAzureVMDscConfiguration.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.IO;
1919
using System.Linq;
2020
using System.Management.Automation;
21+
using Microsoft.Azure.Common.Authentication.Models;
2122
using Microsoft.WindowsAzure.Commands.Common.Storage;
2223
using Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions.DSC;
2324
using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
@@ -93,6 +94,16 @@ public class PublishAzureVMDscConfigurationCommand : ServiceManagementBaseCmdlet
9394
[ValidateNotNullOrEmpty]
9495
public string ConfigurationArchivePath { get; set; }
9596

97+
/// <summary>
98+
/// Suffix for the storage end point, e.g. core.windows.net
99+
/// </summary>
100+
[Parameter(
101+
ValueFromPipelineByPropertyName = true,
102+
ParameterSetName = UploadArchiveParameterSetName,
103+
HelpMessage = "Suffix for the storage end point, e.g. core.windows.net")]
104+
[ValidateNotNullOrEmpty]
105+
public string StorageEndpointSuffix { get; set; }
106+
96107
/// <summary>
97108
/// Credentials used to access Azure Storage
98109
/// </summary>
@@ -203,6 +214,10 @@ protected void ValidateParameters()
203214
{
204215
this.ContainerName = VirtualMachineDscExtensionCmdletBase.DefaultContainerName;
205216
}
217+
if (this.StorageEndpointSuffix == null)
218+
{
219+
this.StorageEndpointSuffix = Profile.Context.Environment.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix);
220+
}
206221
}
207222
else if (this.ParameterSetName == CreateArchiveParameterSetName)
208223
{
@@ -380,7 +395,7 @@ private void UploadConfigurationArchive(string archivePath)
380395

381396
private CloudBlobContainer GetStorageContainer()
382397
{
383-
var storageAccount = new CloudStorageAccount(this._storageCredentials, true);
398+
var storageAccount = new CloudStorageAccount(this._storageCredentials, this.StorageEndpointSuffix, true);
384399
var blobClient = storageAccount.CreateCloudBlobClient();
385400
CloudBlobContainer containerReference = blobClient.GetContainerReference(this.ContainerName);
386401
containerReference.CreateIfNotExists();

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/DSC/SetAzureVMDscExtension.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Globalization;
2020
using System.IO;
2121
using System.Management.Automation;
22+
using Microsoft.Azure.Common.Authentication.Models;
2223
using Microsoft.WindowsAzure.Commands.Common.Storage;
2324
using Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions.DSC;
2425
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
@@ -231,6 +232,11 @@ protected override void ValidateParameters()
231232
{
232233
this.ContainerName = DefaultContainerName;
233234
}
235+
236+
if (this.StorageEndpointSuffix == null)
237+
{
238+
this.StorageEndpointSuffix = Profile.Context.Environment.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix);
239+
}
234240
}
235241

236242
if (this.Version == null)
@@ -285,28 +291,28 @@ private ConfigurationUris UploadConfigurationDataToBlob()
285291

286292
if (this.ConfigurationDataPath != null)
287293
{
294+
var guid = Guid.NewGuid();
295+
// there may be multiple VMs using the same configuration
296+
297+
var configurationDataBlobName = string.Format(
298+
CultureInfo.InvariantCulture,
299+
"{0}-{1}.psd1",
300+
this.ConfigurationName,
301+
guid);
302+
303+
var configurationDataBlobReference =
304+
containerReference.GetBlockBlobReference(configurationDataBlobName);
305+
288306
this.ConfirmAction(
289307
true,
290308
string.Empty,
291309
string.Format(
292310
CultureInfo.CurrentUICulture,
293311
Resources.AzureVMDscUploadToBlobStorageAction,
294312
this.ConfigurationDataPath),
295-
configurationBlobReference.Uri.AbsoluteUri,
313+
configurationDataBlobReference.Uri.AbsoluteUri,
296314
() =>
297315
{
298-
var guid = Guid.NewGuid();
299-
// there may be multiple VMs using the same configuration
300-
301-
var configurationDataBlobName = string.Format(
302-
CultureInfo.InvariantCulture,
303-
"{0}-{1}.psd1",
304-
this.ConfigurationName,
305-
guid);
306-
307-
var configurationDataBlobReference =
308-
containerReference.GetBlockBlobReference(configurationDataBlobName);
309-
310316
if (!this.Force && configurationDataBlobReference.Exists())
311317
{
312318
this.ThrowTerminatingError(

src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17456,7 +17456,14 @@ New-AzureDeployment -ServiceName $cloudSvc -Slot Production -Package $pkg -Confi
1745617456
</maml:description>
1745717457
<command:parameterValue required="true" variableLength="false">AzureStorageContext</command:parameterValue>
1745817458
</command:parameter>
17459-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
17459+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
17460+
<maml:name>StorageEndpointSuffix</maml:name>
17461+
<maml:description>
17462+
<maml:para>Suffix for the storage end point, e.g. core.windows.net</maml:para>
17463+
</maml:description>
17464+
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
17465+
</command:parameter>
17466+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
1746017467
<maml:name>WhatIf</maml:name>
1746117468
<maml:description>
1746217469
<maml:para>Describes what would happen if you executed the command without actually executing the command.</maml:para>
@@ -17560,7 +17567,19 @@ When this parameter is used, the configuration script is not uploaded to Azure b
1756017567
</dev:type>
1756117568
<dev:defaultValue></dev:defaultValue>
1756217569
</command:parameter>
17563-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
17570+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
17571+
<maml:name>StorageEndpointSuffix</maml:name>
17572+
<maml:description>
17573+
<maml:para>Suffix for the storage end point, e.g. core.windows.net</maml:para>
17574+
</maml:description>
17575+
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
17576+
<dev:type>
17577+
<maml:name>string</maml:name>
17578+
<maml:uri/>
17579+
</dev:type>
17580+
<dev:defaultValue></dev:defaultValue>
17581+
</command:parameter>
17582+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
1756417583
<maml:name>WhatIf</maml:name>
1756517584
<maml:description>
1756617585
<maml:para>Describes what would happen if you executed the command without actually executing the command.</maml:para>

0 commit comments

Comments
 (0)