internal static StorageAccountData DeserializeStorageAccountData(JsonElement element)
        {
            Optional <Models.Sku>        sku              = default;
            Optional <Kind>              kind             = default;
            Optional <Identity>          identity         = default;
            Optional <ExtendedLocation>  extendedLocation = default;
            IDictionary <string, string> tags             = default;
            Location                     location         = default;
            ResourceIdentifier           id   = default;
            string                       name = default;
            ResourceType                 type = default;
            Optional <ProvisioningState> provisioningState   = default;
            Optional <Endpoints>         primaryEndpoints    = default;
            Optional <string>            primaryLocation     = default;
            Optional <AccountStatus>     statusOfPrimary     = default;
            Optional <DateTimeOffset>    lastGeoFailoverTime = default;
            Optional <string>            secondaryLocation   = default;
            Optional <AccountStatus>     statusOfSecondary   = default;
            Optional <DateTimeOffset>    creationTime        = default;
            Optional <CustomDomain>      customDomain        = default;
            Optional <SasPolicy>         sasPolicy           = default;
            Optional <KeyPolicy>         keyPolicy           = default;
            Optional <KeyCreationTime>   keyCreationTime     = default;
            Optional <Endpoints>         secondaryEndpoints  = default;
            Optional <Encryption>        encryption          = default;
            Optional <AccessTier>        accessTier          = default;
            Optional <AzureFilesIdentityBasedAuthentication> azureFilesIdentityBasedAuthentication = default;
            Optional <bool>                 supportsHttpsTrafficOnly = default;
            Optional <NetworkRuleSet>       networkAcls          = default;
            Optional <bool>                 isHnsEnabled         = default;
            Optional <GeoReplicationStats>  geoReplicationStats  = default;
            Optional <bool>                 failoverInProgress   = default;
            Optional <LargeFileSharesState> largeFileSharesState = default;
            Optional <IReadOnlyList <PrivateEndpointConnectionData> > privateEndpointConnections = default;
            Optional <RoutingPreference> routingPreference = default;
            Optional <BlobRestoreStatus> blobRestoreStatus = default;
            Optional <bool> allowBlobPublicAccess          = default;
            Optional <MinimumTlsVersion> minimumTlsVersion = default;
            Optional <bool> allowSharedKeyAccess           = default;
            Optional <bool> isNfsV3Enabled = default;
            Optional <bool> allowCrossTenantReplication = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("sku"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    sku = Models.Sku.DeserializeSku(property.Value);
                    continue;
                }
                if (property.NameEquals("kind"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    kind = new Kind(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("identity"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    identity = Identity.DeserializeIdentity(property.Value);
                    continue;
                }
                if (property.NameEquals("extendedLocation"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    extendedLocation = ExtendedLocation.DeserializeExtendedLocation(property.Value);
                    continue;
                }
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("provisioningState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            provisioningState = property0.Value.GetString().ToProvisioningState();
                            continue;
                        }
                        if (property0.NameEquals("primaryEndpoints"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            primaryEndpoints = Endpoints.DeserializeEndpoints(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("primaryLocation"))
                        {
                            primaryLocation = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("statusOfPrimary"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            statusOfPrimary = property0.Value.GetString().ToAccountStatus();
                            continue;
                        }
                        if (property0.NameEquals("lastGeoFailoverTime"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            lastGeoFailoverTime = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("secondaryLocation"))
                        {
                            secondaryLocation = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("statusOfSecondary"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            statusOfSecondary = property0.Value.GetString().ToAccountStatus();
                            continue;
                        }
                        if (property0.NameEquals("creationTime"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            creationTime = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("customDomain"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            customDomain = CustomDomain.DeserializeCustomDomain(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("sasPolicy"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            sasPolicy = SasPolicy.DeserializeSasPolicy(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("keyPolicy"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            keyPolicy = KeyPolicy.DeserializeKeyPolicy(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("keyCreationTime"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            keyCreationTime = KeyCreationTime.DeserializeKeyCreationTime(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("secondaryEndpoints"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            secondaryEndpoints = Endpoints.DeserializeEndpoints(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("encryption"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            encryption = Encryption.DeserializeEncryption(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("accessTier"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            accessTier = property0.Value.GetString().ToAccessTier();
                            continue;
                        }
                        if (property0.NameEquals("azureFilesIdentityBasedAuthentication"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            azureFilesIdentityBasedAuthentication = AzureFilesIdentityBasedAuthentication.DeserializeAzureFilesIdentityBasedAuthentication(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("supportsHttpsTrafficOnly"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            supportsHttpsTrafficOnly = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("networkAcls"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            networkAcls = NetworkRuleSet.DeserializeNetworkRuleSet(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("isHnsEnabled"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            isHnsEnabled = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("geoReplicationStats"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            geoReplicationStats = GeoReplicationStats.DeserializeGeoReplicationStats(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("failoverInProgress"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            failoverInProgress = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("largeFileSharesState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            largeFileSharesState = new LargeFileSharesState(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("privateEndpointConnections"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <PrivateEndpointConnectionData> array = new List <PrivateEndpointConnectionData>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(PrivateEndpointConnectionData.DeserializePrivateEndpointConnectionData(item));
                            }
                            privateEndpointConnections = array;
                            continue;
                        }
                        if (property0.NameEquals("routingPreference"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            routingPreference = RoutingPreference.DeserializeRoutingPreference(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("blobRestoreStatus"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            blobRestoreStatus = BlobRestoreStatus.DeserializeBlobRestoreStatus(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("allowBlobPublicAccess"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            allowBlobPublicAccess = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("minimumTlsVersion"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            minimumTlsVersion = new MinimumTlsVersion(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("allowSharedKeyAccess"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            allowSharedKeyAccess = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("isNfsV3Enabled"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            isNfsV3Enabled = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("allowCrossTenantReplication"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            allowCrossTenantReplication = property0.Value.GetBoolean();
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new StorageAccountData(id, name, type, tags, location, sku.Value, Optional.ToNullable(kind), identity.Value, extendedLocation.Value, Optional.ToNullable(provisioningState), primaryEndpoints.Value, primaryLocation.Value, Optional.ToNullable(statusOfPrimary), Optional.ToNullable(lastGeoFailoverTime), secondaryLocation.Value, Optional.ToNullable(statusOfSecondary), Optional.ToNullable(creationTime), customDomain.Value, sasPolicy.Value, keyPolicy.Value, keyCreationTime.Value, secondaryEndpoints.Value, encryption.Value, Optional.ToNullable(accessTier), azureFilesIdentityBasedAuthentication.Value, Optional.ToNullable(supportsHttpsTrafficOnly), networkAcls.Value, Optional.ToNullable(isHnsEnabled), geoReplicationStats.Value, Optional.ToNullable(failoverInProgress), Optional.ToNullable(largeFileSharesState), Optional.ToList(privateEndpointConnections), routingPreference.Value, blobRestoreStatus.Value, Optional.ToNullable(allowBlobPublicAccess), Optional.ToNullable(minimumTlsVersion), Optional.ToNullable(allowSharedKeyAccess), Optional.ToNullable(isNfsV3Enabled), Optional.ToNullable(allowCrossTenantReplication)));
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (ShouldProcess(this.Name, "Add Cognitive Services Account NetworkRules"))
            {
                var account = this.CognitiveServicesClient.Accounts.Get(
                    this.ResourceGroupName,
                    this.Name);
                NetworkRuleSet accountACL = account.Properties.NetworkAcls;

                if (accountACL == null)
                {
                    accountACL = new NetworkRuleSet();
                    // Deny is the default action value from server side,
                    // Specifically make default action Deny in client side as server side might want this value to be always provided in future.
                    accountACL.DefaultAction = NetworkRuleAction.Deny;
                }

                switch (ParameterSetName)
                {
                case NetWorkRuleStringParameterSet:
                    if (accountACL.VirtualNetworkRules == null)
                    {
                        accountACL.VirtualNetworkRules = new List <VirtualNetworkRule>();
                    }

                    foreach (string s in VirtualNetworkResourceId)
                    {
                        VirtualNetworkRule rule = new VirtualNetworkRule(s, null, true);
                        accountACL.VirtualNetworkRules.Add(rule);
                    }
                    break;

                case IpRuleStringParameterSet:
                    if (accountACL.IpRules == null)
                    {
                        accountACL.IpRules = new List <IpRule>();
                    }

                    foreach (string s in IpAddressOrRange)
                    {
                        IpRule rule = new IpRule(s);
                        accountACL.IpRules.Add(rule);
                    }
                    break;

                case NetworkRuleObjectParameterSet:
                    if (accountACL.VirtualNetworkRules == null)
                    {
                        accountACL.VirtualNetworkRules = new List <VirtualNetworkRule>();
                    }

                    foreach (PSVirtualNetworkRule rule in VirtualNetworkRule)
                    {
                        accountACL.VirtualNetworkRules.Add(rule.ToVirtualNetworkRule());
                    }
                    break;

                case IpRuleObjectParameterSet:
                    if (accountACL.IpRules == null)
                    {
                        accountACL.IpRules = new List <IpRule>();
                    }

                    foreach (PSIpRule rule in IpRule)
                    {
                        accountACL.IpRules.Add(rule.ToIpRule());
                    }
                    break;
                }

                var properties = new AccountProperties();
                properties.NetworkAcls = accountACL;
                this.CognitiveServicesClient.Accounts.Update(
                    this.ResourceGroupName,
                    this.Name,
                    new Account()
                {
                    Properties = properties
                }
                    );

                account = this.CognitiveServicesClient.Accounts.Get(this.ResourceGroupName, this.Name);

                switch (ParameterSetName)
                {
                case NetWorkRuleStringParameterSet:
                case NetworkRuleObjectParameterSet:
                    WriteObject(PSNetworkRuleSet.Create(account.Properties.NetworkAcls).VirtualNetworkRules);
                    break;

                case IpRuleStringParameterSet:
                case IpRuleObjectParameterSet:
                    WriteObject(PSNetworkRuleSet.Create(account.Properties.NetworkAcls).IpRules);
                    break;
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (ShouldProcess(this.Name, "Remove Storage Account Networkrules"))
            {
                var storageAccount = this.StorageClient.StorageAccounts.GetProperties(
                    this.ResourceGroupName,
                    this.Name);
                NetworkRuleSet storageACL = storageAccount.NetworkRuleSet;

                if (storageACL == null)
                {
                    storageACL = new NetworkRuleSet();
                }

                switch (ParameterSetName)
                {
                case NetWorkRuleStringParameterSet:
                    if (storageACL.VirtualNetworkRules == null)
                    {
                        storageACL.VirtualNetworkRules = new List <VirtualNetworkRule>();
                    }
                    foreach (string s in VirtualNetworkResourceId)
                    {
                        VirtualNetworkRule rule = new VirtualNetworkRule(s);
                        if (!RemoveNetworkRule(storageACL.VirtualNetworkRules, rule))
                        {
                            throw new ArgumentOutOfRangeException("VirtualNetworkResourceId", String.Format("Can't remove VirtualNetworkRule with specific ResourceId since not exist: {0}", rule.VirtualNetworkResourceId));
                        }
                    }
                    break;

                case IpRuleStringParameterSet:
                    if (storageACL.IpRules == null)
                    {
                        storageACL.IpRules = new List <IPRule>();
                    }
                    foreach (string s in IPAddressOrRange)
                    {
                        IPRule rule = new IPRule(s);
                        if (!RemoveIpRule(storageACL.IpRules, rule))
                        {
                            throw new ArgumentOutOfRangeException("IPAddressOrRange", String.Format("Can't remove IpRule with specific IPAddressOrRange since not exist: {0}", rule.IPAddressOrRange));
                        }
                    }
                    break;

                case ResourceAccessRuleStringParameterSet:
                    if (storageACL.ResourceAccessRules == null)
                    {
                        storageACL.ResourceAccessRules = new List <ResourceAccessRule>();
                    }
                    ResourceAccessRule resourceaccessrule = new ResourceAccessRule(this.TenantId, this.ResourceId);
                    if (!RemoveResourceAccessRule(storageACL.ResourceAccessRules, resourceaccessrule))
                    {
                        throw new ArgumentOutOfRangeException("TenantId, ResourceId", String.Format("Can't remove ResourceAccessRule since not exist, TenantId: {0}, ResourceId : {1}", resourceaccessrule.TenantId, resourceaccessrule.ResourceId));
                    }

                    break;

                case NetworkRuleObjectParameterSet:
                    if (storageACL.VirtualNetworkRules == null)
                    {
                        storageACL.VirtualNetworkRules = new List <VirtualNetworkRule>();
                    }
                    foreach (PSVirtualNetworkRule rule in VirtualNetworkRule)
                    {
                        if (!RemoveNetworkRule(storageACL.VirtualNetworkRules, PSNetworkRuleSet.ParseStorageNetworkRuleVirtualNetworkRule(rule)))
                        {
                            throw new ArgumentOutOfRangeException("VirtualNetworkRule", String.Format("Can't remove VirtualNetworkRule with specific ResourceId since not exist: {0}", rule.VirtualNetworkResourceId));
                        }
                    }
                    break;

                case IpRuleObjectParameterSet:
                    if (storageACL.IpRules == null)
                    {
                        storageACL.IpRules = new List <IPRule>();
                    }
                    foreach (PSIpRule rule in IPRule)
                    {
                        if (!RemoveIpRule(storageACL.IpRules, PSNetworkRuleSet.ParseStorageNetworkRuleIPRule(rule)))
                        {
                            throw new ArgumentOutOfRangeException("IPRule", String.Format("Can't remove IpRule with specific IPAddressOrRange since not exist: {0}", rule.IPAddressOrRange));
                        }
                    }
                    break;

                case ResourceAccessRuleObjectParameterSet:
                    if (storageACL.ResourceAccessRules == null)
                    {
                        storageACL.ResourceAccessRules = new List <ResourceAccessRule>();
                    }
                    foreach (PSResourceAccessRule rule in this.ResourceAccessRule)
                    {
                        if (!RemoveResourceAccessRule(storageACL.ResourceAccessRules, PSNetworkRuleSet.ParseStorageResourceAccessRule(rule)))
                        {
                            throw new ArgumentOutOfRangeException("ResourceAccessRule", String.Format("Can't remove ResourceAccessRule since not exist, TenantId: {0}, ResourceId : {1}", rule.TenantId, rule.ResourceId));
                        }
                    }
                    break;
                }

                StorageAccountUpdateParameters updateParameters = new StorageAccountUpdateParameters();
                updateParameters.NetworkRuleSet = storageACL;

                var updatedAccountResponse = this.StorageClient.StorageAccounts.Update(
                    this.ResourceGroupName,
                    this.Name,
                    updateParameters);

                storageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name);

                switch (ParameterSetName)
                {
                case NetWorkRuleStringParameterSet:
                case NetworkRuleObjectParameterSet:
                    WriteObject(PSNetworkRuleSet.ParsePSNetworkRule(storageAccount.NetworkRuleSet).VirtualNetworkRules);
                    break;

                case IpRuleStringParameterSet:
                case IpRuleObjectParameterSet:
                    WriteObject(PSNetworkRuleSet.ParsePSNetworkRule(storageAccount.NetworkRuleSet).IpRules);
                    break;

                case ResourceAccessRuleStringParameterSet:
                case ResourceAccessRuleObjectParameterSet:
                    WriteObject(PSNetworkRuleSet.ParsePSNetworkRule(storageAccount.NetworkRuleSet).ResourceAccessRules);
                    break;
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Create or update NetworkRuleSet for a Namespace.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of the resource group within the azure subscription.
 /// </param>
 /// <param name='namespaceName'>
 /// The Namespace name
 /// </param>
 /// <param name='parameters'>
 /// The Namespace IpFilterRule.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <NetworkRuleSet> CreateOrUpdateNetworkRuleSetAsync(this INamespacesOperations operations, string resourceGroupName, string namespaceName, NetworkRuleSet parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateNetworkRuleSetWithHttpMessagesAsync(resourceGroupName, namespaceName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Create or update NetworkRuleSet for a Namespace.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of the resource group within the azure subscription.
 /// </param>
 /// <param name='namespaceName'>
 /// The Namespace name
 /// </param>
 /// <param name='parameters'>
 /// The Namespace IpFilterRule.
 /// </param>
 public static NetworkRuleSet CreateOrUpdateNetworkRuleSet(this INamespacesOperations operations, string resourceGroupName, string namespaceName, NetworkRuleSet parameters)
 {
     return(operations.CreateOrUpdateNetworkRuleSetAsync(resourceGroupName, namespaceName, parameters).GetAwaiter().GetResult());
 }
Ejemplo n.º 6
0
 internal StorageAccountData(ResourceIdentifier id, string name, ResourceType type, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, Models.Sku sku, Kind?kind, ManagedServiceIdentity identity, ExtendedLocation extendedLocation, ProvisioningState?provisioningState, Endpoints primaryEndpoints, string primaryLocation, AccountStatus?statusOfPrimary, DateTimeOffset?lastGeoFailoverTime, string secondaryLocation, AccountStatus?statusOfSecondary, DateTimeOffset?creationTime, CustomDomain customDomain, SasPolicy sasPolicy, KeyPolicy keyPolicy, KeyCreationTime keyCreationTime, Endpoints secondaryEndpoints, Encryption encryption, AccessTier?accessTier, AzureFilesIdentityBasedAuthentication azureFilesIdentityBasedAuthentication, bool?enableHttpsTrafficOnly, NetworkRuleSet networkRuleSet, bool?isSftpEnabled, bool?isLocalUserEnabled, bool?isHnsEnabled, GeoReplicationStats geoReplicationStats, bool?failoverInProgress, LargeFileSharesState?largeFileSharesState, IReadOnlyList <PrivateEndpointConnectionData> privateEndpointConnections, RoutingPreference routingPreference, BlobRestoreStatus blobRestoreStatus, bool?allowBlobPublicAccess, MinimumTlsVersion?minimumTlsVersion, bool?allowSharedKeyAccess, bool?enableNfsV3, bool?allowCrossTenantReplication, bool?defaultToOAuthAuthentication, PublicNetworkAccess?publicNetworkAccess, ImmutableStorageAccount immutableStorageWithVersioning, AllowedCopyScope?allowedCopyScope) : base(id, name, type, systemData, tags, location)
 {
     Sku                 = sku;
     Kind                = kind;
     Identity            = identity;
     ExtendedLocation    = extendedLocation;
     ProvisioningState   = provisioningState;
     PrimaryEndpoints    = primaryEndpoints;
     PrimaryLocation     = primaryLocation;
     StatusOfPrimary     = statusOfPrimary;
     LastGeoFailoverTime = lastGeoFailoverTime;
     SecondaryLocation   = secondaryLocation;
     StatusOfSecondary   = statusOfSecondary;
     CreationTime        = creationTime;
     CustomDomain        = customDomain;
     SasPolicy           = sasPolicy;
     KeyPolicy           = keyPolicy;
     KeyCreationTime     = keyCreationTime;
     SecondaryEndpoints  = secondaryEndpoints;
     Encryption          = encryption;
     AccessTier          = accessTier;
     AzureFilesIdentityBasedAuthentication = azureFilesIdentityBasedAuthentication;
     EnableHttpsTrafficOnly     = enableHttpsTrafficOnly;
     NetworkRuleSet             = networkRuleSet;
     IsSftpEnabled              = isSftpEnabled;
     IsLocalUserEnabled         = isLocalUserEnabled;
     IsHnsEnabled               = isHnsEnabled;
     GeoReplicationStats        = geoReplicationStats;
     FailoverInProgress         = failoverInProgress;
     LargeFileSharesState       = largeFileSharesState;
     PrivateEndpointConnections = privateEndpointConnections;
     RoutingPreference          = routingPreference;
     BlobRestoreStatus          = blobRestoreStatus;
     AllowBlobPublicAccess      = allowBlobPublicAccess;
     MinimumTlsVersion          = minimumTlsVersion;
     AllowSharedKeyAccess       = allowSharedKeyAccess;
     EnableNfsV3 = enableNfsV3;
     AllowCrossTenantReplication    = allowCrossTenantReplication;
     DefaultToOAuthAuthentication   = defaultToOAuthAuthentication;
     PublicNetworkAccess            = publicNetworkAccess;
     ImmutableStorageWithVersioning = immutableStorageWithVersioning;
     AllowedCopyScope = allowedCopyScope;
 }
Ejemplo n.º 7
0
        public async Task SetGetNetworkRuleSets()
        {
            IgnoreTestInLiveMode();
            //create namespace with premium
            _resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
            string namespaceName = await CreateValidNamespaceName(namespacePrefix);

            ServiceBusNamespaceData createParameters = new ServiceBusNamespaceData(DefaultLocation);

            createParameters.Sku = new ServiceBusSku(SkuName.Premium)
            {
                Tier = SkuTier.Premium
            };
            ServiceBusNamespace serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(namespaceName, createParameters)).Value;

            //prepare vnet
            string vnetName   = Recording.GenerateAssetName("sdktestvnet");
            var    parameters = new VirtualNetworkData
            {
                AddressSpace = new AddressSpace {
                    AddressPrefixes = { "10.0.0.0/16" }
                },
                Subnets =
                {
                    new SubnetData
                    {
                        Name             = "default1",
                        AddressPrefix    = "10.0.0.0/24",
                        ServiceEndpoints ={ new ServiceEndpointPropertiesFormat                        {
                          Service = "Microsoft.ServiceBus"
                      } }
                    },
                    new SubnetData
                    {
                        Name             = "default2",
                        AddressPrefix    = "10.0.1.0/24",
                        ServiceEndpoints ={ new ServiceEndpointPropertiesFormat                        {
                          Service = "Microsoft.ServiceBus"
                      } }
                    },
                    new SubnetData
                    {
                        Name             = "default3",
                        AddressPrefix    = "10.0.2.0/24",
                        ServiceEndpoints ={ new ServiceEndpointPropertiesFormat                        {
                          Service = "Microsoft.ServiceBus"
                      } }
                    }
                },
                Location = "eastus2"
            };
            VirtualNetwork virtualNetwork = (await _resourceGroup.GetVirtualNetworks().CreateOrUpdateAsync(vnetName, parameters)).Value;

            //set network rule set
            string             subscriptionId = DefaultSubscription.Id.ToString();
            ResourceIdentifier subnetId1      = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default1");
            ResourceIdentifier subnetId2      = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default2");
            ResourceIdentifier subnetId3      = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default3");
            NetworkRuleSetData parameter      = new NetworkRuleSetData()
            {
                DefaultAction       = DefaultAction.Deny,
                VirtualNetworkRules =
                {
                    new NetworkRuleSetVirtualNetworkRules()
                    {
                        Subnet = new WritableSubResource()
                        {
                            Id = subnetId1
                        }, IgnoreMissingVnetServiceEndpoint = true
                    },
                    new NetworkRuleSetVirtualNetworkRules()
                    {
                        Subnet = new WritableSubResource()
                        {
                            Id = subnetId2
                        }, IgnoreMissingVnetServiceEndpoint = false
                    },
                    new NetworkRuleSetVirtualNetworkRules()
                    {
                        Subnet = new WritableSubResource()
                        {
                            Id = subnetId3
                        }, IgnoreMissingVnetServiceEndpoint = false
                    }
                },
                IpRules =
                {
                    new NetworkRuleSetIpRules()
                    {
                        IpMask = "1.1.1.1", Action = "Allow"
                    },
                    new NetworkRuleSetIpRules()
                    {
                        IpMask = "1.1.1.2", Action = "Allow"
                    },
                    new NetworkRuleSetIpRules()
                    {
                        IpMask = "1.1.1.3", Action = "Allow"
                    },
                    new NetworkRuleSetIpRules()
                    {
                        IpMask = "1.1.1.4", Action = "Allow"
                    },
                    new NetworkRuleSetIpRules()
                    {
                        IpMask = "1.1.1.5", Action = "Allow"
                    }
                }
            };
            await serviceBusNamespace.GetNetworkRuleSet().CreateOrUpdateAsync(parameter);

            //get the network rule set
            NetworkRuleSet networkRuleSet = await serviceBusNamespace.GetNetworkRuleSet().GetAsync();

            Assert.NotNull(networkRuleSet);
            Assert.NotNull(networkRuleSet.Data.IpRules);
            Assert.NotNull(networkRuleSet.Data.VirtualNetworkRules);
            Assert.AreEqual(networkRuleSet.Data.VirtualNetworkRules.Count, 3);
            Assert.AreEqual(networkRuleSet.Data.IpRules.Count, 5);

            //delete virtual network
            await virtualNetwork.DeleteAsync();
        }