diff --git a/src/Storage/Storage.Management/Models/PSAzureFilesIdentityBasedAuthentication.cs b/src/Storage/Storage.Management/Models/PSAzureFilesIdentityBasedAuthentication.cs index 14ae48c41f6a..3ce99750875b 100644 --- a/src/Storage/Storage.Management/Models/PSAzureFilesIdentityBasedAuthentication.cs +++ b/src/Storage/Storage.Management/Models/PSAzureFilesIdentityBasedAuthentication.cs @@ -12,19 +12,19 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Management.Storage.Models; +using Track2Models = Azure.ResourceManager.Storage.Models; namespace Microsoft.Azure.Commands.Management.Storage.Models { public class PSAzureFilesIdentityBasedAuthentication { - public PSAzureFilesIdentityBasedAuthentication(AzureFilesIdentityBasedAuthentication auth) + public PSAzureFilesIdentityBasedAuthentication(Track2Models.AzureFilesIdentityBasedAuthentication auth) { if (auth != null) { - this.DirectoryServiceOptions = auth.DirectoryServiceOptions; + this.DirectoryServiceOptions = auth.DirectoryServiceOptions.ToString(); this.ActiveDirectoryProperties = auth.ActiveDirectoryProperties != null ? new PSActiveDirectoryProperties(auth.ActiveDirectoryProperties) : null; - this.DefaultSharePermission = auth.DefaultSharePermission; + this.DefaultSharePermission = auth.DefaultSharePermission.ToString(); } } // Gets or sets indicates the directory service used. Possible values include: 'None','AADDS', 'AD' @@ -35,7 +35,7 @@ public PSAzureFilesIdentityBasedAuthentication(AzureFilesIdentityBasedAuthentica public class PSActiveDirectoryProperties { - public PSActiveDirectoryProperties(ActiveDirectoryProperties properties) + public PSActiveDirectoryProperties(Track2Models.ActiveDirectoryProperties properties) { if (properties != null) { @@ -46,7 +46,7 @@ public PSActiveDirectoryProperties(ActiveDirectoryProperties properties) this.DomainSid = properties.DomainSid; this.AzureStorageSid = properties.AzureStorageSid; this.SamAccountName = properties.SamAccountName; - this.AccountType = properties.AccountType; + this.AccountType = properties.AccountType != null ? properties.AccountType.ToString() : null; } } public string DomainName { get; set; } diff --git a/src/Storage/Storage.Management/Models/PSBlobRestore.cs b/src/Storage/Storage.Management/Models/PSBlobRestore.cs index 8b02e2424584..33384b2d60a6 100644 --- a/src/Storage/Storage.Management/Models/PSBlobRestore.cs +++ b/src/Storage/Storage.Management/Models/PSBlobRestore.cs @@ -17,6 +17,7 @@ using Microsoft.WindowsAzure.Commands.Common.Attributes; using System; using System.Collections.Generic; +using Track2Models = Azure.ResourceManager.Storage.Models; namespace Microsoft.Azure.Commands.Management.Storage.Models { @@ -37,40 +38,32 @@ public PSBlobRestoreRange(string startRange, string endRange) this.EndRange = endRange; } - public PSBlobRestoreRange(BlobRestoreRange range) + public PSBlobRestoreRange(Track2Models.BlobRestoreRange range) { this.StartRange = range.StartRange; this.EndRange = range.EndRange; } - public static IList ParseBlobRestoreRanges(PSBlobRestoreRange[] ranges) + public static IList ParseBlobRestoreRanges(PSBlobRestoreRange[] ranges) { - IList re = new List(); + IList re = new List(); if (ranges == null) { re.Add( - new BlobRestoreRange - { - StartRange = "", - EndRange = "" - }); + new Track2Models.BlobRestoreRange("", "")); } else { foreach (PSBlobRestoreRange range in ranges) { re.Add( - new BlobRestoreRange - { - StartRange = range.StartRange, - EndRange = range.EndRange - }); + new Track2Models.BlobRestoreRange(range.EndRange, range.StartRange)); } } return re; } - public static PSBlobRestoreRange[] ParsePSBlobRestoreRanges(IList ranges) + public static PSBlobRestoreRange[] ParsePSBlobRestoreRanges(IList ranges) { if (ranges == null) { @@ -78,7 +71,7 @@ public static PSBlobRestoreRange[] ParsePSBlobRestoreRanges(IList re = new List(); - foreach (BlobRestoreRange range in ranges) + foreach (Track2Models.BlobRestoreRange range in ranges) { re.Add( new PSBlobRestoreRange @@ -109,11 +102,11 @@ public class PSBlobRestoreStatus public PSBlobRestoreStatus() { } - public PSBlobRestoreStatus(BlobRestoreStatus status) + public PSBlobRestoreStatus(Track2Models.BlobRestoreStatus status) { if (status != null) { - this.Status = status.Status; + this.Status = status.Status != null ? status.Status.ToString() : null; this.FailureReason = status.FailureReason; this.RestoreId = status.RestoreId; this.Parameters = status.Parameters is null ? null : new PSBlobRestoreParameters(status.Parameters); @@ -126,13 +119,13 @@ public PSBlobRestoreStatus(BlobRestoreStatus status) /// public class PSBlobRestoreParameters { - public DateTime TimeToRestore { get; set; } + public DateTimeOffset TimeToRestore { get; set; } public PSBlobRestoreRange[] BlobRanges { get; set; } public PSBlobRestoreParameters() { } - public PSBlobRestoreParameters(BlobRestoreParameters parameters) + public PSBlobRestoreParameters(Track2Models.BlobRestoreContent parameters) { this.TimeToRestore = parameters.TimeToRestore; this.BlobRanges = PSBlobRestoreRange.ParsePSBlobRestoreRanges(parameters.BlobRanges); diff --git a/src/Storage/Storage.Management/Models/PSGeoReplicationStats.cs b/src/Storage/Storage.Management/Models/PSGeoReplicationStats.cs index e7f9eca61d1a..84e1ce90080f 100644 --- a/src/Storage/Storage.Management/Models/PSGeoReplicationStats.cs +++ b/src/Storage/Storage.Management/Models/PSGeoReplicationStats.cs @@ -12,32 +12,32 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Management.Storage.Models; +using Track2Models = Azure.ResourceManager.Storage.Models; using System; namespace Microsoft.Azure.Commands.Management.Storage.Models { public class PSGeoReplicationStats { - //Parse GeoReplicationStats in SDK to wrapped property PSGeoReplicationStats - public static PSGeoReplicationStats ParsePSGeoReplicationStats(GeoReplicationStats geoReplicationStats) + //Parse GeoReplicationStats in SDK to wrapped property PSGeoReplicationStats + public static PSGeoReplicationStats ParsePSGeoReplicationStats(Track2Models.GeoReplicationStats geoReplicationStats) { if (geoReplicationStats == null) { return null; } - PSGeoReplicationStats pSGeoReplicationStats = new PSGeoReplicationStats(); - - pSGeoReplicationStats.Status = geoReplicationStats.Status; - pSGeoReplicationStats.LastSyncTime = geoReplicationStats.LastSyncTime; - pSGeoReplicationStats.CanFailover = geoReplicationStats.CanFailover; - + PSGeoReplicationStats pSGeoReplicationStats = new PSGeoReplicationStats + { + Status = geoReplicationStats.Status != null ? geoReplicationStats.Status.ToString() : null, + LastSyncTime = geoReplicationStats.LastSyncOn, + CanFailover = geoReplicationStats.CanFailover != null ? geoReplicationStats.CanFailover : null + }; return pSGeoReplicationStats; } public string Status { get; set; } - public DateTime? LastSyncTime { get; set; } + public DateTimeOffset? LastSyncTime { get; set; } public bool? CanFailover { get; set; } } } diff --git a/src/Storage/Storage.Management/Models/PSNetworkRule.cs b/src/Storage/Storage.Management/Models/PSNetworkRule.cs index 7bd7e96ef6ef..0bc50bcbfcc8 100644 --- a/src/Storage/Storage.Management/Models/PSNetworkRule.cs +++ b/src/Storage/Storage.Management/Models/PSNetworkRule.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using Microsoft.WindowsAzure.Commands.Common.Attributes; +using Track2Models = Azure.ResourceManager.Storage.Models; namespace Microsoft.Azure.Commands.Management.Storage.Models { @@ -82,14 +83,14 @@ public class PSNetworkRuleSet //Parse NetworkRule property Action in SDK to wrapped property PSNetworkRuleActionEnum - public static PSNetworkRuleActionEnum? ParsePSNetworkRuleAction(Microsoft.Azure.Management.Storage.Models.Action? action) + public static PSNetworkRuleActionEnum? ParsePSNetworkRuleAction(string action) { if (action == null) { return null; } - if (action.Value == Microsoft.Azure.Management.Storage.Models.Action.Allow) + if (string.Equals(action.ToUpper(), "ALLOW")) { return PSNetworkRuleActionEnum.Allow; } @@ -99,7 +100,7 @@ public class PSNetworkRuleSet //Parse wrapped property PSNetworkRuleActionEnum to NetworkRule rule property Action in SDK - public static Microsoft.Azure.Management.Storage.Models.Action? ParseStorageNetworkRuleAction(PSNetworkRuleActionEnum? action) + public static string ParseStorageNetworkRuleAction(PSNetworkRuleActionEnum? action) { if (action == null) { @@ -108,9 +109,9 @@ public class PSNetworkRuleSet if (action == PSNetworkRuleActionEnum.Allow) { - return Microsoft.Azure.Management.Storage.Models.Action.Allow; + return "Allow"; } - return Microsoft.Azure.Management.Storage.Models.Action.Allow; + return "Allow"; } //Parse NetworkRule property Bypass in SDK to wrapped property PSNetworkRuleBypassEnum @@ -171,9 +172,9 @@ public static string ParseStorageNetworkRuleBypass(PSNetWorkRuleBypassEnum? bypa } //Parse NetworkRule property DefaultAction in SDK to wrapped property PSNetworkRuleDefaultActionEnum - public static PSNetWorkRuleDefaultActionEnum ParsePSNetworkRuleDefaultAction(DefaultAction defaultAction) + public static PSNetWorkRuleDefaultActionEnum ParsePSNetworkRuleDefaultAction(Track2Models.DefaultAction defaultAction) { - if (defaultAction == Microsoft.Azure.Management.Storage.Models.DefaultAction.Allow) + if (defaultAction == Track2Models.DefaultAction.Allow) { return PSNetWorkRuleDefaultActionEnum.Allow; } @@ -184,56 +185,62 @@ public static PSNetWorkRuleDefaultActionEnum ParsePSNetworkRuleDefaultAction(Def } //Parse wrapped property PSNetworkRuleDefaultActionEnum to NetworkRule property DefaultAction in SDK - public static DefaultAction ParseStorageNetworkRuleDefaultAction(PSNetWorkRuleDefaultActionEnum defaultAction) + public static Track2Models.DefaultAction ParseStorageNetworkRuleDefaultAction(PSNetWorkRuleDefaultActionEnum defaultAction) { if (defaultAction == PSNetWorkRuleDefaultActionEnum.Allow) { - return Microsoft.Azure.Management.Storage.Models.DefaultAction.Allow; + return Track2Models.DefaultAction.Allow; } else { - return Microsoft.Azure.Management.Storage.Models.DefaultAction.Deny; + return Track2Models.DefaultAction.Deny; } } //Parse single NetworkRule IpRule in SDK to wrapped property PSIpRule - public static PSIpRule ParsePSNetworkRuleIPRule(IPRule ipRule) + public static PSIpRule ParsePSNetworkRuleIPRule(Track2Models.IPRule ipRule) { - PSIpRule returnRule = new PSIpRule(); - returnRule.Action = ParsePSNetworkRuleAction(ipRule.Action); - returnRule.IPAddressOrRange = ipRule.IPAddressOrRange; + PSIpRule returnRule = new PSIpRule + { + Action = ipRule.Action != null ? ParsePSNetworkRuleAction(ipRule.Action) : null, + IPAddressOrRange = ipRule.IPAddressOrRange + }; return returnRule; } //Parse wrapped property PSIpRule to single NetworkRule IpRule in SDK - public static IPRule ParseStorageNetworkRuleIPRule(PSIpRule ipRule) + public static Track2Models.IPRule ParseStorageNetworkRuleIPRule(PSIpRule ipRule) { - IPRule returnRule = new IPRule(); + Track2Models.IPRule returnRule = new Track2Models.IPRule(ipRule.IPAddressOrRange); returnRule.Action = ParseStorageNetworkRuleAction(ipRule.Action); - returnRule.IPAddressOrRange = ipRule.IPAddressOrRange; return returnRule; } //Parse single NetworkRule PSResourceAccessRule in SDK to wrapped property PSPSResourceAccessRule - public static PSResourceAccessRule ParsePSResourceAccessRule(ResourceAccessRule rule) + public static PSResourceAccessRule ParsePSResourceAccessRule(Track2Models.ResourceAccessRule rule) { - PSResourceAccessRule returnRule = new PSResourceAccessRule(); - returnRule.TenantId = rule.TenantId; - returnRule.ResourceId = rule.ResourceId; + PSResourceAccessRule returnRule = new PSResourceAccessRule + { + TenantId = rule.TenantId, + ResourceId = rule.ResourceId + }; return returnRule; } //Parse wrapped property PSPSResourceAccessRule to single NetworkRule PSResourceAccessRule in SDK - public static ResourceAccessRule ParseStorageResourceAccessRule(PSResourceAccessRule rule) + public static Track2Models.ResourceAccessRule ParseStorageResourceAccessRule(PSResourceAccessRule rule) { - ResourceAccessRule returnRule = new ResourceAccessRule(); - returnRule.TenantId = rule.TenantId; - returnRule.ResourceId = rule.ResourceId; + Track2Models.ResourceAccessRule returnRule = + new Track2Models.ResourceAccessRule + { + TenantId = rule.TenantId, + ResourceId = rule.ResourceId + }; return returnRule; } //Parse single NetworkRule VirtualNetworkRule in SDK to wrapped property PSVirtualNetworkRule - public static PSVirtualNetworkRule ParsePSNetworkRuleVirtualNetworkRule(VirtualNetworkRule virtualNetworkRule) + public static PSVirtualNetworkRule ParsePSNetworkRuleVirtualNetworkRule(Track2Models.VirtualNetworkRule virtualNetworkRule) { PSVirtualNetworkRule returnRule = new PSVirtualNetworkRule(); returnRule.Action = ParsePSNetworkRuleAction(virtualNetworkRule.Action); @@ -244,30 +251,31 @@ public static PSVirtualNetworkRule ParsePSNetworkRuleVirtualNetworkRule(VirtualN } //Parse wrapped property PSVirtualNetworkRule to single NetworkRule VirtualNetworkRule in SDK - public static VirtualNetworkRule ParseStorageNetworkRuleVirtualNetworkRule(PSVirtualNetworkRule virtualNetworkRule) + public static Track2Models.VirtualNetworkRule ParseStorageNetworkRuleVirtualNetworkRule(PSVirtualNetworkRule virtualNetworkRule) { - VirtualNetworkRule returnRule = new VirtualNetworkRule(); - returnRule.Action = ParseStorageNetworkRuleAction(virtualNetworkRule.Action); - returnRule.VirtualNetworkResourceId = virtualNetworkRule.VirtualNetworkResourceId; + Track2Models.VirtualNetworkRule returnRule = + new Track2Models.VirtualNetworkRule(virtualNetworkRule.VirtualNetworkResourceId); + var action = ParseStorageNetworkRuleAction(virtualNetworkRule.Action); + returnRule.Action = action != null ? action : null; return returnRule; } //Parse Storage NetworkRule object in SDK to wrapped PSNetworkRuleSet - public static PSNetworkRuleSet ParsePSNetworkRule(NetworkRuleSet rules) + public static PSNetworkRuleSet ParsePSNetworkRule(Track2Models.NetworkRuleSet rules) { if (rules == null) { return null; } PSNetworkRuleSet returnRules = new PSNetworkRuleSet(); - returnRules.Bypass = ParsePSNetworkRuleBypass(rules.Bypass); + returnRules.Bypass = rules.Bypass != null ? ParsePSNetworkRuleBypass(rules.Bypass.ToString()) : null; returnRules.DefaultAction = ParsePSNetworkRuleDefaultAction(rules.DefaultAction); List ipRuleList = new List(); - if (rules.IpRules != null) + if (rules.IPRules != null) { - foreach (var ipRule in rules.IpRules) + foreach (var ipRule in rules.IPRules) { ipRuleList.Add(ParsePSNetworkRuleIPRule(ipRule)); } @@ -298,44 +306,40 @@ public static PSNetworkRuleSet ParsePSNetworkRule(NetworkRuleSet rules) } //Parse wrapped PSNetworkRuleSet to storage NetworkRule object in SDK - public static NetworkRuleSet ParseStorageNetworkRule(PSNetworkRuleSet rules) + public static Track2Models.NetworkRuleSet ParseStorageNetworkRule(PSNetworkRuleSet rules) { if (rules == null) { return null; } - NetworkRuleSet returnRules = new NetworkRuleSet(); - returnRules.Bypass = ParseStorageNetworkRuleBypass(rules.Bypass); - returnRules.DefaultAction = ParseStorageNetworkRuleDefaultAction(rules.DefaultAction); + Track2Models.NetworkRuleSet returnRules = + new Track2Models.NetworkRuleSet(ParseStorageNetworkRuleDefaultAction(rules.DefaultAction)) + { + Bypass = ParseStorageNetworkRuleBypass(rules.Bypass) + }; - List ipRuleList = new List(); if (rules.IpRules != null) { foreach (var ipRule in rules.IpRules) { - ipRuleList.Add(ParseStorageNetworkRuleIPRule(ipRule)); + returnRules.IPRules.Add(ParseStorageNetworkRuleIPRule(ipRule)); } - returnRules.IpRules = ipRuleList.ToArray(); } - List virtualNetworkList = new List(); if (rules.VirtualNetworkRules != null) { foreach (var virtualNetworkRule in rules.VirtualNetworkRules) { - virtualNetworkList.Add(ParseStorageNetworkRuleVirtualNetworkRule(virtualNetworkRule)); + returnRules.VirtualNetworkRules.Add(ParseStorageNetworkRuleVirtualNetworkRule(virtualNetworkRule)); } - returnRules.VirtualNetworkRules = virtualNetworkList.ToArray(); } - List resourceAccessRuleList = new List(); if (rules.ResourceAccessRules != null) { foreach (var rule in rules.ResourceAccessRules) { - resourceAccessRuleList.Add(ParseStorageResourceAccessRule(rule)); + returnRules.ResourceAccessRules.Add(ParseStorageResourceAccessRule(rule)); } - returnRules.ResourceAccessRules = resourceAccessRuleList.ToArray(); } return returnRules; diff --git a/src/Storage/Storage.Management/Models/PSRoutingPreference.cs b/src/Storage/Storage.Management/Models/PSRoutingPreference.cs index bfa76016af71..65b30abc75d1 100644 --- a/src/Storage/Storage.Management/Models/PSRoutingPreference.cs +++ b/src/Storage/Storage.Management/Models/PSRoutingPreference.cs @@ -12,7 +12,7 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Management.Storage.Models; +using Track2Models = Azure.ResourceManager.Storage.Models; using System; namespace Microsoft.Azure.Commands.Management.Storage.Models @@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.Management.Storage.Models public class PSRoutingPreference { //Parse RoutingPreference in SDK to wrapped property PSRoutingPreference - public static PSRoutingPreference ParsePSRoutingPreference(RoutingPreference routingPreference) + public static PSRoutingPreference ParsePSRoutingPreference(Track2Models.RoutingPreference routingPreference) { if (routingPreference == null) { @@ -29,7 +29,7 @@ public static PSRoutingPreference ParsePSRoutingPreference(RoutingPreference rou PSRoutingPreference pSRoutingPreference = new PSRoutingPreference(); - pSRoutingPreference.RoutingChoice = routingPreference.RoutingChoice; + pSRoutingPreference.RoutingChoice = routingPreference.RoutingChoice != null ? routingPreference.RoutingChoice.ToString() : null; pSRoutingPreference.PublishMicrosoftEndpoints = routingPreference.PublishMicrosoftEndpoints; pSRoutingPreference.PublishInternetEndpoints = routingPreference.PublishInternetEndpoints; diff --git a/src/Storage/Storage.Management/Models/PSStorageAccount.cs b/src/Storage/Storage.Management/Models/PSStorageAccount.cs index 889202dfc399..4d98050c7754 100644 --- a/src/Storage/Storage.Management/Models/PSStorageAccount.cs +++ b/src/Storage/Storage.Management/Models/PSStorageAccount.cs @@ -20,62 +20,71 @@ using System; using System.Collections.Generic; using Microsoft.WindowsAzure.Commands.Common.Attributes; -using StorageModels = Microsoft.Azure.Management.Storage.Models; using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; +using Track2 = Azure.ResourceManager.Storage; +using Track2Models = Azure.ResourceManager.Storage.Models; +using Azure.ResourceManager.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Microsoft.Azure.Storage; +using Microsoft.Azure.Storage.Auth; namespace Microsoft.Azure.Commands.Management.Storage.Models { public class PSStorageAccount : IStorageContextProvider { - public PSStorageAccount(StorageModels.StorageAccount storageAccount) + + public PSStorageAccount(Track2.StorageAccountResource storageAccountResource) { - this.ResourceGroupName = new ResourceIdentifier(storageAccount.Id).ResourceGroupName; - this.StorageAccountName = storageAccount.Name; - this.Id = storageAccount.Id; - this.Location = storageAccount.Location; - this.Sku = new PSSku(storageAccount.Sku); - this.Encryption = storageAccount.Encryption; - this.Kind = storageAccount.Kind; - this.AccessTier = storageAccount.AccessTier; - this.CreationTime = storageAccount.CreationTime; - this.CustomDomain = storageAccount.CustomDomain is null ? null : new PSCustomDomain(storageAccount.CustomDomain); - this.Identity = storageAccount.Identity; - this.LastGeoFailoverTime = storageAccount.LastGeoFailoverTime; - this.PrimaryEndpoints = storageAccount.PrimaryEndpoints; - this.PrimaryLocation = storageAccount.PrimaryLocation; - this.ProvisioningState = storageAccount.ProvisioningState; - this.SecondaryEndpoints = storageAccount.SecondaryEndpoints; - this.SecondaryLocation = storageAccount.SecondaryLocation; - this.StatusOfPrimary = storageAccount.StatusOfPrimary; - this.StatusOfSecondary = storageAccount.StatusOfSecondary; - this.Tags = storageAccount.Tags; - this.EnableHttpsTrafficOnly = storageAccount.EnableHttpsTrafficOnly; - this.NetworkRuleSet = PSNetworkRuleSet.ParsePSNetworkRule(storageAccount.NetworkRuleSet); - this.EnableHierarchicalNamespace = storageAccount.IsHnsEnabled; - this.FailoverInProgress = storageAccount.FailoverInProgress; - this.LargeFileSharesState = storageAccount.LargeFileSharesState; - this.AzureFilesIdentityBasedAuth = storageAccount.AzureFilesIdentityBasedAuthentication is null ? null : new PSAzureFilesIdentityBasedAuthentication(storageAccount.AzureFilesIdentityBasedAuthentication); - this.GeoReplicationStats = PSGeoReplicationStats.ParsePSGeoReplicationStats(storageAccount.GeoReplicationStats); - this.AllowBlobPublicAccess = storageAccount.AllowBlobPublicAccess; - this.MinimumTlsVersion = storageAccount.MinimumTlsVersion; - this.RoutingPreference = PSRoutingPreference.ParsePSRoutingPreference(storageAccount.RoutingPreference); - this.BlobRestoreStatus = storageAccount.BlobRestoreStatus is null ? null : new PSBlobRestoreStatus(storageAccount.BlobRestoreStatus); - this.EnableNfsV3 = storageAccount.EnableNfsV3; - this.ExtendedLocation = storageAccount.ExtendedLocation is null ? null : new PSExtendedLocation(storageAccount.ExtendedLocation); - this.AllowSharedKeyAccess = storageAccount.AllowSharedKeyAccess; - this.KeyCreationTime = storageAccount.KeyCreationTime is null ? null : new PSKeyCreationTime(storageAccount.KeyCreationTime); - this.KeyPolicy = storageAccount.KeyPolicy; - this.SasPolicy = storageAccount.SasPolicy; - this.AllowCrossTenantReplication = storageAccount.AllowCrossTenantReplication; - this.PublicNetworkAccess = storageAccount.PublicNetworkAccess; - this.ImmutableStorageWithVersioning = storageAccount.ImmutableStorageWithVersioning is null ? null : new PSImmutableStorageAccount(storageAccount.ImmutableStorageWithVersioning); - this.StorageAccountSkuConversionStatus = storageAccount.StorageAccountSkuConversionStatus is null ? null : new PSStorageAccountSkuConversionStatus(storageAccount.StorageAccountSkuConversionStatus); + this.ResourceGroupName = new ResourceIdentifier(storageAccountResource.Id).ResourceGroupName; + this.StorageAccountName = storageAccountResource.Data.Name; + this.Id = storageAccountResource.Id; + this.Location = storageAccountResource.Data.Location; + this.Sku = new PSSku(storageAccountResource.Data.Sku); + this.Encryption = storageAccountResource.Data.Encryption; + this.Kind = storageAccountResource.Data.Kind.ToString(); + this.AccessTier = storageAccountResource.Data.AccessTier; + this.CreationTime = storageAccountResource.Data.CreationOn; + this.CustomDomain = storageAccountResource.Data.CustomDomain is null ? null : new PSCustomDomain(storageAccountResource.Data.CustomDomain); + this.Identity = storageAccountResource.Data.Identity != null ? new PSIdentity(storageAccountResource.Data.Identity) : null; + this.LastGeoFailoverTime = storageAccountResource.Data.LastGeoFailoverOn; + this.PrimaryEndpoints = storageAccountResource.Data.PrimaryEndpoints; + this.PrimaryLocation = storageAccountResource.Data.PrimaryLocation; + this.ProvisioningState = storageAccountResource.Data.ProvisioningState; + this.SecondaryEndpoints = storageAccountResource.Data.SecondaryEndpoints; + this.SecondaryLocation = storageAccountResource.Data.SecondaryLocation; + this.StatusOfPrimary = storageAccountResource.Data.StatusOfPrimary; + this.StatusOfSecondary = storageAccountResource.Data.StatusOfSecondary; + this.Tags = storageAccountResource.Data.Tags; + this.EnableHttpsTrafficOnly = storageAccountResource.Data.EnableHttpsTrafficOnly; + + this.NetworkRuleSet = PSNetworkRuleSet.ParsePSNetworkRule(storageAccountResource.Data.NetworkRuleSet); + + this.EnableHierarchicalNamespace = storageAccountResource.Data.IsHnsEnabled; + this.FailoverInProgress = storageAccountResource.Data.FailoverInProgress; + this.LargeFileSharesState = storageAccountResource.Data.LargeFileSharesState.ToString(); + this.AzureFilesIdentityBasedAuth = + storageAccountResource.Data.AzureFilesIdentityBasedAuthentication is null ? null : new PSAzureFilesIdentityBasedAuthentication(storageAccountResource.Data.AzureFilesIdentityBasedAuthentication); + this.GeoReplicationStats = PSGeoReplicationStats.ParsePSGeoReplicationStats(storageAccountResource.Data.GeoReplicationStats); + this.AllowBlobPublicAccess = storageAccountResource.Data.AllowBlobPublicAccess; + this.MinimumTlsVersion = storageAccountResource.Data.MinimumTlsVersion is null ? null : storageAccountResource.Data.MinimumTlsVersion.ToString(); + this.RoutingPreference = PSRoutingPreference.ParsePSRoutingPreference(storageAccountResource.Data.RoutingPreference); + this.BlobRestoreStatus = storageAccountResource.Data.BlobRestoreStatus is null ? null : new PSBlobRestoreStatus(storageAccountResource.Data.BlobRestoreStatus); + this.EnableNfsV3 = storageAccountResource.Data.EnableNfsV3; + this.ExtendedLocation = storageAccountResource.Data.ExtendedLocation is null ? null : new PSExtendedLocation(storageAccountResource.Data.ExtendedLocation); + this.AllowSharedKeyAccess = storageAccountResource.Data.AllowSharedKeyAccess; + this.KeyCreationTime = storageAccountResource.Data.KeyCreationTime is null ? null : new PSKeyCreationTime(storageAccountResource.Data.KeyCreationTime); + this.KeyPolicy = storageAccountResource.Data.KeyExpirationPeriodInDays != null ? new PSKeyPolicy((int)(storageAccountResource.Data.KeyExpirationPeriodInDays)) : null; + this.SasPolicy = storageAccountResource.Data.SasPolicy != null ? new PSSasPolicy(storageAccountResource.Data.SasPolicy.SasExpirationPeriod, storageAccountResource.Data.SasPolicy.ExpirationAction.ToString()) : null; + this.AllowCrossTenantReplication = storageAccountResource.Data.AllowCrossTenantReplication; + this.PublicNetworkAccess = storageAccountResource.Data.PublicNetworkAccess != null ? storageAccountResource.Data.PublicNetworkAccess.ToString() : null; + this.ImmutableStorageWithVersioning = storageAccountResource.Data.ImmutableStorageWithVersioning is null ? null : new PSImmutableStorageAccount(storageAccountResource.Data.ImmutableStorageWithVersioning); } + public bool? AllowCrossTenantReplication { get; set; } public PSKeyCreationTime KeyCreationTime { get; set; } - public KeyPolicy KeyPolicy { get; } - public SasPolicy SasPolicy { get; } + public PSKeyPolicy KeyPolicy { get; } + public PSSasPolicy SasPolicy { get; } [Ps1Xml(Label = "ResourceGroupName", Target = ViewControl.Table, Position = 1)] public string ResourceGroupName { get; set; } @@ -93,35 +102,35 @@ public PSStorageAccount(StorageModels.StorageAccount storageAccount) [Ps1Xml(Label = "Kind", Target = ViewControl.Table, Position = 4)] public string Kind { get; set; } - public Encryption Encryption { get; set; } + public Track2Models.Encryption Encryption { get; set; } [Ps1Xml(Label = "AccessTier", Target = ViewControl.Table, Position = 5)] - public AccessTier? AccessTier { get; set; } + public Track2Models.AccessTier? AccessTier { get; set; } [Ps1Xml(Label = "CreationTime", Target = ViewControl.Table, Position = 6)] - public DateTime? CreationTime { get; set; } + public DateTimeOffset? CreationTime { get; set; } public PSCustomDomain CustomDomain { get; set; } - public Identity Identity { get; set; } + public PSIdentity Identity { get; set; } - public DateTime? LastGeoFailoverTime { get; set; } + public DateTimeOffset? LastGeoFailoverTime { get; set; } - public Endpoints PrimaryEndpoints { get; set; } + public Track2Models.Endpoints PrimaryEndpoints { get; set; } [Ps1Xml(Label = "PrimaryLocation", Target = ViewControl.Table, Position = 2)] public string PrimaryLocation { get; set; } [Ps1Xml(Label = "ProvisioningState", Target = ViewControl.Table, Position = 7)] - public ProvisioningState? ProvisioningState { get; set; } + public Track2Models.ProvisioningState? ProvisioningState { get; set; } - public Endpoints SecondaryEndpoints { get; set; } + public Track2Models.Endpoints SecondaryEndpoints { get; set; } public string SecondaryLocation { get; set; } - public AccountStatus? StatusOfPrimary { get; set; } + public Track2Models.AccountStatus? StatusOfPrimary { get; set; } - public AccountStatus? StatusOfSecondary { get; set; } + public Track2Models.AccountStatus? StatusOfSecondary { get; set; } public IDictionary Tags { get; set; } @@ -157,20 +166,37 @@ public PSStorageAccount(StorageModels.StorageAccount storageAccount) public string PublicNetworkAccess { get; set; } public PSImmutableStorageAccount ImmutableStorageWithVersioning { get; set; } - public PSStorageAccountSkuConversionStatus StorageAccountSkuConversionStatus { get; set; } - - public static PSStorageAccount Create(StorageModels.StorageAccount storageAccount, IStorageManagementClient client) + public static PSStorageAccount Create(Track2.StorageAccountResource storageAccountResource, Track2StorageManagementClient client) { - var result = new PSStorageAccount(storageAccount); + var result = new PSStorageAccount(storageAccountResource); + result.Context = new LazyAzureStorageContext((s) => { - return (new ARMStorageProvider(client)).GetCloudStorageAccount(s, result.ResourceGroupName); + return GetCloudStorageAccount(storageAccountResource); }, result.StorageAccountName) as AzureStorageContext; return result; } + public static CloudStorageAccount GetCloudStorageAccount(Track2.StorageAccountResource storageAccountResource) + { + Uri blobEndpoint = storageAccountResource.Data.PrimaryEndpoints.Blob != null ? new Uri(storageAccountResource.Data.PrimaryEndpoints.Blob) : null; + Uri queueEndpoint = storageAccountResource.Data.PrimaryEndpoints.Queue != null ? new Uri(storageAccountResource.Data.PrimaryEndpoints.Queue) : null; + Uri tableEndpoint = storageAccountResource.Data.PrimaryEndpoints.Table != null ? new Uri(storageAccountResource.Data.PrimaryEndpoints.Table) : null; + Uri fileEndpoint = storageAccountResource.Data.PrimaryEndpoints.File != null ? new Uri(storageAccountResource.Data.PrimaryEndpoints.File) : null; + string key = storageAccountResource.GetKeys().Value.Keys[0].Value; + StorageCredentials storageCredentials = new Azure.Storage.Auth.StorageCredentials(storageAccountResource.Data.Name, key); + CloudStorageAccount cloudStorageAccount = new CloudStorageAccount( + storageCredentials, + new StorageUri(blobEndpoint), + new StorageUri(queueEndpoint), + new StorageUri(tableEndpoint), + new StorageUri(fileEndpoint)); + + return cloudStorageAccount; + } + public IStorageContext Context { get; private set; } public IDictionary ExtendedProperties { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -186,45 +212,139 @@ public override string ToString() } } + public class PSKeyPolicy + { + public string KeyExpirationPeriodInDays { get; set; } + + public PSKeyPolicy(int keyExpirationPeriodInDays) + + { + this.KeyExpirationPeriodInDays = keyExpirationPeriodInDays.ToString(); + } + } + + public class PSSasPolicy + { + public string SasExpirationPeriod { get; set; } + + public static string ExpirationAction { get; set; } + + public PSSasPolicy(string sasExpirationPeriod, string expirationAction) + { + if (sasExpirationPeriod != null) + { + this.SasExpirationPeriod = sasExpirationPeriod; + } + if (expirationAction != null) + { + PSSasPolicy.ExpirationAction = expirationAction; + } + + } + + public PSSasPolicy() { } + } + public class PSCustomDomain { public string Name { get; set; } public bool? UseSubDomain { get; set; } - public PSCustomDomain(CustomDomain input) + public PSCustomDomain(Track2Models.CustomDomain input) { this.Name = input.Name; this.UseSubDomain = input.UseSubDomainName; } - public CustomDomain ParseCustomDomain() + public Track2Models.CustomDomain ParseCustomDomain() { - return new CustomDomain(this.Name, this.UseSubDomain); + Track2Models.CustomDomain customDomain = + new Track2Models.CustomDomain(this.Name); + customDomain.UseSubDomainName = this.UseSubDomain; + return customDomain; } } + + + + public class PSIdentity + { + public string PrincipalId { get; set; } + public string TenantId { get; set; } + + public string Type { get; set; } + + public IDictionary UserAssignedIdentities = new Dictionary(); + + public PSIdentity(ManagedServiceIdentity identity) + { + if (identity.PrincipalId != null) + { + this.PrincipalId = identity.PrincipalId.Value.ToString(); + } + + if (identity.TenantId != null) + { + this.TenantId = identity.TenantId.Value.ToString(); + } + if (identity != null) + { + this.Type = identity.ManagedServiceIdentityType.ToString(); + } + + identity.UserAssignedIdentities + .ForEach(x => this.UserAssignedIdentities.Add(x.Key, new PSUserAssignedIdentity(x.Value))); + } + + } + + public class PSUserAssignedIdentity + { + public string PrincipalId { get; set; } + + public string ClientId { get; set; } + + public PSUserAssignedIdentity(global::Azure.ResourceManager.Models.UserAssignedIdentity userAssignedIdentity) + { + if (userAssignedIdentity.PrincipalId != null) + { + this.PrincipalId = userAssignedIdentity.PrincipalId.Value.ToString(); + } + + if (userAssignedIdentity.ClientId != null) + { + this.ClientId = userAssignedIdentity.ClientId.Value.ToString(); + } + } + + } + public class PSSku { public string Name { get; set; } - public SkuTier? Tier { get; set; } + public Track2Models.StorageSkuTier? Tier { get; set; } public string ResourceType { get; set; } public string Kind { get; set; } public IList Locations { get; set; } public IList Capabilities { get; set; } public IList Restrictions { get; set; } - public PSSku(Sku sku) + public PSSku(Track2Models.StorageSku sku) { if (sku != null) { - this.Name = sku.Name; + this.Name = sku.Name.ToString(); this.Tier = sku.Tier; + } } - public Sku ParseSku() + + public Track2Models.StorageSku ParseSku() { - return new Sku(Name, Tier); + Track2Models.StorageSku sku = new Track2Models.StorageSku(Name); + return sku; } } @@ -233,10 +353,10 @@ public class PSExtendedLocation public PSExtendedLocation() { } - public PSExtendedLocation(ExtendedLocation extendedLocation) + public PSExtendedLocation(Track2Models.ExtendedLocation extendedLocation) { this.Name = extendedLocation.Name; - this.Type = extendedLocation.Type; + this.Type = extendedLocation.ExtendedLocationType != null ? extendedLocation.ExtendedLocationType.ToString() : null; } public string Name { get; set; } @@ -248,7 +368,7 @@ public class PSKeyCreationTime public PSKeyCreationTime() { } - public PSKeyCreationTime(KeyCreationTime keyCreationTime) + public PSKeyCreationTime(Track2Models.KeyCreationTime keyCreationTime) { if (keyCreationTime != null) { @@ -256,8 +376,8 @@ public PSKeyCreationTime(KeyCreationTime keyCreationTime) this.Key2 = keyCreationTime.Key2; } } - public System.DateTime? Key1 { get; set; } - public System.DateTime? Key2 { get; set; } + public System.DateTimeOffset? Key1 { get; set; } + public System.DateTimeOffset? Key2 { get; set; } } /// @@ -268,7 +388,7 @@ public class PSImmutableStorageAccount public PSImmutableStorageAccount() { } - public PSImmutableStorageAccount(ImmutableStorageAccount immutableStorageAccount) + public PSImmutableStorageAccount(Track2Models.ImmutableStorageAccount immutableStorageAccount) { if (immutableStorageAccount != null) { @@ -288,37 +408,15 @@ public class PSAccountImmutabilityPolicyProperties public PSAccountImmutabilityPolicyProperties() { } - public PSAccountImmutabilityPolicyProperties(AccountImmutabilityPolicyProperties accountImmutabilityPolicyProperties) + public PSAccountImmutabilityPolicyProperties(Track2Models.AccountImmutabilityPolicyProperties accountImmutabilityPolicyProperties) { if (accountImmutabilityPolicyProperties != null) { this.ImmutabilityPeriodSinceCreationInDays = accountImmutabilityPolicyProperties.ImmutabilityPeriodSinceCreationInDays; - this.State = accountImmutabilityPolicyProperties.State; + this.State = accountImmutabilityPolicyProperties.State != null ? accountImmutabilityPolicyProperties.State.ToString() : null; } } public int? ImmutabilityPeriodSinceCreationInDays { get; set; } public string State { get; set; } } - - /// - /// wrapper class of StorageAccountSkuConversionStatus - /// - public class PSStorageAccountSkuConversionStatus - { - public string SkuConversionStatus { get; set; } - public string TargetSkuName { get; set; } - public string StartTime { get; set; } - public string EndTime { get; set; } - - public PSStorageAccountSkuConversionStatus(StorageAccountSkuConversionStatus status) - { - if (status != null) - { - this.SkuConversionStatus = status.SkuConversionStatus; - this.TargetSkuName = status.TargetSkuName; - this.StartTime = status.StartTime; - this.EndTime = status.EndTime; - } - } - } } diff --git a/src/Storage/Storage.Management/Storage.Management.csproj b/src/Storage/Storage.Management/Storage.Management.csproj index c938fa96f3ba..af2abb9c9c5f 100644 --- a/src/Storage/Storage.Management/Storage.Management.csproj +++ b/src/Storage/Storage.Management/Storage.Management.csproj @@ -14,6 +14,18 @@ $(LegacyAssemblyPrefix)$(PsModuleName) + + + + + + + + + + + + diff --git a/src/Storage/Storage.Management/StorageAccount/GetAzureStorageAccount.cs b/src/Storage/Storage.Management/StorageAccount/GetAzureStorageAccount.cs index f253649af99e..4348ba5dc21b 100644 --- a/src/Storage/Storage.Management/StorageAccount/GetAzureStorageAccount.cs +++ b/src/Storage/Storage.Management/StorageAccount/GetAzureStorageAccount.cs @@ -12,10 +12,11 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using Azure; +using Track2 = Azure.ResourceManager.Storage; +using Track2Models = Azure.ResourceManager.Storage.Models; using Microsoft.Azure.Commands.Management.Storage.Models; using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; -using Microsoft.Azure.Management.Storage; -using Microsoft.Azure.Management.Storage.Models; using Microsoft.Rest.Azure; using System.Management.Automation; @@ -88,45 +89,36 @@ public override void ExecuteCmdlet() if (string.IsNullOrEmpty(this.ResourceGroupName)) { - IPage storageAccounts = this.StorageClient.StorageAccounts.List(); - WriteStorageAccountList(storageAccounts); - - while (storageAccounts.NextPageLink != null) + Pageable accounts = this.StorageClientTrack2.ListStorageAccounts(); + foreach (Track2.StorageAccountResource account in accounts) { - storageAccounts = this.StorageClient.StorageAccounts.ListNext(storageAccounts.NextPageLink); - WriteStorageAccountList(storageAccounts); + WriteStorageAccount(account); } } else if (string.IsNullOrEmpty(this.Name)) { - IPage storageAccounts = this.StorageClient.StorageAccounts.ListByResourceGroup(this.ResourceGroupName); - WriteStorageAccountList(storageAccounts); - - while (storageAccounts.NextPageLink != null) + Pageable accounts = this.StorageClientTrack2.ListStorageAccounts(this.ResourceGroupName); + foreach (Track2.StorageAccountResource account in accounts) { - storageAccounts = this.StorageClient.StorageAccounts.ListByResourceGroupNext(storageAccounts.NextPageLink); - WriteStorageAccountList(storageAccounts); + WriteStorageAccount(account); } } else { // ParameterSet ensure can only set one of the following 2 parameters - StorageAccountExpand? expandproperties = null; + Track2Models.StorageAccountExpand? expandProperties = null; if (this.IncludeGeoReplicationStats) { - expandproperties = StorageAccountExpand.GeoReplicationStats; + expandProperties = Track2Models.StorageAccountExpand.GeoReplicationStats; } if (this.IncludeBlobRestoreStatus) { - expandproperties = StorageAccountExpand.BlobRestoreStatus; + expandProperties = Track2Models.StorageAccountExpand.BlobRestoreStatus; } + Track2.StorageAccountResource account = this.StorageClientTrack2.GetSingleStorageAccount( + this.ResourceGroupName, this.Name, expandProperties); - var storageAccount = this.StorageClient.StorageAccounts.GetProperties( - this.ResourceGroupName, - this.Name, - expandproperties); - - WriteStorageAccount(storageAccount); + WriteStorageAccount(account); } } } diff --git a/src/Storage/Storage.Management/StorageAccount/NewAzureStorageAccount.cs b/src/Storage/Storage.Management/StorageAccount/NewAzureStorageAccount.cs index 8399dc796b08..f87487718520 100644 --- a/src/Storage/Storage.Management/StorageAccount/NewAzureStorageAccount.cs +++ b/src/Storage/Storage.Management/StorageAccount/NewAzureStorageAccount.cs @@ -15,13 +15,16 @@ using System.Collections; using System.Management.Automation; using Microsoft.Azure.Commands.ResourceManager.Common.Tags; -using Microsoft.Azure.Management.Storage; -using Microsoft.Azure.Management.Storage.Models; -using StorageModels = Microsoft.Azure.Management.Storage.Models; using Microsoft.Azure.Commands.Management.Storage.Models; using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; using System; using System.Collections.Generic; +using Track2Models = Azure.ResourceManager.Storage.Models; +using Azure.ResourceManager.Models; +using Azure.Core; +using System.ComponentModel; +using System.Management.Automation.Remoting; +using Azure.ResourceManager.Storage; namespace Microsoft.Azure.Commands.Management.Storage { @@ -62,14 +65,15 @@ public class NewAzureStorageAccountCommand : StorageAccountBaseCmdlet ValueFromPipelineByPropertyName = true, HelpMessage = "Storage Account Sku Name.")] [Alias(StorageAccountTypeAlias, AccountTypeAlias, Account_TypeAlias)] - [ValidateSet(StorageModels.SkuName.StandardLRS, - StorageModels.SkuName.StandardZRS, - StorageModels.SkuName.StandardGRS, - StorageModels.SkuName.StandardRAGRS, - StorageModels.SkuName.PremiumLRS, - StorageModels.SkuName.PremiumZRS, - StorageModels.SkuName.StandardGZRS, - StorageModels.SkuName.StandardRAGZRS, + [ValidateSet( + SkuNameType.StandardLRS, + SkuNameType.StandardZRS, + SkuNameType.StandardGRS, + SkuNameType.StandardRagrs, + SkuNameType.PremiumLRS, + SkuNameType.PremiumZRS, + SkuNameType.StandardGzrs, + SkuNameType.StandardRagzrs, IgnoreCase = true)] public string SkuName { get; set; } @@ -85,13 +89,14 @@ public class NewAzureStorageAccountCommand : StorageAccountBaseCmdlet [Parameter( Mandatory = false, HelpMessage = "Storage Account Kind.")] - [ValidateSet(StorageModels.Kind.Storage, - StorageModels.Kind.StorageV2, - StorageModels.Kind.BlobStorage, - StorageModels.Kind.BlockBlobStorage, - StorageModels.Kind.FileStorage, + [ValidateSet( + StorageKindType.Storage, + StorageKindType.StorageV2, + StorageKindType.BlobStorage, + StorageKindType.BlockBlobStorage, + StorageKindType.FileStorage, IgnoreCase = true)] - [PSDefaultValue(Help = "StorageV2", Value = StorageModels.Kind.StorageV2)] + [PSDefaultValue(Help = "StorageV2", Value = StorageKindType.StorageV2)] public string Kind { get @@ -103,7 +108,7 @@ public string Kind kind = value; } } - private string kind = StorageModels.Kind.StorageV2; + private string kind = StorageKindType.StorageV2; [Parameter( Mandatory = false, @@ -162,10 +167,10 @@ public bool EnableHttpsTrafficOnly [Parameter( Mandatory = false, HelpMessage = "Set the new Storage Account Identity type, the idenetity is for use with key management services like Azure KeyVault.")] - [ValidateSet(AccountIdentityType.systemAssigned, - AccountIdentityType.userAssigned, - AccountIdentityType.systemAssignedUserAssigned, - AccountIdentityType.none, + [ValidateSet(AccountIdentityType.SystemAssigned, + AccountIdentityType.UserAssigned, + AccountIdentityType.SystemAssignedUserAssigned, + AccountIdentityType.None, IgnoreCase = true)] public string IdentityType { get; set; } @@ -241,8 +246,8 @@ public bool EnableAzureActiveDirectoryDomainServicesForFile [Parameter(Mandatory = false, HelpMessage = "Routing Choice defines the kind of network routing opted by the user. Possible values include: 'MicrosoftRouting', 'InternetRouting'")] [ValidateSet( - Microsoft.Azure.Management.Storage.Models.RoutingChoice.MicrosoftRouting, - Microsoft.Azure.Management.Storage.Models.RoutingChoice.InternetRouting, + RoutingChoiceType.MicrosoftRouting, + RoutingChoiceType.InternetRouting, IgnoreCase = true)] public string RoutingChoice; @@ -360,14 +365,16 @@ public bool EnableActiveDirectoryDomainServicesForFile public SwitchParameter AsJob { get; set; } [Parameter(Mandatory = false, HelpMessage = "Set the Encryption KeyType for Table. -Account, Table will be encrypted with account-scoped encryption key. -Service, Table will always be encrypted with Service-Managed keys. The default value is Service.")] - [ValidateSet(StorageModels.KeyType.Service, - StorageModels.KeyType.Account, + [ValidateSet( + KeyType.Service, + KeyType.Account, IgnoreCase = true)] public string EncryptionKeyTypeForTable { get; set; } [Parameter(Mandatory = false, HelpMessage = "Set the Encryption KeyType for Queue. -Account, Queue will be encrypted with account-scoped encryption key. -Service, Queue will always be encrypted with Service-Managed keys. The default value is Service.")] - [ValidateSet(StorageModels.KeyType.Service, - StorageModels.KeyType.Account, + [ValidateSet( + KeyType.Service, + KeyType.Account, IgnoreCase = true)] public string EncryptionKeyTypeForQueue { get; set; } @@ -379,7 +386,7 @@ public TimeSpan SasExpirationPeriod { get { - return sasExpirationPeriod is null? TimeSpan.Zero : sasExpirationPeriod.Value; + return sasExpirationPeriod is null ? TimeSpan.Zero : sasExpirationPeriod.Value; } set { @@ -422,9 +429,10 @@ public bool AllowBlobPublicAccess [Parameter( Mandatory = false, HelpMessage = "The minimum TLS version to be permitted on requests to storage. The default interpretation is TLS 1.0 for this property.")] - [ValidateSet(StorageModels.MinimumTlsVersion.TLS10, - StorageModels.MinimumTlsVersion.TLS11, - StorageModels.MinimumTlsVersion.TLS12, + [ValidateSet( + MinimumTlsVersionType.TLS10, + MinimumTlsVersionType.TLS11, + MinimumTlsVersionType.TLS12, IgnoreCase = true)] public string MinimumTlsVersion { @@ -543,77 +551,78 @@ public override void ExecuteCmdlet() { base.ExecuteCmdlet(); - CheckNameAvailabilityResult checkNameAvailabilityResult = this.StorageClient.StorageAccounts.CheckNameAvailability(this.Name); + Track2Models.CheckNameAvailabilityResult checkNameAvailabilityResult = + this.StorageClientTrack2.GetSubscription(this.SubscriptionId).CheckStorageAccountNameAvailability( + new Track2Models.StorageAccountCheckNameAvailabilityContent(this.Name)); + if (!checkNameAvailabilityResult.NameAvailable.Value) { throw new System.ArgumentException(checkNameAvailabilityResult.Message, "Name"); } - StorageAccountCreateParameters createParameters = new StorageAccountCreateParameters() - { - Location = this.Location, - Sku = new Sku(this.SkuName), - Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), - }; + Track2Models.StorageKind kind = string.IsNullOrEmpty(this.Kind) ? null : new Track2Models.StorageKind(this.Kind); + + Track2Models.StorageAccountCreateOrUpdateContent createContent = + new Track2Models.StorageAccountCreateOrUpdateContent(new Track2Models.StorageSku(this.SkuName), kind, this.Location); if (this.CustomDomainName != null) { - createParameters.CustomDomain = new CustomDomain() - { - Name = CustomDomainName, - UseSubDomainName = UseSubDomain - }; + + createContent.CustomDomain = new Track2Models.CustomDomain(this.CustomDomainName); + createContent.CustomDomain.UseSubDomainName = this.UseSubDomain; } else if (UseSubDomain != null) { throw new System.ArgumentException(string.Format("UseSubDomain must be set together with CustomDomainName.")); } - if (kind != null) - { - createParameters.Kind = kind; - } - if (this.AccessTier != null) { - createParameters.AccessTier = ParseAccessTier(AccessTier); + createContent.AccessTier = ParseAccessTier(this.AccessTier); } if (enableHttpsTrafficOnly != null) { - createParameters.EnableHttpsTrafficOnly = enableHttpsTrafficOnly; + createContent.EnableHttpsTrafficOnly = enableHttpsTrafficOnly; } if (AssignIdentity.IsPresent || this.UserAssignedIdentityId != null || this.IdentityType != null) { - createParameters.Identity = new Identity() { Type = StorageModels.IdentityType.SystemAssigned }; + createContent.Identity = + new ManagedServiceIdentity(ManagedServiceIdentityType.SystemAssigned); if (this.IdentityType != null) { - createParameters.Identity.Type = GetIdentityTypeString(this.IdentityType); + if (this.IdentityType == AccountIdentityType.SystemAssignedUserAssigned) + { + createContent.Identity.ManagedServiceIdentityType = new ManagedServiceIdentityType(AccountIdentityType.SystemAssignedUserAssignedTrack2); + } else + { + createContent.Identity.ManagedServiceIdentityType = new ManagedServiceIdentityType(this.IdentityType); + } } if (this.UserAssignedIdentityId != null) { - if (createParameters.Identity.Type != StorageModels.IdentityType.UserAssigned && createParameters.Identity.Type != StorageModels.IdentityType.SystemAssignedUserAssigned) + if (createContent.Identity.ManagedServiceIdentityType != AccountIdentityType.UserAssigned && createContent.Identity.ManagedServiceIdentityType != AccountIdentityType.SystemAssignedUserAssignedTrack2) { throw new ArgumentException("UserAssignIdentityId should only be specified when AssignIdentityType is UserAssigned or SystemAssignedUserAssigned.", "UserAssignIdentityId"); } - createParameters.Identity.UserAssignedIdentities = new Dictionary(); - createParameters.Identity.UserAssignedIdentities.Add(this.UserAssignedIdentityId, new UserAssignedIdentity()); + + createContent.Identity.UserAssignedIdentities.Add(new ResourceIdentifier(this.UserAssignedIdentityId), new global::Azure.ResourceManager.Models.UserAssignedIdentity()); + } } if (NetworkRuleSet != null) { - createParameters.NetworkRuleSet = PSNetworkRuleSet.ParseStorageNetworkRule(NetworkRuleSet); + createContent.NetworkRuleSet = PSNetworkRuleSet.ParseStorageNetworkRule(NetworkRuleSet); } if (enableHierarchicalNamespace != null) { - createParameters.IsHnsEnabled = enableHierarchicalNamespace; + createContent.IsHnsEnabled = enableHierarchicalNamespace; } - if (enableAzureActiveDirectoryDomainServicesForFile !=null || enableActiveDirectoryDomainServicesForFile != null) + if (enableAzureActiveDirectoryDomainServicesForFile != null || enableActiveDirectoryDomainServicesForFile != null) { - createParameters.AzureFilesIdentityBasedAuthentication = new AzureFilesIdentityBasedAuthentication(); if (enableAzureActiveDirectoryDomainServicesForFile != null && enableAzureActiveDirectoryDomainServicesForFile.Value) { - createParameters.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions = DirectoryServiceOptions.AADDS; + createContent.AzureFilesIdentityBasedAuthentication = new Track2Models.AzureFilesIdentityBasedAuthentication(Track2Models.DirectoryServiceOptions.Aadds); } else if (enableActiveDirectoryDomainServicesForFile != null && enableActiveDirectoryDomainServicesForFile.Value) { @@ -625,25 +634,23 @@ public override void ExecuteCmdlet() || string.IsNullOrEmpty(this.ActiveDirectoryAzureStorageSid) ) { - throw new System.ArgumentNullException("ActiveDirectoryDomainName, ActiveDirectoryNetBiosDomainName, ActiveDirectoryForestName, ActiveDirectoryDomainGuid, ActiveDirectoryDomainSid, ActiveDirectoryAzureStorageSid", + throw new System.ArgumentNullException("ActiveDirectoryDomainName, ActiveDirectoryNetBiosDomainName, ActiveDirectoryForestName, ActiveDirectoryDomainGuid, ActiveDirectoryDomainSid, ActiveDirectoryAzureStorageSid", "To enable ActiveDirectoryDomainServicesForFile, user must specify all of: ActiveDirectoryDomainName, ActiveDirectoryNetBiosDomainName, ActiveDirectoryForestName, ActiveDirectoryDomainGuid, ActiveDirectoryDomainSid, ActiveDirectoryAzureStorageSid."); } - createParameters.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions = DirectoryServiceOptions.AD; - createParameters.AzureFilesIdentityBasedAuthentication.ActiveDirectoryProperties = new ActiveDirectoryProperties() - { - DomainName = this.ActiveDirectoryDomainName, - NetBiosDomainName = this.ActiveDirectoryNetBiosDomainName, - ForestName = this.ActiveDirectoryForestName, - DomainGuid = this.ActiveDirectoryDomainGuid, - DomainSid = this.ActiveDirectoryDomainSid, - AzureStorageSid = this.ActiveDirectoryAzureStorageSid, - SamAccountName = this.ActiveDirectorySamAccountName, - AccountType = this.ActiveDirectoryAccountType - }; + + createContent.AzureFilesIdentityBasedAuthentication = + new Track2Models.AzureFilesIdentityBasedAuthentication(Track2Models.DirectoryServiceOptions.AD); + createContent.AzureFilesIdentityBasedAuthentication.ActiveDirectoryProperties = + new Track2Models.ActiveDirectoryProperties(this.ActiveDirectoryDomainName, this.ActiveDirectoryNetBiosDomainName, + this.ActiveDirectoryForestName, this.ActiveDirectoryDomainGuid, this.ActiveDirectoryDomainSid, this.ActiveDirectoryAzureStorageSid); + createContent.AzureFilesIdentityBasedAuthentication.ActiveDirectoryProperties.SamAccountName = this.ActiveDirectorySamAccountName; + createContent.AzureFilesIdentityBasedAuthentication.ActiveDirectoryProperties.AccountType = this.ActiveDirectoryAccountType; + } else { - createParameters.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions = DirectoryServiceOptions.None; + createContent.AzureFilesIdentityBasedAuthentication = + new Track2Models.AzureFilesIdentityBasedAuthentication(Track2Models.DirectoryServiceOptions.None); } } @@ -653,52 +660,63 @@ public override void ExecuteCmdlet() { throw new ArgumentException("'-DefaultSharePermission' need be specify together with '-EnableAzureActiveDirectoryDomainServicesForFile' or '-EnableActiveDirectoryDomainServicesForFile'."); } - if (createParameters.AzureFilesIdentityBasedAuthentication == null) + if (createContent.AzureFilesIdentityBasedAuthentication == null) { - createParameters.AzureFilesIdentityBasedAuthentication = new AzureFilesIdentityBasedAuthentication(); + createContent.AzureFilesIdentityBasedAuthentication = + new Track2Models.AzureFilesIdentityBasedAuthentication(Track2Models.DirectoryServiceOptions.None); } - createParameters.AzureFilesIdentityBasedAuthentication.DefaultSharePermission = this.DefaultSharePermission; + + createContent.AzureFilesIdentityBasedAuthentication.DefaultSharePermission = this.DefaultSharePermission; } if (this.EnableLargeFileShare.IsPresent) { - createParameters.LargeFileSharesState = LargeFileSharesState.Enabled; + createContent.LargeFileSharesState = Track2Models.LargeFileSharesState.Enabled; } - if(this.EncryptionKeyTypeForQueue != null || this.EncryptionKeyTypeForTable != null || this.RequireInfrastructureEncryption.IsPresent) + if (this.EncryptionKeyTypeForQueue != null || this.EncryptionKeyTypeForTable != null || this.RequireInfrastructureEncryption.IsPresent) { - createParameters.Encryption = new Encryption(); - createParameters.Encryption.KeySource = KeySource.MicrosoftStorage; + + createContent.Encryption = new Track2Models.Encryption(Track2Models.KeySource.MicrosoftStorage); + if (this.EncryptionKeyTypeForQueue != null || this.EncryptionKeyTypeForTable != null) { - createParameters.Encryption.Services = new EncryptionServices(); + createContent.Encryption.Services = new Track2Models.EncryptionServices(); + if (this.EncryptionKeyTypeForQueue != null) { - createParameters.Encryption.Services.Queue = new EncryptionService(keyType: this.EncryptionKeyTypeForQueue); + createContent.Encryption.Services.Queue = new Track2Models.EncryptionService + { + KeyType = this.EncryptionKeyTypeForQueue + }; } if (this.EncryptionKeyTypeForTable != null) { - createParameters.Encryption.Services.Table = new EncryptionService(keyType: this.EncryptionKeyTypeForTable); + createContent.Encryption.Services.Table = new Track2Models.EncryptionService + { + KeyType = this.EncryptionKeyTypeForTable + }; } } if (this.RequireInfrastructureEncryption.IsPresent) { - createParameters.Encryption.RequireInfrastructureEncryption = true; - if (createParameters.Encryption.Services is null) + createContent.Encryption.RequireInfrastructureEncryption = true; + + if (createContent.Encryption.Services == null) { - createParameters.Encryption.Services = new EncryptionServices(); - createParameters.Encryption.Services.Blob = new EncryptionService(); + createContent.Encryption.Services = new Track2Models.EncryptionServices(); + createContent.Encryption.Services.Blob = new Track2Models.EncryptionService(); } } } - if (this.KeyVaultUri !=null || this.KeyName != null || this.KeyVersion != null || this.KeyVaultUserAssignedIdentityId != null) + if (this.KeyVaultUri != null || this.KeyName != null || this.KeyVersion != null || this.KeyVaultUserAssignedIdentityId != null) { if ((this.KeyVaultUri != null && this.KeyName == null) || (this.KeyVaultUri == null && this.KeyName != null)) { - throw new ArgumentException("KeyVaultUri and KeyName must be specify together"); + throw new ArgumentException("KeyVaultUri and KeyName must be specify together"); } if (this.KeyVersion != null && (this.KeyVaultUri == null || this.KeyName == null)) { - throw new ArgumentException("KeyVersion can only be specified when specify KeyVaultUri and KeyName together.", "KeyVersion"); + throw new ArgumentException("KeyVersion can only be specified when specify KeyVaultUri and KeyName together.", "KeyVersion"); } if (this.KeyVaultUserAssignedIdentityId != null && (this.KeyVaultUri == null || this.KeyName == null)) @@ -706,98 +724,118 @@ public override void ExecuteCmdlet() throw new ArgumentException("KeyVaultUserAssignedIdentityId can only be specified when specify KeyVaultUri and KeyName together.", "KeyVaultUserAssignedIdentityId"); } - if (createParameters.Encryption == null) + + if (createContent.Encryption == null) { - createParameters.Encryption = new Encryption(); - createParameters.Encryption.KeySource = KeySource.MicrosoftStorage; + createContent.Encryption = new Track2Models.Encryption( + Track2Models.KeySource.MicrosoftStorage); } - if (createParameters.Encryption.Services is null) + if (createContent.Encryption.Services == null) { - createParameters.Encryption.Services = new EncryptionServices(); - createParameters.Encryption.Services.Blob = new EncryptionService(); + createContent.Encryption.Services = new Track2Models.EncryptionServices + { + Blob = new Track2Models.EncryptionService() + }; } if (this.KeyVaultUri != null || this.KeyName != null || this.KeyVersion != null) { - createParameters.Encryption.KeySource = KeySource.MicrosoftKeyvault; - createParameters.Encryption.KeyVaultProperties = new KeyVaultProperties(this.KeyName, this.KeyVersion, this.KeyVaultUri); + + createContent.Encryption.KeySource = Track2Models.KeySource.MicrosoftKeyvault; + createContent.Encryption.KeyVaultProperties = new Track2Models.KeyVaultProperties + { + KeyName = this.KeyName, + KeyVersion = this.KeyVersion, + KeyVaultUri = new Uri(this.KeyVaultUri) + }; } if (this.KeyVaultUserAssignedIdentityId != null) { - createParameters.Encryption.EncryptionIdentity = new EncryptionIdentity(); - createParameters.Encryption.EncryptionIdentity.EncryptionUserAssignedIdentity = this.KeyVaultUserAssignedIdentityId; + createContent.Encryption.EncryptionIdentity = new Track2Models.EncryptionIdentity + { + EncryptionUserAssignedIdentity = this.KeyVaultUserAssignedIdentityId + }; + } } if (this.minimumTlsVersion != null) { - createParameters.MinimumTlsVersion = this.minimumTlsVersion; + createContent.MinimumTlsVersion = new Track2Models.MinimumTlsVersion(this.minimumTlsVersion); } if (this.allowBlobPublicAccess != null) { - createParameters.AllowBlobPublicAccess = this.allowBlobPublicAccess; + createContent.AllowBlobPublicAccess = this.allowBlobPublicAccess; } if (this.RoutingChoice != null || this.publishMicrosoftEndpoint != null || this.publishInternetEndpoint != null) { - createParameters.RoutingPreference = new RoutingPreference(this.RoutingChoice, this.publishMicrosoftEndpoint, this.publishInternetEndpoint); + createContent.RoutingPreference = new Track2Models.RoutingPreference + { + RoutingChoice = new Track2Models.RoutingChoice(this.RoutingChoice), + PublishMicrosoftEndpoints = this.publishMicrosoftEndpoint, + PublishInternetEndpoints = this.publishInternetEndpoint + }; } if (allowSharedKeyAccess != null) { - createParameters.AllowSharedKeyAccess = allowSharedKeyAccess; + createContent.AllowSharedKeyAccess = this.allowSharedKeyAccess; } if (enableNfsV3 != null) { - createParameters.EnableNfsV3 = enableNfsV3; + createContent.EnableNfsV3 = this.enableNfsV3; } if (this.EdgeZone != null) { - createParameters.ExtendedLocation = new ExtendedLocation() + createContent.ExtendedLocation = new Track2Models.ExtendedLocation { - Type = ExtendedLocationTypes.EdgeZone, - Name = this.EdgeZone + Name = this.EdgeZone, + ExtendedLocationType = Track2Models.ExtendedLocationTypes.EdgeZone, }; } if (sasExpirationPeriod != null) { - createParameters.SasPolicy = new SasPolicy(sasExpirationPeriod.Value.ToString(@"d\.hh\:mm\:ss")); + createContent.SasPolicy = new Track2Models.SasPolicy(sasExpirationPeriod.Value.ToString(@"d\.hh\:mm\:ss"), Track2Models.ExpirationAction.Log); } if (keyExpirationPeriodInDay != null) { - createParameters.KeyPolicy = new KeyPolicy(keyExpirationPeriodInDay.Value); + createContent.KeyExpirationPeriodInDays = keyExpirationPeriodInDay.Value; + } - if(allowCrossTenantReplication != null) + if (allowCrossTenantReplication != null) { - createParameters.AllowCrossTenantReplication = allowCrossTenantReplication; + createContent.AllowCrossTenantReplication = this.allowCrossTenantReplication; } if (this.PublicNetworkAccess != null) { - createParameters.PublicNetworkAccess = this.PublicNetworkAccess; + createContent.PublicNetworkAccess = this.PublicNetworkAccess; } - if (EnableAccountLevelImmutability.IsPresent || this.immutabilityPeriod != null || this.ImmutabilityPolicyState != null) + if (EnableAccountLevelImmutability.IsPresent || this.immutabilityPeriod != null || this.ImmutabilityPolicyState != null) { if (!EnableAccountLevelImmutability.IsPresent) { throw new ArgumentException("ImmutabilityPeriod, ImmutabilityPolicyState and AllowProtectedAppendWrite, can only be specified with -EnableAccountLevelImmutability."); } - createParameters.ImmutableStorageWithVersioning = new ImmutableStorageAccount(); - createParameters.ImmutableStorageWithVersioning.Enabled = this.EnableAccountLevelImmutability.IsPresent; + + createContent.ImmutableStorageWithVersioning = new Track2Models.ImmutableStorageAccount + { + Enabled = this.EnableAccountLevelImmutability.IsPresent + }; + if (this.immutabilityPeriod != null || this.ImmutabilityPolicyState != null) { - createParameters.ImmutableStorageWithVersioning.ImmutabilityPolicy = new AccountImmutabilityPolicyProperties(); - createParameters.ImmutableStorageWithVersioning.ImmutabilityPolicy.ImmutabilityPeriodSinceCreationInDays = this.immutabilityPeriod; - createParameters.ImmutableStorageWithVersioning.ImmutabilityPolicy.State = this.ImmutabilityPolicyState; + createContent.ImmutableStorageWithVersioning.ImmutabilityPolicy = new Track2Models.AccountImmutabilityPolicyProperties + { + ImmutabilityPeriodSinceCreationInDays = this.ImmutabilityPeriod, + State = this.ImmutabilityPolicyState, + }; } } + var createAccountResponse = this.StorageClientTrack2.CreateStorageAccount(this.ResourceGroupName, this.Name, createContent); + var storageAccount = this.StorageClientTrack2.GetSingleStorageAccount(this.ResourceGroupName, this.Name); - var createAccountResponse = this.StorageClient.StorageAccounts.Create( - this.ResourceGroupName, - this.Name, - createParameters); - - var storageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name); + WriteStorageAccount(storageAccount); - this.WriteStorageAccount(storageAccount); } } } diff --git a/src/Storage/Storage.Management/StorageAccount/RemoveAzureStorageAccount.cs b/src/Storage/Storage.Management/StorageAccount/RemoveAzureStorageAccount.cs index d3302b8c3619..bac84078e813 100644 --- a/src/Storage/Storage.Management/StorageAccount/RemoveAzureStorageAccount.cs +++ b/src/Storage/Storage.Management/StorageAccount/RemoveAzureStorageAccount.cs @@ -13,8 +13,8 @@ // ---------------------------------------------------------------------------------- using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; -using Microsoft.Azure.Management.Storage; using System.Management.Automation; +using Azure; namespace Microsoft.Azure.Commands.Management.Storage { @@ -56,9 +56,7 @@ public override void ExecuteCmdlet() { if (this.Force || ShouldContinue(string.Format("Remove Storage Account '{0}' and all content in it", this.Name), "")) { - this.StorageClient.StorageAccounts.Delete( - this.ResourceGroupName, - this.Name); + this.StorageClientTrack2.GetStorageAccount(this.ResourceGroupName, this.Name).Delete(WaitUntil.Completed); } } } diff --git a/src/Storage/Storage.Management/StorageAccount/SetAzureStorageAccount.cs b/src/Storage/Storage.Management/StorageAccount/SetAzureStorageAccount.cs index 6ca2af72787f..fef32205e11c 100644 --- a/src/Storage/Storage.Management/StorageAccount/SetAzureStorageAccount.cs +++ b/src/Storage/Storage.Management/StorageAccount/SetAzureStorageAccount.cs @@ -16,12 +16,13 @@ using System.Collections.Generic; using System.Management.Automation; using Microsoft.Azure.Commands.ResourceManager.Common.Tags; -using Microsoft.Azure.Management.Storage; -using Microsoft.Azure.Management.Storage.Models; -using StorageModels = Microsoft.Azure.Management.Storage.Models; using Microsoft.Azure.Commands.Management.Storage.Models; using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; using System; +using Track2 = Azure.ResourceManager.Models; +using Track2Models = Azure.ResourceManager.Storage.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Azure.Core; namespace Microsoft.Azure.Commands.Management.Storage { @@ -78,13 +79,14 @@ public SwitchParameter Force ValueFromPipelineByPropertyName = true, HelpMessage = "Storage Account Sku Name.")] [Alias(StorageAccountTypeAlias, AccountTypeAlias, Account_TypeAlias)] - [ValidateSet(StorageModels.SkuName.StandardLRS, - StorageModels.SkuName.StandardZRS, - StorageModels.SkuName.StandardGRS, - StorageModels.SkuName.StandardRAGRS, - StorageModels.SkuName.PremiumLRS, - StorageModels.SkuName.StandardGZRS, - StorageModels.SkuName.StandardRAGZRS, + [ValidateSet( + SkuNameType.StandardLRS, + SkuNameType.StandardZRS, + SkuNameType.StandardGRS, + SkuNameType.StandardRagrs, + SkuNameType.PremiumLRS, + SkuNameType.StandardGzrs, + SkuNameType.StandardRagzrs, IgnoreCase = true)] public string SkuName { get; set; } @@ -192,10 +194,10 @@ public string KeyVaultUri [Parameter( Mandatory = false, HelpMessage = "Set the new Storage Account Identity type, the idenetity is for use with key management services like Azure KeyVault.")] - [ValidateSet(AccountIdentityType.systemAssigned, - AccountIdentityType.userAssigned, - AccountIdentityType.systemAssignedUserAssigned, - AccountIdentityType.none, + [ValidateSet(AccountIdentityType.SystemAssigned, + AccountIdentityType.UserAssigned, + AccountIdentityType.SystemAssignedUserAssigned, + AccountIdentityType.None, IgnoreCase = true)] public string IdentityType { get; set; } @@ -239,8 +241,8 @@ public bool EnableAzureActiveDirectoryDomainServicesForFile [Parameter(Mandatory = false, HelpMessage = "Routing Choice defines the kind of network routing opted by the user. Possible values include: 'MicrosoftRouting', 'InternetRouting'")] [ValidateSet( - Microsoft.Azure.Management.Storage.Models.RoutingChoice.MicrosoftRouting, - Microsoft.Azure.Management.Storage.Models.RoutingChoice.InternetRouting, + RoutingChoiceType.MicrosoftRouting, + RoutingChoiceType.InternetRouting, IgnoreCase = true)] [ValidateNotNullOrEmpty] public string RoutingChoice; @@ -261,7 +263,7 @@ public bool PublishMicrosoftEndpoint } } private bool? publishMicrosoftEndpoint = null; - + [Parameter( Mandatory = false, HelpMessage = "Indicates whether internet routing storage endpoints are to be published")] @@ -278,7 +280,7 @@ public bool PublishInternetEndpoint } } private bool? publishInternetEndpoint = null; - + [Parameter( Mandatory = true, HelpMessage = "Enable Azure Files Active Directory Domain Service Authentication for the storage account.", @@ -374,9 +376,10 @@ public bool AllowBlobPublicAccess [Parameter( Mandatory = false, HelpMessage = "The minimum TLS version to be permitted on requests to storage.")] - [ValidateSet(StorageModels.MinimumTlsVersion.TLS10, - StorageModels.MinimumTlsVersion.TLS11, - StorageModels.MinimumTlsVersion.TLS12, + [ValidateSet( + MinimumTlsVersionType.TLS10, + MinimumTlsVersionType.TLS11, + MinimumTlsVersionType.TLS12, IgnoreCase = true)] public string MinimumTlsVersion { @@ -389,7 +392,7 @@ public string MinimumTlsVersion minimumTlsVersion = value; } } - private string minimumTlsVersion = null; + private string minimumTlsVersion = null; [Parameter( Mandatory = false, @@ -508,25 +511,25 @@ public override void ExecuteCmdlet() { if (this.force || this.AccessTier == null || ShouldContinue("Changing the access tier may result in additional charges. See (http://go.microsoft.com/fwlink/?LinkId=786482) to learn more.", "")) { - StorageAccountUpdateParameters updateParameters = new StorageAccountUpdateParameters(); + + Track2Models.StorageAccountPatch storageAccountPatch = new Track2Models.StorageAccountPatch(); + if (this.SkuName != null) { - updateParameters.Sku = new Sku(this.SkuName); + storageAccountPatch.Sku = new Track2Models.StorageSku(new Track2Models.StorageSkuName(this.SkuName)); } if (this.Tag != null) { Dictionary tagDictionary = TagsConversionHelper.CreateTagDictionary(Tag, validate: true); - updateParameters.Tags = tagDictionary ?? new Dictionary(); + tagDictionary.ForEach(kv => storageAccountPatch.Tags.Add(kv.Key, kv.Value)); } if (this.CustomDomainName != null) { - updateParameters.CustomDomain = new CustomDomain() - { - Name = CustomDomainName, - UseSubDomainName = UseSubDomain - }; + storageAccountPatch.CustomDomain = new Track2Models.CustomDomain(this.CustomDomainName); + storageAccountPatch.CustomDomain.UseSubDomainName = this.UseSubDomain; + } else if (UseSubDomain != null) { @@ -535,37 +538,45 @@ public override void ExecuteCmdlet() if (this.AccessTier != null) { - updateParameters.AccessTier = ParseAccessTier(AccessTier); + storageAccountPatch.AccessTier = ParseAccessTier(this.AccessTier); } if (enableHttpsTrafficOnly != null) { - updateParameters.EnableHttpsTrafficOnly = enableHttpsTrafficOnly; + storageAccountPatch.EnableHttpsTrafficOnly = enableHttpsTrafficOnly; } if (AssignIdentity.IsPresent || this.UserAssignedIdentityId != null || this.IdentityType != null) { - updateParameters.Identity = new Identity() { Type = StorageModels.IdentityType.SystemAssigned }; + storageAccountPatch.Identity = new Track2.ManagedServiceIdentity(Track2.ManagedServiceIdentityType.SystemAssigned); if (this.IdentityType != null) { - updateParameters.Identity.Type = GetIdentityTypeString(this.IdentityType); + if (this.IdentityType == AccountIdentityType.SystemAssignedUserAssigned) + { + storageAccountPatch.Identity.ManagedServiceIdentityType = new Track2.ManagedServiceIdentityType(AccountIdentityType.SystemAssignedUserAssignedTrack2); + } else + { + storageAccountPatch.Identity.ManagedServiceIdentityType = new Track2.ManagedServiceIdentityType(this.IdentityType); + } } if (this.UserAssignedIdentityId != null) { - if (updateParameters.Identity.Type != StorageModels.IdentityType.UserAssigned && updateParameters.Identity.Type != StorageModels.IdentityType.SystemAssignedUserAssigned) + if (storageAccountPatch.Identity.ManagedServiceIdentityType != AccountIdentityType.UserAssigned && storageAccountPatch.Identity.ManagedServiceIdentityType != AccountIdentityType.SystemAssignedUserAssignedTrack2) { throw new ArgumentException("UserAssignIdentityId should only be specified when AssignIdentityType is UserAssigned or SystemAssignedUserAssigned.", "UserAssignIdentityId"); } - updateParameters.Identity.UserAssignedIdentities = new Dictionary(); - updateParameters.Identity.UserAssignedIdentities.Add(this.UserAssignedIdentityId, new UserAssignedIdentity()); - var accountProperties = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name); - if (accountProperties.Identity != null && accountProperties.Identity.UserAssignedIdentities != null && accountProperties.Identity.UserAssignedIdentities.Count > 0) + storageAccountPatch.Identity.UserAssignedIdentities.Add(new ResourceIdentifier(this.UserAssignedIdentityId), new global::Azure.ResourceManager.Models.UserAssignedIdentity()); + + var accountProperties = this.StorageClientTrack2.GetSingleStorageAccount(this.ResourceGroupName, this.Name); + + + if (accountProperties.Data.Identity != null && accountProperties.Data.Identity.UserAssignedIdentities != null && accountProperties.Data.Identity.UserAssignedIdentities.Count > 0) { - foreach (var uid in accountProperties.Identity.UserAssignedIdentities) + foreach (var uid in accountProperties.Data.Identity.UserAssignedIdentities) { - if (!uid.Key.Equals(this.UserAssignedIdentityId, StringComparison.OrdinalIgnoreCase)) + if (!uid.Key.ToString().Equals(this.UserAssignedIdentityId, StringComparison.OrdinalIgnoreCase)) { - updateParameters.Identity.UserAssignedIdentities.Add(uid.Key, null); + storageAccountPatch.Identity.UserAssignedIdentities.Add(uid.Key, null); } } } @@ -578,50 +589,61 @@ public override void ExecuteCmdlet() { keyvaultEncryption = true; } - updateParameters.Encryption = ParseEncryption(StorageEncryption, keyvaultEncryption, KeyName, KeyVersion, KeyVaultUri); + + storageAccountPatch.Encryption = ParseEncryption(StorageEncryption, keyvaultEncryption, KeyName, KeyVersion, KeyVaultUri); + if (this.KeyVaultUserAssignedIdentityId != null) { - updateParameters.Encryption.EncryptionIdentity = new EncryptionIdentity(); - updateParameters.Encryption.EncryptionIdentity.EncryptionUserAssignedIdentity = this.KeyVaultUserAssignedIdentityId; + storageAccountPatch.Encryption.EncryptionIdentity = new Track2Models.EncryptionIdentity + { + EncryptionUserAssignedIdentity = this.KeyVaultUserAssignedIdentityId + }; } } - + if (NetworkRuleSet != null) { - updateParameters.NetworkRuleSet = PSNetworkRuleSet.ParseStorageNetworkRule(NetworkRuleSet); + storageAccountPatch.NetworkRuleSet = PSNetworkRuleSet.ParseStorageNetworkRule(NetworkRuleSet); } if (UpgradeToStorageV2.IsPresent) { - updateParameters.Kind = Kind.StorageV2; + storageAccountPatch.Kind = Track2Models.StorageKind.StorageV2; } if (enableAzureActiveDirectoryDomainServicesForFile != null) { if (enableAzureActiveDirectoryDomainServicesForFile.Value) // enable AADDS { //if user want to enable AADDS, must first disable AD - var originStorageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name); - if (originStorageAccount.AzureFilesIdentityBasedAuthentication != null - && originStorageAccount.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions == DirectoryServiceOptions.AD) + + var originStorageAccount = this.StorageClientTrack2.GetSingleStorageAccount(this.ResourceGroupName, this.Name); + + if (originStorageAccount.Data.AzureFilesIdentityBasedAuthentication != null + && originStorageAccount.Data.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions == Track2Models.DirectoryServiceOptions.AD) { throw new System.ArgumentException("The Storage account already enabled ActiveDirectoryDomainServicesForFile, please disable it by run this cmdlets with \"-EnableActiveDirectoryDomainServicesForFile $false\" before enable AzureActiveDirectoryDomainServicesForFile."); } - updateParameters.AzureFilesIdentityBasedAuthentication = new AzureFilesIdentityBasedAuthentication(); - updateParameters.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions = DirectoryServiceOptions.AADDS; + + storageAccountPatch.AzureFilesIdentityBasedAuthentication = + new Track2Models.AzureFilesIdentityBasedAuthentication(Track2Models.DirectoryServiceOptions.Aadds); + } else //Disable AADDS { // Only disable AADDS; else keep unchanged - var originStorageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name); - if (originStorageAccount.AzureFilesIdentityBasedAuthentication == null - || originStorageAccount.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions == DirectoryServiceOptions.AADDS) + + var originStorageAccount = this.StorageClientTrack2.GetSingleStorageAccount(this.ResourceGroupName, this.Name); + + if (originStorageAccount.Data.AzureFilesIdentityBasedAuthentication == null + || originStorageAccount.Data.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions == Track2Models.DirectoryServiceOptions.Aadds) { - updateParameters.AzureFilesIdentityBasedAuthentication = new AzureFilesIdentityBasedAuthentication(); - updateParameters.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions = DirectoryServiceOptions.None; + storageAccountPatch.AzureFilesIdentityBasedAuthentication = + new Track2Models.AzureFilesIdentityBasedAuthentication(Track2Models.DirectoryServiceOptions.None); } else { - updateParameters.AzureFilesIdentityBasedAuthentication = originStorageAccount.AzureFilesIdentityBasedAuthentication; + storageAccountPatch.AzureFilesIdentityBasedAuthentication = originStorageAccount.Data.AzureFilesIdentityBasedAuthentication; + } } } @@ -643,26 +665,26 @@ public override void ExecuteCmdlet() } //if user want to enable AD, must first disable AADDS - var originStorageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name); - if (originStorageAccount.AzureFilesIdentityBasedAuthentication != null - && originStorageAccount.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions == DirectoryServiceOptions.AADDS) + + var originStorageAccount = this.StorageClientTrack2.GetSingleStorageAccount(this.ResourceGroupName, this.Name); + + + + if (originStorageAccount.Data.AzureFilesIdentityBasedAuthentication != null + && originStorageAccount.Data.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions == Track2Models.DirectoryServiceOptions.Aadds) { throw new System.ArgumentException("The Storage account already enabled AzureActiveDirectoryDomainServicesForFile, please disable it by run this cmdlets with \"-EnableAzureActiveDirectoryDomainServicesForFile $false\" before enable ActiveDirectoryDomainServicesForFile."); } - updateParameters.AzureFilesIdentityBasedAuthentication = new AzureFilesIdentityBasedAuthentication(); - updateParameters.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions = DirectoryServiceOptions.AD; - updateParameters.AzureFilesIdentityBasedAuthentication.ActiveDirectoryProperties = new ActiveDirectoryProperties() - { - DomainName = this.ActiveDirectoryDomainName, - NetBiosDomainName = this.ActiveDirectoryNetBiosDomainName, - ForestName = this.ActiveDirectoryForestName, - DomainGuid = this.ActiveDirectoryDomainGuid, - DomainSid = this.ActiveDirectoryDomainSid, - AzureStorageSid = this.ActiveDirectoryAzureStorageSid, - SamAccountName = this.ActiveDirectorySamAccountName, - AccountType = this.ActiveDirectoryAccountType - }; + storageAccountPatch.AzureFilesIdentityBasedAuthentication = + new Track2Models.AzureFilesIdentityBasedAuthentication(Track2Models.DirectoryServiceOptions.AD); + + storageAccountPatch.AzureFilesIdentityBasedAuthentication.ActiveDirectoryProperties = + new Track2Models.ActiveDirectoryProperties(this.ActiveDirectoryDomainName, this.ActiveDirectoryNetBiosDomainName, + this.ActiveDirectoryForestName, this.ActiveDirectoryDomainGuid, this.ActiveDirectoryDomainSid, this.ActiveDirectoryAzureStorageSid); + storageAccountPatch.AzureFilesIdentityBasedAuthentication.ActiveDirectoryProperties.SamAccountName = this.ActiveDirectorySamAccountName; + storageAccountPatch.AzureFilesIdentityBasedAuthentication.ActiveDirectoryProperties.AccountType = this.ActiveDirectoryAccountType; + } else // Disable AD { @@ -680,77 +702,97 @@ public override void ExecuteCmdlet() } // Only disable AD; else keep unchanged - var originStorageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name); - if (originStorageAccount.AzureFilesIdentityBasedAuthentication == null - || originStorageAccount.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions == DirectoryServiceOptions.AD) + var originStorageAccount = this.StorageClientTrack2.GetSingleStorageAccount(this.ResourceGroupName, this.Name); + + if (originStorageAccount.Data.AzureFilesIdentityBasedAuthentication == null + || originStorageAccount.Data.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions == Track2Models.DirectoryServiceOptions.AD) { - updateParameters.AzureFilesIdentityBasedAuthentication = new AzureFilesIdentityBasedAuthentication(); - updateParameters.AzureFilesIdentityBasedAuthentication.DirectoryServiceOptions = DirectoryServiceOptions.None; + storageAccountPatch.AzureFilesIdentityBasedAuthentication = + new Track2Models.AzureFilesIdentityBasedAuthentication(Track2Models.DirectoryServiceOptions.AD); + } else { - updateParameters.AzureFilesIdentityBasedAuthentication = originStorageAccount.AzureFilesIdentityBasedAuthentication; + storageAccountPatch.AzureFilesIdentityBasedAuthentication = originStorageAccount.Data.AzureFilesIdentityBasedAuthentication; + } } } if (this.DefaultSharePermission != null) { - if (updateParameters.AzureFilesIdentityBasedAuthentication == null) + if (storageAccountPatch.AzureFilesIdentityBasedAuthentication == null) { - updateParameters.AzureFilesIdentityBasedAuthentication = new AzureFilesIdentityBasedAuthentication(); + storageAccountPatch.AzureFilesIdentityBasedAuthentication = + new Track2Models.AzureFilesIdentityBasedAuthentication( + Track2Models.DirectoryServiceOptions.None); } - updateParameters.AzureFilesIdentityBasedAuthentication.DefaultSharePermission = this.DefaultSharePermission; + + storageAccountPatch.AzureFilesIdentityBasedAuthentication.DefaultSharePermission = this.DefaultSharePermission; } if (this.EnableLargeFileShare.IsPresent) { - updateParameters.LargeFileSharesState = LargeFileSharesState.Enabled; + storageAccountPatch.LargeFileSharesState = Track2Models.LargeFileSharesState.Enabled; } if (this.minimumTlsVersion != null) { - updateParameters.MinimumTlsVersion = this.minimumTlsVersion; + storageAccountPatch.MinimumTlsVersion = this.minimumTlsVersion; } if (this.allowBlobPublicAccess != null) { - updateParameters.AllowBlobPublicAccess = this.allowBlobPublicAccess; + storageAccountPatch.AllowBlobPublicAccess = this.allowBlobPublicAccess; } if (this.RoutingChoice != null || this.publishMicrosoftEndpoint != null || this.publishInternetEndpoint != null) - { - updateParameters.RoutingPreference = new RoutingPreference(this.RoutingChoice, this.publishMicrosoftEndpoint, this.publishInternetEndpoint); + { + storageAccountPatch.RoutingPreference = new Track2Models.RoutingPreference + { + RoutingChoice = this.RoutingChoice, + PublishInternetEndpoints = this.publishInternetEndpoint, + PublishMicrosoftEndpoints = this.publishMicrosoftEndpoint, + + }; } if (allowSharedKeyAccess != null) { - updateParameters.AllowSharedKeyAccess = allowSharedKeyAccess; + storageAccountPatch.AllowSharedKeyAccess = this.allowSharedKeyAccess; } if (sasExpirationPeriod != null) { - updateParameters.SasPolicy = new SasPolicy(sasExpirationPeriod.Value.ToString(@"d\.hh\:mm\:ss")); + storageAccountPatch.SasPolicy = new Track2Models.SasPolicy( + this.sasExpirationPeriod.Value.ToString(@"d\.hh\:mm\:ss"), Track2Models.ExpirationAction.Log); } if (keyExpirationPeriodInDay != null) { - updateParameters.KeyPolicy = new KeyPolicy(keyExpirationPeriodInDay.Value); + + storageAccountPatch.KeyExpirationPeriodInDays = keyExpirationPeriodInDay.Value; + + } if (allowCrossTenantReplication != null) { - updateParameters.AllowCrossTenantReplication = allowCrossTenantReplication; + storageAccountPatch.AllowCrossTenantReplication = this.allowCrossTenantReplication; } if (this.PublicNetworkAccess != null) { - updateParameters.PublicNetworkAccess = this.PublicNetworkAccess; + storageAccountPatch.PublicNetworkAccess = this.PublicNetworkAccess; } - if(this.immutabilityPeriod !=null || this.ImmutabilityPolicyState != null) + if (this.immutabilityPeriod != null || this.ImmutabilityPolicyState != null) { - updateParameters.ImmutableStorageWithVersioning = new ImmutableStorageAccount(); - updateParameters.ImmutableStorageWithVersioning.ImmutabilityPolicy = new AccountImmutabilityPolicyProperties(); - updateParameters.ImmutableStorageWithVersioning.ImmutabilityPolicy.ImmutabilityPeriodSinceCreationInDays = this.immutabilityPeriod; - updateParameters.ImmutableStorageWithVersioning.ImmutabilityPolicy.State = this.ImmutabilityPolicyState; + storageAccountPatch.ImmutableStorageWithVersioning = new Track2Models.ImmutableStorageAccount(); + storageAccountPatch.ImmutableStorageWithVersioning.ImmutabilityPolicy = new Track2Models.AccountImmutabilityPolicyProperties(); + if (this.immutabilityPeriod != null) + { + storageAccountPatch.ImmutableStorageWithVersioning.ImmutabilityPolicy.ImmutabilityPeriodSinceCreationInDays = this.immutabilityPeriod; + } + if (this.ImmutabilityPolicyState != null) + { + storageAccountPatch.ImmutableStorageWithVersioning.ImmutabilityPolicy.State = this.ImmutabilityPolicyState; + } + } - var updatedAccountResponse = this.StorageClient.StorageAccounts.Update( - this.ResourceGroupName, - this.Name, - updateParameters); - var storageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name); + var updatedAccountResponse = this.StorageClientTrack2.UpdateStorageAccount(this.ResourceGroupName, this.Name, storageAccountPatch); + var storageAccount = this.StorageClientTrack2.GetSingleStorageAccount(this.ResourceGroupName, this.Name, null); WriteStorageAccount(storageAccount); } diff --git a/src/Storage/Storage.Management/StorageAccount/StorageAccountBaseCmdlet.cs b/src/Storage/Storage.Management/StorageAccount/StorageAccountBaseCmdlet.cs index 998d0583315a..68c2bbac4aba 100644 --- a/src/Storage/Storage.Management/StorageAccount/StorageAccountBaseCmdlet.cs +++ b/src/Storage/Storage.Management/StorageAccount/StorageAccountBaseCmdlet.cs @@ -12,6 +12,11 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using Azure.Core; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Track2 = Azure.ResourceManager.Storage; +using Track2Models = Azure.ResourceManager.Storage.Models; using Microsoft.Azure.Commands.Management.Storage.Models; using Microsoft.Azure.Commands.ResourceManager.Common; using Microsoft.Azure.Management.Storage; @@ -73,12 +78,54 @@ protected struct ManagementPolicyAction protected struct AccountIdentityType { - internal const string systemAssigned = "SystemAssigned"; - internal const string userAssigned = "UserAssigned"; - internal const string systemAssignedUserAssigned = "SystemAssignedUserAssigned"; - internal const string none = "None"; + internal const string SystemAssigned = "SystemAssigned"; + internal const string UserAssigned = "UserAssigned"; + internal const string SystemAssignedUserAssigned = "SystemAssignedUserAssigned"; + internal const string SystemAssignedUserAssignedTrack2 = "SystemAssigned, UserAssigned"; + internal const string None = "None"; + } + + protected struct RoutingChoiceType + { + internal const string MicrosoftRouting = "MicrosoftRouting"; + internal const string InternetRouting = "InternetRouting"; + } + + protected struct KeyType + { + internal const string Service = "Service"; + internal const string Account = "Account"; + } + + protected struct SkuNameType + { + internal const string StandardLRS = "Standard_LRS"; + internal const string StandardGRS = "Standard_GRS"; + internal const string StandardRagrs = "Standard_RAGRS"; + internal const string StandardZRS = "Standard_ZRS"; + internal const string PremiumLRS = "Premium_LRS"; + internal const string PremiumZRS = "Premium_ZRS"; + internal const string StandardGzrs = "Standard_GZRS"; + internal const string StandardRagzrs = "Standard_RAGZRS"; + } + + protected struct StorageKindType + { + internal const string Storage = "Storage"; + internal const string StorageV2 = "StorageV2"; + internal const string BlobStorage = "BlobStorage"; + internal const string FileStorage = "FileStorage"; + internal const string BlockBlobStorage = "BlockBlobStorage"; + } + + protected struct MinimumTlsVersionType + { + internal const string TLS10 = "TLS1_0"; + internal const string TLS11 = "TLS1_1"; + internal const string TLS12 = "TLS1_2"; } + [Flags] public enum EncryptionSupportServiceEnum { @@ -113,6 +160,19 @@ public IStorageManagementClient StorageClient set { storageClientWrapper = new StorageManagementClientWrapper(value); } } + private Track2StorageManagementClient _track2StorageManagementClient; + public Track2StorageManagementClient StorageClientTrack2 + { + get + { + return _track2StorageManagementClient ?? (_track2StorageManagementClient = new Track2StorageManagementClient( + Microsoft.Azure.Commands.Common.Authentication.AzureSession.Instance.ClientFactory, + DefaultContext)); + } + + set { _track2StorageManagementClient = value; } + } + public string SubscriptionId { get @@ -121,42 +181,40 @@ public string SubscriptionId } } - protected static AccessTier ParseAccessTier(string accessTier) + + protected static Track2Models.AccessTier ParseAccessTier(string accessTier) { - AccessTier returnAccessTier; - if (!Enum.TryParse(accessTier, true, out returnAccessTier)) + Track2Models.AccessTier returnAccessTier; + if (!Enum.TryParse(accessTier, true, out returnAccessTier)) { throw new ArgumentOutOfRangeException("AccessTier"); } return returnAccessTier; } - protected static Encryption ParseEncryption(bool storageEncryption = false, bool keyVaultEncryption = false, string keyName = null, string keyVersion = null, string keyVaultUri = null) + protected static Track2Models.Encryption ParseEncryption(bool storageEncryption = false, bool keyVaultEncryption = false, string keyName = null, string keyVersion = null, string keyVaultUri = null) { - Encryption accountEncryption = new Encryption(); + Track2Models.Encryption accountEncryption = + new Track2Models.Encryption(Track2Models.KeySource.MicrosoftKeyvault); if (storageEncryption) { - accountEncryption.KeySource = "Microsoft.Storage"; + accountEncryption.KeySource = Track2Models.KeySource.MicrosoftStorage; } if (keyVaultEncryption) { - accountEncryption.KeySource = "Microsoft.Keyvault"; - accountEncryption.KeyVaultProperties = new KeyVaultProperties(keyName, keyVersion, keyVaultUri); + accountEncryption.KeySource = Track2Models.KeySource.MicrosoftKeyvault; + accountEncryption.KeyVaultProperties = new Track2Models.KeyVaultProperties(); + accountEncryption.KeyVaultProperties.KeyName = keyName; + accountEncryption.KeyVaultProperties.KeyVersion = keyVersion; + accountEncryption.KeyVaultProperties.KeyVaultUri = new Uri(keyVaultUri); } return accountEncryption; } - protected void WriteStorageAccount(StorageModels.StorageAccount storageAccount) - { - WriteObject(PSStorageAccount.Create(storageAccount, this.StorageClient)); - } - - protected void WriteStorageAccountList(IEnumerable storageAccounts) + protected void WriteStorageAccount(Track2.StorageAccountResource storageAccountResource) { - List output = new List(); - storageAccounts.ForEach(storageAccount => output.Add(PSStorageAccount.Create(storageAccount, this.StorageClient))); - WriteObject(output, true); + WriteObject(PSStorageAccount.Create(storageAccountResource, this.StorageClientTrack2)); } public static string GetIdentityTypeString(string inputIdentityType) @@ -167,21 +225,21 @@ public static string GetIdentityTypeString(string inputIdentityType) } // The parameter validate set make sure the value must be systemAssigned or userAssigned or systemAssignedUserAssigned or None - if (inputIdentityType.ToLower() == AccountIdentityType.systemAssigned.ToLower()) + if (inputIdentityType.ToLower() == AccountIdentityType.SystemAssigned.ToLower()) { - return IdentityType.SystemAssigned; + return AccountIdentityType.SystemAssigned; } - if (inputIdentityType.ToLower() == AccountIdentityType.userAssigned.ToLower()) + if (inputIdentityType.ToLower() == AccountIdentityType.UserAssigned.ToLower()) { - return IdentityType.UserAssigned; + return AccountIdentityType.UserAssigned; } - if (inputIdentityType.ToLower() == AccountIdentityType.systemAssignedUserAssigned.ToLower()) + if (inputIdentityType.ToLower() == AccountIdentityType.SystemAssignedUserAssigned.ToLower()) { - return IdentityType.SystemAssignedUserAssigned; + return AccountIdentityType.SystemAssignedUserAssigned; } - if (inputIdentityType.ToLower() == AccountIdentityType.none.ToLower()) + if (inputIdentityType.ToLower() == AccountIdentityType.None.ToLower()) { - return IdentityType.None; + return AccountIdentityType.None; } throw new ArgumentException("The value for AssignIdentityType is not valid, the valid value are: \"None\", \"SystemAssigned\", \"UserAssigned\", or \"SystemAssignedUserAssigned\"", "AssignIdentityType"); } diff --git a/src/Storage/Storage.Management/Track2StorageManagementClient.cs b/src/Storage/Storage.Management/Track2StorageManagementClient.cs new file mode 100644 index 000000000000..18390527fbd7 --- /dev/null +++ b/src/Storage/Storage.Management/Track2StorageManagementClient.cs @@ -0,0 +1,151 @@ +using Azure.ResourceManager; +using Track2 = Azure.ResourceManager.Storage; +using Track2Model = Azure.ResourceManager.Storage.Models; +using Azure.ResourceManager.Resources; + +using Microsoft.Azure.Commands.Common.Authentication; +using Microsoft.Azure.Commands.Common.Authentication.Abstractions; + +using System.Collections.Generic; +using Azure.ResourceManager.Storage; +using Azure; +using Azure.Core; +using Microsoft.Azure.Commands.Management.Storage.Models; +using Azure.ResourceManager.Storage.Models; +using Microsoft.Azure.Storage.Blob.Protocol; +using System.Diagnostics.Contracts; + +namespace Microsoft.Azure.Commands.Management.Storage +{ + public class Track2StorageManagementClient + { + private ArmClient _armClient; + private string _subscription; + private IClientFactory _clientFactory; + + public Track2StorageManagementClient(IClientFactory clientFactory, IAzureContext context) + { + _clientFactory = clientFactory; + _armClient = _clientFactory.CreateArmClient(context, AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId); + _subscription = context.Subscription.Id; + } + + /// + /// Get resource group instance + /// + /// + public ResourceGroupResource GetResourceGroup(string resourcegroup) => + _armClient.GetResourceGroupResource(new global::Azure.Core.ResourceIdentifier( + string.Format("/subscriptions/{0}/resourceGroups/{1}", _subscription, resourcegroup))); + + + public SubscriptionResource GetSubscription(string subscription) => + _armClient.GetSubscriptionResource(new global::Azure.Core.ResourceIdentifier( + string.Format("/subscriptions/{0}", subscription))); + + /// + /// List accounts from subscription + /// + /// + public Pageable ListStorageAccounts() => + _armClient.GetSubscriptionResource(new global::Azure.Core.ResourceIdentifier( + string.Format("/subscriptions/{0}", _subscription))) + .GetStorageAccounts(); + + /// + /// List accounts from Resource group + /// + public Pageable ListStorageAccounts(string resourcegroup) => + GetResourceGroup(resourcegroup).GetStorageAccounts().GetAll(); + + /// + /// Get single storage account with no data + /// + public Track2.StorageAccountResource GetStorageAccount(string resourcegroup, string storageAccountName) => + _armClient.GetStorageAccountResource(Track2.StorageAccountResource.CreateResourceIdentifier(_subscription, resourcegroup, storageAccountName)); + + /// + /// Get a single Storage account with its data + /// + public Track2.StorageAccountResource GetSingleStorageAccount(string resourceGroup, string storageAccountName, StorageAccountExpand? expand = null) => + GetResourceGroup(resourceGroup).GetStorageAccounts().Get(storageAccountName, expand); + + /// + /// Create a Storage account + /// + public StorageAccountResource CreateStorageAccount(string resourceGroup, string storageAccountName, StorageAccountCreateOrUpdateContent content) => + GetResourceGroup(resourceGroup).GetStorageAccounts().CreateOrUpdate(WaitUntil.Completed, storageAccountName, content).Value; + + /// + /// Update a Storage account + /// + public Track2.StorageAccountResource UpdateStorageAccount(string resourcegroup, string storageAccountName, StorageAccountPatch patch) => + GetStorageAccount(resourcegroup, storageAccountName).Update(patch); + + /// + /// Get BlobServiceResource with subscription, resource group name, and storage account name + /// + public Track2.BlobServiceResource GetBlobServiceResource(string resourceGroupName, string storageAccountName) => + _armClient.GetBlobServiceResource(Track2.BlobServiceResource.CreateResourceIdentifier(_subscription, resourceGroupName, storageAccountName)); + + /// + /// Get BlobContainerResource with subscription, resource group name, and storage account name + /// + public Track2.BlobContainerResource GetBlobContainerResource(string resourceGroupName, string storageAccountName, string containerName) => + _armClient.GetBlobContainerResource(Track2.BlobContainerResource.CreateResourceIdentifier(_subscription, resourceGroupName, storageAccountName, containerName)); + + /// + /// List blob containers under a resource group and storage account + /// + public Track2.BlobContainerCollection GetBlobContainers(string resourceGroupName, string storageAccountName) => + GetBlobServiceResource(resourceGroupName, storageAccountName).GetBlobContainers(); + + /// + /// Get a blob container under a resource group and storage account with container name + /// + public Track2.BlobContainerResource GetBlobContainer(string resourceGroupName, string storageAccountName, string containerName) => + GetBlobContainerResource(resourceGroupName, storageAccountName, containerName).Get(); + + /// + /// Update a blob container + /// + public Track2.BlobContainerResource UpdateBlobContainer(string resourceGroupName, string storageAccountName, string containerName, BlobContainerData data) => + GetBlobContainerResource(resourceGroupName, storageAccountName, containerName).Update(data); + + /// + /// Create a blob container + /// + public Track2.BlobContainerResource CreateBlobContainer(string resourceGroupName, string storageAccountName, string containerName, BlobContainerData data) => + GetBlobContainers(resourceGroupName, storageAccountName).CreateOrUpdate(WaitUntil.Completed, containerName, data).Value; + + /// + /// Get immutability policy of a blob container + /// + public Track2.ImmutabilityPolicyResource GetImmutabilityPolicy(string resourceGroupName, string storageAccountName, string containerName, string etag) => + GetBlobContainerResource(resourceGroupName, storageAccountName, containerName).GetImmutabilityPolicy().Get(etag); + + /// + /// Lock immutability policy of a blob container + /// + public Track2.ImmutabilityPolicyResource LockImmutabilityPolicy(string resourceGroupName, string storageAccountName, string containerName, string etag) => + GetBlobContainerResource(resourceGroupName, storageAccountName, containerName).GetImmutabilityPolicy().LockImmutabilityPolicy(etag); + + /// + /// Create immutability policy for a blob container + /// + public Track2.ImmutabilityPolicyResource CreateImmutabilityPolicy(string resourceGroupName, string storageAccountName, string containerName, ImmutabilityPolicyData data, string etag) => + GetBlobContainerResource(resourceGroupName, storageAccountName, containerName).GetImmutabilityPolicy().CreateOrUpdate(WaitUntil.Completed, data, etag).Value; + + /// + /// Extend immutability policy for a blob container + /// + public Track2.ImmutabilityPolicyResource ExtendImmutabilityPolicy(string resourceGroupName, string storageAccountName, string containerName, ImmutabilityPolicyData data, string etag) => + GetBlobContainerResource(resourceGroupName, storageAccountName, containerName).GetImmutabilityPolicy().ExtendImmutabilityPolicy(etag, data); + + /// + /// Delete immutability policy for a blob container + /// + public Track2.ImmutabilityPolicyResource DeleteImmutabilityPolicy(string resourceGroupName, string storageAccountName, string containerName, string etag) => + GetBlobContainerResource(resourceGroupName, storageAccountName, containerName).GetImmutabilityPolicy().Delete(WaitUntil.Completed, etag).Value; + } +} \ No newline at end of file