Skip to content
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

add param to Add-AzVhd, and New-AzHostGroup #18333

Merged
merged 24 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
628767c
add -DataAccessAuthMode to Snaptshot/Disk config/updateConfig
grizzlytheodore Apr 26, 2022
b0c2ae1
trying DataAuth in Add-AzVhd
grizzlytheodore Apr 27, 2022
bb16431
progress save for Add-AzVhd
grizzlytheodore May 11, 2022
54291b6
updates to cmdlets
grizzlytheodore May 11, 2022
bb5b551
fix NewGalleryImage instead of update, add md files, update changelog
grizzlytheodore May 11, 2022
aef5121
update last md
grizzlytheodore May 11, 2022
558edab
remove add-azvhd stuff
grizzlytheodore May 12, 2022
d0772ff
md files
grizzlytheodore May 12, 2022
1ce0fc1
Merge branch 'feature/cplat-arm64' into feature/cplat-dataAuthAccess
grizzlytheodore May 12, 2022
b436af7
add update for Add-AzVhd DataAccessAuthMode
May 28, 2022
6d06364
resolve readme
May 28, 2022
16257dd
add veryEarly's comments
May 31, 2022
1b02816
update
Jun 9, 2022
fe517ac
update sdk package to 55.0.0
Jun 9, 2022
4692130
add -enableUltraSSD to New-AzHostGroup
Jun 9, 2022
d52ccc7
update token. removing uneccesary "authorizerequest"
Jun 10, 2022
f3ded60
suppress nonbreaking change
Jun 13, 2022
f745a5b
Update ChangeLog.md
VeryEarly Jun 15, 2022
40c8941
a
Jun 15, 2022
c5f7994
Merge branch 'main' into feature/cplat-dataAuthAccess
Jun 15, 2022
7b31258
Merge branch 'feature/cplat-dataAuthAccess' of https://github.com/Azu…
Jun 15, 2022
eef7f63
update to resolve failing tests. small object updated from swagger to…
Jun 16, 2022
4f1cb1e
Update Compute.Automation.generated.format.ps1xml
grizzlytheodore Jun 16, 2022
1381282
Update ResourceSkuListMethod.cs
grizzlytheodore Jun 16, 2022
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
5 changes: 3 additions & 2 deletions src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Text;
using Azure.Storage.Blobs.Specialized;
using System.IO;
using Azure.Core;

namespace Microsoft.Azure.Commands.Compute
{
Expand All @@ -28,9 +29,9 @@ internal PSPageBlobClient(PageBlobClient pageblobclient)
{
_pageBlobClient = pageblobclient;
}
public PSPageBlobClient(Uri blobUri)
public PSPageBlobClient(Uri blobUri, TokenCredential tokenCredential = null )
{
_pageBlobClient = new PageBlobClient(blobUri, null);
_pageBlobClient = tokenCredential == null ? new PageBlobClient(blobUri, null) : new PageBlobClient(blobUri, tokenCredential);
}

public Uri Uri { get { return _pageBlobClient.Uri; } }
Expand Down
1 change: 1 addition & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

-->
## Upcoming Release
* Add `-DataAccessAuthMode` parameter to Add-AzVhd DirectUploadToManagedDisk parameter set.

## Version 4.27.0
* Edited `New-AzVm` cmdlet internal logic to use the `PlatformFaultDomain` value in the `PSVirtualMachine` object passed to it in the new virtual machine.
Expand Down
73 changes: 73 additions & 0 deletions src/Compute/Compute/Common/ComputeTokenCredential.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Azure.Core;
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;

namespace Microsoft.Azure.Commands.Compute.Common
{
public class ComputeTokenCredential : TokenCredential
{
public IAccessToken accessToken { get; set; }
grizzlytheodore marked this conversation as resolved.
Show resolved Hide resolved
public ComputeTokenCredential(IAzureContext DefaultContext, string customAudience)
grizzlytheodore marked this conversation as resolved.
Show resolved Hide resolved
{

if (DefaultContext == null || DefaultContext.Account == null)
{
throw new InvalidOperationException();
}

accessToken = AzureSession.Instance.AuthenticationFactory.Authenticate(
DefaultContext.Account,
EnsureCustomAudienceSet(DefaultContext.Environment, customAudience),
DefaultContext.Tenant.Id,
null,
ShowDialog.Never,
null,
customAudience);

}

public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken)
{
AccessToken token;
accessToken.AuthorizeRequest((tokenType, tokenValue) =>
grizzlytheodore marked this conversation as resolved.
Show resolved Hide resolved
{
token = new AccessToken(tokenValue, DateTimeOffset.UtcNow);
});
return token;
}

public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken)
{
return new ValueTask<AccessToken>(this.GetToken(requestContext, cancellationToken));
}

private IAzureEnvironment EnsureCustomAudienceSet(IAzureEnvironment environment, string customAudience)
{
if (environment != null)
{
if (!environment.IsPropertySet(customAudience))
{
environment.SetProperty(customAudience, customAudience);
}
}
return environment;
}
}
}
2 changes: 1 addition & 1 deletion src/Compute/Compute/Compute.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>Compute</PsModuleName>
Expand Down
23 changes: 20 additions & 3 deletions src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
using Microsoft.Samples.HyperV.Storage;
using Microsoft.Samples.HyperV.Common;
using System.Threading;
using Azure.Core;
using Microsoft.Azure.Commands.Compute.Common;


namespace Microsoft.Azure.Commands.Compute.StorageServices
Expand Down Expand Up @@ -178,6 +180,14 @@ public class AddAzureVhdCommand : ComputeClientBaseCmdlet
HelpMessage = "Skips the resizing of VHD")]
public SwitchParameter SkipResizing { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
ParameterSetName = DirectUploadToManagedDiskSet,
HelpMessage = "Additional authentication requirements when exporting or uploading to a disk or snapshot. Possible options are: \"AzureActiveDirectory\" and \"None\".")]
[PSArgumentCompleter("AzureActiveDirectory", "None")]
public string DataAccessAuthMode { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

Expand Down Expand Up @@ -228,13 +238,19 @@ public override void ExecuteCmdlet()

// 3-4: UPLOAD
WriteVerbose("Preparing for Upload");
PSPageBlobClient managedDisk = new PSPageBlobClient(sasUri);
ComputeTokenCredential tokenCredential = null;
if (this.DataAccessAuthMode == "AzureActiveDirectory")
{
// get token
tokenCredential = new ComputeTokenCredential(DefaultContext, "https://disk.compute.azure.com/");
grizzlytheodore marked this conversation as resolved.
Show resolved Hide resolved
}
PSPageBlobClient managedDisk = new PSPageBlobClient(sasUri, tokenCredential);
DiskUploadCreator diskUploadCreator = new DiskUploadCreator();
var uploadContext = diskUploadCreator.Create(this.LocalFilePath, managedDisk, false);
var synchronizer = new DiskSynchronizer(uploadContext, this.NumberOfUploaderThreads ?? DefaultNumberOfUploaderThreads);

WriteVerbose("Uploading");
if (synchronizer.Synchronize())
if (synchronizer.Synchronize(tokenCredential))
{
var result = new VhdUploadContext { LocalFilePath = this.LocalFilePath, DestinationUri = sasUri };
WriteObject(result);
Expand Down Expand Up @@ -378,7 +394,8 @@ private PSDisk CreateDiskConfig()
EncryptionSettingsCollection = null,
Encryption = null,
NetworkAccessPolicy = null,
DiskAccessId = null
DiskAccessId = null,
DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? this.DataAccessAuthMode : null
grizzlytheodore marked this conversation as resolved.
Show resolved Hide resolved
};
return vDisk;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Compute/Compute/Sync/Upload/DiskSynchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.WindowsAzure.Commands.Sync.Upload;
using Microsoft.WindowsAzure.Commands.Sync;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.Compute.Common;

namespace Microsoft.Azure.Commands.Compute.Sync.Upload
{
Expand All @@ -47,7 +48,7 @@ public DiskSynchronizer(UploadContextDisk context, int maxParallelism)
this.maxParallelism = maxParallelism;
}

public bool Synchronize()
public bool Synchronize(ComputeTokenCredential tokenCredential)
{
var uploadStatus = new ProgressStatus(alreadyUploadedData, alreadyUploadedData + dataToUpload, new ComputeStats());

Expand All @@ -57,7 +58,7 @@ public bool Synchronize()
Task<LoopResult> task = Task<LoopResult>.Factory.StartNew(() =>
{
return Threading.Parallel.ForEach(dataWithRanges,
() => new PSPageBlobClient(pageBlob.Uri),
() => new PSPageBlobClient(pageBlob.Uri, tokenCredential),
(dwr, b) =>
{
using (dwr)
Expand Down
33 changes: 18 additions & 15 deletions src/Compute/Compute/help/Add-AzVhd.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Add-AzVhd [-ResourceGroupName] <String> [-Destination] <Uri> [-LocalFilePath] <F
```
Add-AzVhd [-ResourceGroupName] <String> [-LocalFilePath] <FileInfo> -DiskName <String> [-Location] <String>
[-DiskSku <String>] [-DiskZone <String[]>] [-DiskHyperVGeneration <String>]
[-DiskOsType <OperatingSystemTypes>] [[-NumberOfUploaderThreads] <Int32>] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
[-DiskOsType <OperatingSystemTypes>] [[-NumberOfUploaderThreads] <Int32>] [-DataAccessAuthMode <String>]
[-AsJob] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -127,6 +127,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -DataAccessAuthMode
Additional authentication requirements when exporting or uploading to a disk or snapshot. Possible options are: "AzureActiveDirectory" and "None".

```yaml
Type: System.String
Parameter Sets: DirectUploadToManagedDiskSet
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure.

Expand Down Expand Up @@ -299,19 +314,7 @@ Specifies the name of the resource group of the virtual machine.

```yaml
Type: System.String
Parameter Sets: DefaultParameterSet
Aliases:

Required: False
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

```yaml
Type: System.String
Parameter Sets: DirectUploadToManagedDiskSet
Parameter Sets: (All)
Aliases:

Required: True
Expand Down