Upgrade Azure.ResourceManager to 1.0.0

This commit is contained in:
Beisi Zhou 2022-05-13 10:50:28 +08:00
Родитель 9105155fa6
Коммит c11047e997
8 изменённых файлов: 33 добавлений и 31 удалений

Просмотреть файл

@ -142,7 +142,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Factories
}
var creds = AzureSession.Instance.AuthenticationFactory.GetTokenCredential(context, endpoint);
return new ArmClient(context.Subscription.Id.ToString(), creds, option);
return new ArmClient(creds, context.Subscription.Id.ToString(), option);
}
public virtual TClient CreateCustomArmClient<TClient>(params object[] parameters) where TClient : Microsoft.Rest.ServiceClient<TClient>

Просмотреть файл

@ -17,7 +17,7 @@
<PackageReference Include="Portable.BouncyCastle" Version="1.8.8" />
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.KeyVault.WebKey" Version="3.0.1" />
<PackageReference Include="Azure.ResourceManager.KeyVault" Version="1.0.0-beta.5" />
<PackageReference Include="Azure.ResourceManager.KeyVault" Version="1.0.0-beta.8" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="4.0.0-preview.1" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="4.5.0" />
</ItemGroup>

Просмотреть файл

@ -29,7 +29,7 @@ namespace Microsoft.Azure.Commands.KeyVault.Models
{
}
public PSKeyVault(Track2ManagementSdk.Vault vault, IMicrosoftGraphClient graphClient)
public PSKeyVault(Track2ManagementSdk.VaultResource vault, IMicrosoftGraphClient graphClient)
{
if (!vault.HasData)
{
@ -45,7 +45,7 @@ namespace Microsoft.Azure.Commands.KeyVault.Models
TenantId = vault.Data.Properties.TenantId;
var vaultTenantDisplayName = ModelExtensions.GetDisplayNameForTenant(vault.Data.Properties.TenantId, graphClient);
TenantName = vaultTenantDisplayName;
VaultUri = vault.Data.Properties.VaultUri;
VaultUri = vault.Data.Properties.VaultUri.ToString();
EnabledForDeployment = vault.Data.Properties.EnabledForDeployment ?? false;
EnabledForTemplateDeployment = vault.Data.Properties.EnabledForTemplateDeployment;
EnabledForDiskEncryption = vault.Data.Properties.EnabledForDiskEncryption;

Просмотреть файл

@ -107,7 +107,7 @@ namespace Microsoft.Azure.Commands.KeyVault.Models
};
}
public Track2ManagementSdk.VaultCreateOrUpdateParameters ToTrack2VaultCreateOrUpdateParameters()
public Track2ManagementSdk.VaultCreateOrUpdateContent ToTrack2VaultCreateOrUpdateContent()
{
if (this == null)
throw new ArgumentNullException("parameters");
@ -118,7 +118,7 @@ namespace Microsoft.Azure.Commands.KeyVault.Models
if (string.IsNullOrWhiteSpace(Location))
throw new ArgumentNullException("parameters.Location");
Track2ManagementSdk.Sku sku = null;
Track2ManagementSdk.KeyVaultSku sku = null;
Track2ManagementSdk.VaultProperties properties = null;
if (CreateMode != Track1ManagementSdk.CreateMode.Recover)
@ -130,10 +130,10 @@ namespace Microsoft.Azure.Commands.KeyVault.Models
if (!string.IsNullOrWhiteSpace(SkuName) && !string.IsNullOrWhiteSpace(SkuFamilyName))
{
if (Enum.TryParse(SkuName, true, out Track2ManagementSdk.SkuName skuName) &&
Enum.TryParse(SkuFamilyName, true, out Track2ManagementSdk.SkuFamily skuFamily))
if (Enum.TryParse(SkuName, true, out Track2ManagementSdk.KeyVaultSkuName skuName) &&
Enum.TryParse(SkuFamilyName, true, out Track2ManagementSdk.KeyVaultSkuFamily skuFamily))
{
sku = new Track2ManagementSdk.Sku(skuFamily, skuName);
sku = new Track2ManagementSdk.KeyVaultSku(skuFamily, skuName);
}
else
{
@ -151,7 +151,7 @@ namespace Microsoft.Azure.Commands.KeyVault.Models
EnableRbacAuthorization = EnableRbacAuthorization,
SoftDeleteRetentionInDays = SoftDeleteRetentionInDays,
TenantId = TenantId,
VaultUri = ""
VaultUri = new Uri("")
};
/*properties.AccessPolicies = (parameters.AccessPolicy != null) ? new[] { parameters.AccessPolicy } :
new Track1ManagementSdk.AccessPolicyEntry[] { };
@ -167,7 +167,7 @@ namespace Microsoft.Azure.Commands.KeyVault.Models
properties.CreateMode = Track2ManagementSdk.CreateMode.Recover;
}
return new Track2ManagementSdk.VaultCreateOrUpdateParameters(Location, properties);
return new Track2ManagementSdk.VaultCreateOrUpdateContent(Location, properties);
}
private void UpdateVaultNetworkRuleSetProperties(Track1ManagementSdk.VaultProperties vaultProperties, PSKeyVaultNetworkRuleSet psRuleSet)

Просмотреть файл

@ -1,4 +1,6 @@
using Azure.ResourceManager;
using Azure;
using Azure.Core;
using Azure.ResourceManager;
using Azure.ResourceManager.KeyVault;
using Azure.ResourceManager.KeyVault.Models;
using Azure.ResourceManager.Resources;
@ -23,18 +25,18 @@ namespace Microsoft.Azure.Commands.KeyVault.Track2Models
_subscription = context.Subscription.Id;
}
private ResourceGroup GetResourceGroup(string resourcegroup) =>
_armClient.GetResourceGroup(new ResourceIdentifier(
string.Format("/subscriptions/{0}/resourceGroups/{1}", _subscription, resourcegroup)));
private ResourceGroupResource GetResourceGroup(string resourceGroupName) =>
_armClient.GetResourceGroupResource(ResourceGroupResource.CreateResourceIdentifier(_subscription, resourceGroupName));
public IEnumerable<Vault> ListVaults(string resourcegroup) =>
GetResourceGroup(resourcegroup).GetVaults().GetAll();
public Vault GetVault(string resourcegroup, string vaultName) =>
_armClient.GetVault(Vault.CreateResourceIdentifier(_subscription, resourcegroup, vaultName));
public IEnumerable<VaultResource> ListVaults(string resourceGroupName) =>
GetResourceGroup(resourceGroupName).GetVaults().GetAll();
public VaultResource GetVault(string resourcegroup, string vaultName) =>
_armClient.GetVaultResource(VaultResource.CreateResourceIdentifier(_subscription, resourcegroup, vaultName));
public VaultResource CreateVault(string resourceGroupName, string vaultName, VaultCreateOrUpdateContent parameters) =>
GetResourceGroup(resourceGroupName).GetVaults().CreateOrUpdate(WaitUntil.Completed, vaultName, parameters).WaitForCompletion();
public Vault CreateVault(string resourcegroup, string vaultName, VaultCreateOrUpdateParameters parameters) =>
GetResourceGroup(resourcegroup).GetVaults().CreateOrUpdate(vaultName, parameters).Value;
}
}

Просмотреть файл

@ -64,7 +64,7 @@ namespace Microsoft.Azure.Commands.KeyVault
{
Bypass = track2NetworkRuleSet.Bypass.ToString(),
DefaultAction = track2NetworkRuleSet.DefaultAction.ToString(),
IpRules = track2NetworkRuleSet.IpRules.Select(ipRule => new Track1ManagementSdk.Models.IPRule(ipRule.Value)).ToList(),
IpRules = track2NetworkRuleSet.IPRules.Select(ipRule => new Track1ManagementSdk.Models.IPRule(ipRule.Value)).ToList(),
VirtualNetworkRules = track2NetworkRuleSet.VirtualNetworkRules.Select(vnRule => new Track1ManagementSdk.Models.VirtualNetworkRule(vnRule.Id)).ToList()
};
@ -77,7 +77,7 @@ namespace Microsoft.Azure.Commands.KeyVault
return track1CreateMode;
}
public static Track1ManagementSdk.Models.Permissions ToTrack1Permissions(this Track2ManagementSdk.Models.Permissions track2Permissions) =>
public static Track1ManagementSdk.Models.Permissions ToTrack1Permissions(this Track2ManagementSdk.Models.AccessPermissions track2Permissions) =>
new Track1ManagementSdk.Models.Permissions(track2Permissions.Keys.Select(key => key.ToString()).ToList(),
track2Permissions.Secrets.Select(key => key.ToString()).ToList(),
track2Permissions.Certificates.Select(key => key.ToString()).ToList(),
@ -92,7 +92,7 @@ namespace Microsoft.Azure.Commands.KeyVault
TenantId = track2AccessPolicyEntry.TenantId
};
public static Track1ManagementSdk.Models.Sku ToTrack1Sku(this Track2ManagementSdk.Models.Sku track2Sku)
public static Track1ManagementSdk.Models.Sku ToTrack1Sku(this Track2ManagementSdk.Models.KeyVaultSku track2Sku)
{
Track1ManagementSdk.Models.Sku track1Sku = new Track1ManagementSdk.Models.Sku();
@ -107,7 +107,7 @@ namespace Microsoft.Azure.Commands.KeyVault
public static Track1ManagementSdk.Models.PrivateEndpointConnectionItem ToTrack1PrivateEndpointConnectionItem(this Track2ManagementSdk.Models.PrivateEndpointConnectionItem track2PrivateEndpointConnectionItem) =>
new Track1ManagementSdk.Models.PrivateEndpointConnectionItem()
{
PrivateEndpoint = new Track1ManagementSdk.Models.PrivateEndpoint(track2PrivateEndpointConnectionItem.PrivateEndpoint.Id),
PrivateEndpoint = new Track1ManagementSdk.Models.PrivateEndpoint(track2PrivateEndpointConnectionItem.Id),
PrivateLinkServiceConnectionState = new Track1ManagementSdk.Models.PrivateLinkServiceConnectionState(
track2PrivateEndpointConnectionItem.PrivateLinkServiceConnectionState.Status?.ToString(),
track2PrivateEndpointConnectionItem.PrivateLinkServiceConnectionState.Description,
@ -120,7 +120,7 @@ namespace Microsoft.Azure.Commands.KeyVault
TenantId = track2VaultProperties.TenantId,
Sku = track2VaultProperties.Sku?.ToTrack1Sku(),
AccessPolicies = track2VaultProperties.AccessPolicies.Select(ap => ap?.ToTrack1AccessPolicyEntry()).ToList(),
VaultUri = track2VaultProperties.VaultUri,
VaultUri = track2VaultProperties.VaultUri.ToString(),
EnabledForDeployment = track2VaultProperties.EnabledForDeployment,
EnabledForDiskEncryption = track2VaultProperties.EnabledForDiskEncryption,
EnabledForTemplateDeployment = track2VaultProperties.EnabledForTemplateDeployment,
@ -133,9 +133,9 @@ namespace Microsoft.Azure.Commands.KeyVault
// PrivateEndpointConnections = track2VaultProperties.PrivateEndpointConnections.Select(peCon => peCon?.ToTrack1PrivateEndpointConnectionItem()).ToList()
};
public static Track1ManagementSdk.Models.Vault ToTrack1Vault(this Track2ManagementSdk.Vault track2Vault) =>
public static Track1ManagementSdk.Models.Vault ToTrack1Vault(this Track2ManagementSdk.VaultResource track2Vault) =>
new Track1ManagementSdk.Models.Vault(
track2Vault.Data.Properties?.ToTrack1VaultProperties(),
track2Vault.Data.Id, track2Vault.Data.Name, track2Vault.Data.Type, track2Vault.Data.Location, track2Vault.Data.Tags.ToDictionary(pair => pair.Key, pair => pair.Value));
track2Vault.Data.Id, track2Vault.Data.Name, track2Vault.Data.ResourceType, track2Vault.Data.Location, track2Vault.Data.Tags.ToDictionary(pair => pair.Key, pair => pair.Value));
}
}

Просмотреть файл

@ -38,7 +38,7 @@ namespace Microsoft.Azure.Commands.KeyVault.Track2Models
#region Vault-related METHODS
public PSKeyVault CreateVault(string resourcegroup, string vaultName, VaultCreationOrUpdateParameters parameters, IMicrosoftGraphClient msGraphClient = null) =>
new PSKeyVault(Track2KeyVaultManagementClient.CreateVault(resourcegroup, vaultName, parameters.ToTrack2VaultCreateOrUpdateParameters()), msGraphClient);
new PSKeyVault(Track2KeyVaultManagementClient.CreateVault(resourcegroup, vaultName, parameters.ToTrack2VaultCreateOrUpdateContent()), msGraphClient);
public IList<PSKeyVault> ListVaults(string resourcegroup, IMicrosoftGraphClient msGraphClient = null)
{

Просмотреть файл

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Azure.ResourceManager" Version="1.0.0-beta.7" />
<PackageReference Include="Azure.ResourceManager" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.0.0-preview"/>