public void TestCreateAndDropVirtualNetworkRule() { string testPrefix = "virtualnetworkrulecrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { // Basic setup var location = TestEnvironmentUtilities.DefaultEuapPrimaryLocationId; ResourceGroup resourceGroup = context.CreateResourceGroup(location); VirtualNetwork getVnetResponse = CreateVirtualNetwork(context, resourceGroup, location: location, subnetCount: 1); Server server = context.CreateServer(resourceGroup, location); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // create virtual network rules string vnetfirewallRuleName = SqlManagementTestUtilities.GenerateName(testPrefix); VirtualNetworkRule rule = new VirtualNetworkRule() { VirtualNetworkSubnetId = getVnetResponse.Subnets[0].Id.ToString(), IgnoreMissingVnetServiceEndpoint = false }; VirtualNetworkRule vfr = sqlClient.VirtualNetworkRules.CreateOrUpdate(resourceGroup.Name, server.Name, vnetfirewallRuleName, rule); SqlManagementTestUtilities.ValidateVirtualNetworkRule(rule, vfr, vnetfirewallRuleName); // delete virtual network rules sqlClient.VirtualNetworkRules.Delete(resourceGroup.Name, server.Name, vfr.Name); } }
public void TestGetAndListVirtualNetworkRule() { string testPrefix = "virtualnetworkrulescrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { // Basic setup var location = TestEnvironmentUtilities.DefaultEuapPrimaryLocationId; ResourceGroup resourceGroup = context.CreateResourceGroup(location); VirtualNetwork getVnetResponse = CreateVirtualNetwork(context, resourceGroup, location: location, subnetCount: 2); Server server = context.CreateServer(resourceGroup, location); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // create virtual network rules Dictionary <string, VirtualNetworkRule> rules = new Dictionary <string, VirtualNetworkRule>(); //rule 1 string vnetfirewallRuleName1 = SqlManagementTestUtilities.GenerateName(testPrefix); VirtualNetworkRule rule1 = new VirtualNetworkRule() { VirtualNetworkSubnetId = getVnetResponse.Subnets[0].Id.ToString(), IgnoreMissingVnetServiceEndpoint = false }; sqlClient.VirtualNetworkRules.CreateOrUpdate(resourceGroup.Name, server.Name, vnetfirewallRuleName1, rule1); rules.Add(vnetfirewallRuleName1, rule1); //rule 2 string vnetfirewallRuleName2 = SqlManagementTestUtilities.GenerateName(testPrefix); VirtualNetworkRule rule2 = new VirtualNetworkRule() { VirtualNetworkSubnetId = getVnetResponse.Subnets[1].Id.ToString(), IgnoreMissingVnetServiceEndpoint = false }; sqlClient.VirtualNetworkRules.CreateOrUpdate(resourceGroup.Name, server.Name, vnetfirewallRuleName2, rule2); rules.Add(vnetfirewallRuleName2, rule2); foreach (var rul in rules) { VirtualNetworkRule response = sqlClient.VirtualNetworkRules.Get(resourceGroup.Name, server.Name, rul.Key); SqlManagementTestUtilities.ValidateVirtualNetworkRule(rul.Value, response, rul.Key); } var listResponse = sqlClient.VirtualNetworkRules.ListByServer(resourceGroup.Name, server.Name); Assert.Equal(rules.Count(), listResponse.Count()); foreach (var rul in listResponse) { SqlManagementTestUtilities.ValidateVirtualNetworkRule(rules[rul.Name], rul, rul.Name); } foreach (var rul in rules) { SqlManagementTestUtilities.ValidateVirtualNetworkRule(rul.Value, listResponse.Single(r => r.Name == rul.Key), rul.Key); } } }
//Parse wrapped property PSVirtualNetworkRule to single NetworkRule VirtualNetworkRule in SDK public static VirtualNetworkRule ParseStorageNetworkRuleVirtualNetworkRule(PSVirtualNetworkRule virtualNetworkRule) { VirtualNetworkRule returnRule = new VirtualNetworkRule(); returnRule.Action = ParseStorageNetworkRuleAction(virtualNetworkRule.Action); returnRule.VirtualNetworkResourceId = virtualNetworkRule.VirtualNetworkResourceId; return(returnRule); }
//Parse single NetworkRule VirtualNetworkRule in SDK to wrapped property PSVirtualNetworkRule public static PSVirtualNetworkRule ParsePSNetworkRuleVirtualNetworkRule(VirtualNetworkRule virtualNetworkRule) { PSVirtualNetworkRule returnRule = new PSVirtualNetworkRule(); returnRule.Action = ParsePSNetworkRuleAction(virtualNetworkRule.Action); returnRule.VirtualNetworkResourceId = virtualNetworkRule.VirtualNetworkResourceId; returnRule.State = virtualNetworkRule.State.ToString(); return(returnRule); }
public PSVirtualNetworkRule(VirtualNetworkRule virtualNetworkRule) { if (virtualNetworkRule == null) { return; } Id = virtualNetworkRule.Id; IgnoreMissingVNetServiceEndpoint = virtualNetworkRule.IgnoreMissingVNetServiceEndpoint; }
/// <summary> /// Remove one NetworkRule from NetworkRule List /// </summary> /// <param name="ruleList">The NetworkRule List</param> /// <param name="ruleToRemove">The NetworkRulee to remove</param> /// <returns>true if reove success</returns> public bool RemoveNetworkRule(IList <VirtualNetworkRule> ruleList, VirtualNetworkRule ruleToRemove) { foreach (VirtualNetworkRule rule in ruleList) { if (rule.Id == ruleToRemove.Id) { ruleList.Remove(rule); return(true); } } return(false); }
public override void ExecuteCmdlet() { // Update the NetworlruleSet if (ShouldProcess(target: Name, action: string.Format("Update NetworkruleSet for {0} Namespace in {1} ResourceGroup", Name, ResourceGroupName))) { try { if (ParameterSetName.Equals(NetwrokruleSetPropertiesParameterSet)) { PSNetworkRuleSetAttributes networkRuleSetAttributes = new PSNetworkRuleSetAttributes() { DefaultAction = DefaultAction, TrustedServiceAccessEnabled = TrustedServiceAccessEnabled.IsPresent, IpRules = IPRule.OfType <PSNWRuleSetIpRulesAttributes>().ToList(), VirtualNetworkRules = VirtualNetworkRule.OfType <PSNWRuleSetVirtualNetworkRulesAttributes>().ToList(), PublicNetworkAccess = PublicNetworkAccess }; WriteObject(Client.CreateOrUpdateNetworkRuleSet(ResourceGroupName, Name, networkRuleSetAttributes)); } if (ParameterSetName.Equals(NetwrokruleSetInputObjectParameterSet)) { WriteObject(Client.CreateOrUpdateNetworkRuleSet(ResourceGroupName, Name, InputObject)); } if (ParameterSetName.Equals("NetworkRuleSetResourceIdParameterSet")) { ResourceIdentifier getParamGeoDR = GetResourceDetailsFromId(ResourceId); PSNetworkRuleSetAttributes getNWRuleSet = Client.GetNetworkRuleSet(getParamGeoDR.ResourceGroupName, getParamGeoDR.ParentResource); if (ResourceGroupName != null && getParamGeoDR.ResourceName != null) { if (ShouldProcess(target: Name, action: string.Format("updating NetwrokruleSet", Name, ResourceGroupName))) { WriteObject(Client.CreateOrUpdateNetworkRuleSet(ResourceGroupName, Name, getNWRuleSet)); } } } } catch (Management.EventHub.Models.ErrorResponseException ex) { WriteError(Eventhub.EventHubsClient.WriteErrorforBadrequest(ex)); } } }
/// <summary> /// Creates storage account. /// </summary> /// <param name="storageAccountName">Storage account to be created.</param> /// <param name="skuName">Storage SKU.</param> /// <param name="storageKind">Storage kind.</param> /// <returns>Stoprage account.</returns> public StorageAccount CreateStorageAccount(string storageAccountName, string skuName = null, string storageKind = null, bool blobNfs = false, string subnetUri = null) { var sku = string.IsNullOrEmpty(skuName) ? DefaultSkuName : skuName; var kind = string.IsNullOrEmpty(storageKind) ? DefaultKind : storageKind; StorageAccountCreateParameters storageAccountCreateParameters = new StorageAccountCreateParameters { Location = this.resourceGroup.Location, // Tags = DefaultTags, Sku = new Sku() { Name = sku }, Kind = kind, }; if (blobNfs == true) { storageAccountCreateParameters.IsHnsEnabled = true; storageAccountCreateParameters.Kind = "BlockBlobStorage"; storageAccountCreateParameters.Sku.Name = "Premium_LRS"; storageAccountCreateParameters.EnableHttpsTrafficOnly = false; storageAccountCreateParameters.EnableNfsV3 = true; storageAccountCreateParameters.AllowSharedKeyAccess = true; storageAccountCreateParameters.AllowBlobPublicAccess = true; //RoutingPreference rp = new RoutingPreference(); //rp.PublishMicrosoftEndpoints = true; //rp.PublishInternetEndpoints = false; //storageAccountCreateParameters.RoutingPreference = rp; VirtualNetworkRule virtualNetworkRule = new VirtualNetworkRule(); virtualNetworkRule.VirtualNetworkResourceId = subnetUri; List <VirtualNetworkRule> virtualNetworkRules = new List <VirtualNetworkRule>(); virtualNetworkRules.Add(virtualNetworkRule); NetworkRuleSet nrs = new NetworkRuleSet(); nrs.VirtualNetworkRules = virtualNetworkRules; nrs.Bypass = "******"; nrs.DefaultAction = DefaultAction.Deny; nrs.IpRules = new List <IPRule>(); storageAccountCreateParameters.NetworkRuleSet = nrs; } StorageAccount storageAccount = this.StorageManagementClient.StorageAccounts.Create(this.resourceGroup.Name, storageAccountName, storageAccountCreateParameters); return(storageAccount); }
public override void ExecuteCmdlet() { // get the current virtual network rule VirtualNetworkRule rule = DataLakeStoreClient.GetVirtualNetworkRule(Account, Name); if (rule == null) { throw new PSInvalidOperationException(string.Format(Resources.VirtualNetworkRuleNotFound, Name)); } var subnetId = SubnetId ?? rule.SubnetId; ConfirmAction( string.Format(Resources.SetDataLakeVirtualNetworkRule, Name), Name, () => WriteObject(new DataLakeStoreVirtualNetworkRule(DataLakeStoreClient.AddOrUpdateVirtualNetworkRule( Account, Name, subnetId, this))) ); }
public DataLakeStoreVirtualNetworkRule(VirtualNetworkRule baseRule) { VirtualNetworkRuleName = baseRule.Name; VirtualNetworkSubnetId = baseRule.SubnetId; }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); if (ShouldProcess(this.Name, "Add Cognitive Services Account NetworkRules")) { var account = this.CognitiveServicesClient.Accounts.GetProperties( 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 CognitiveServicesAccountProperties(); properties.NetworkAcls = accountACL; this.CognitiveServicesClient.Accounts.Update( this.ResourceGroupName, this.Name, new CognitiveServicesAccount() { Properties = properties } ); account = this.CognitiveServicesClient.Accounts.GetProperties(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, "Add 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); storageACL.VirtualNetworkRules.Add(rule); } break; case IpRuleStringParameterSet: if (storageACL.IpRules == null) { storageACL.IpRules = new List <IPRule>(); } foreach (string s in IPAddressOrRange) { IPRule rule = new IPRule(s); storageACL.IpRules.Add(rule); } break; case NetworkRuleObjectParameterSet: if (storageACL.VirtualNetworkRules == null) { storageACL.VirtualNetworkRules = new List <VirtualNetworkRule>(); } foreach (PSVirtualNetworkRule rule in VirtualNetworkRule) { storageACL.VirtualNetworkRules.Add(PSNetworkRuleSet.ParseStorageNetworkRuleVirtualNetworkRule(rule)); } break; case IpRuleObjectParameterSet: if (storageACL.IpRules == null) { storageACL.IpRules = new List <IPRule>(); } foreach (PSIpRule rule in IPRule) { storageACL.IpRules.Add(PSNetworkRuleSet.ParseStorageNetworkRuleIPRule(rule)); } 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; } } }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); if (ShouldProcess(this.Name, "Remove 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(); 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); if (!RemoveNetworkRule(accountACL.VirtualNetworkRules, rule)) { throw new ArgumentOutOfRangeException("VirtualNetworkResourceId", String.Format("Can't remove VirtualNetworkRule with specific ResourceId since not exist: {0}", rule.Id)); } } break; case IpRuleStringParameterSet: if (accountACL.IpRules == null) { accountACL.IpRules = new List <IpRule>(); } foreach (string s in IpAddressOrRange) { IpRule rule = new IpRule(s); if (!RemoveIpRule(accountACL.IpRules, rule)) { throw new ArgumentOutOfRangeException("IPAddressOrRange", String.Format("Can't remove IpRule with specific IPAddressOrRange since not exist: {0}", rule.Value)); } } break; case NetworkRuleObjectParameterSet: if (accountACL.VirtualNetworkRules == null) { accountACL.VirtualNetworkRules = new List <VirtualNetworkRule>(); } foreach (PSVirtualNetworkRule rule in VirtualNetworkRule) { if (!RemoveNetworkRule(accountACL.VirtualNetworkRules, rule.ToVirtualNetworkRule())) { throw new ArgumentOutOfRangeException("VirtualNetworkRule", String.Format("Can't remove VirtualNetworkRule with specific ResourceId since not exist: {0}", rule.Id)); } } break; case IpRuleObjectParameterSet: if (accountACL.IpRules == null) { accountACL.IpRules = new List <IpRule>(); } foreach (PSIpRule rule in IpRule) { if (!RemoveIpRule(accountACL.IpRules, rule.ToIpRule())) { throw new ArgumentOutOfRangeException("IPRule", String.Format("Can't remove IpRule with specific IPAddressOrRange since not exist: {0}", rule.IpAddress)); } } 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; } } }
private static AzureResourceBag CreateBaseAzureInfrastructure(Config config) { var location = config.Require("azure-location"); var environment = config.Require("azure-tags-environment"); var owner = config.Require("azure-tags-owner"); var createdBy = config.Require("azure-tags-createdby"); var kubernetesVersion = config.Require("kubernetes-version"); var kubernetesNodeCount = config.RequireInt32("kubernetes-scaling-nodecount"); var sqlUser = config.RequireSecret("azure-sqlserver-username"); var sqlPassword = config.RequireSecret("azure-sqlserver-password"); var tags = new InputMap <string> { { "Environment", environment }, { "CreatedBy", createdBy }, { "Owner", owner } }; var resourceGroup = new ResourceGroup("pet-doctor-resource-group", new ResourceGroupArgs { Name = "pet-doctor", Location = location, Tags = tags }); var vnet = new VirtualNetwork("pet-doctor-vnet", new VirtualNetworkArgs { ResourceGroupName = resourceGroup.Name, Name = "petdoctorvnet", AddressSpaces = { "10.0.0.0/8" }, Tags = tags }); var subnet = new Subnet("pet-doctor-subnet", new SubnetArgs { ResourceGroupName = resourceGroup.Name, Name = "petdoctorsubet", AddressPrefixes = { "10.240.0.0/16" }, VirtualNetworkName = vnet.Name, ServiceEndpoints = new InputList <string> { "Microsoft.KeyVault", "Microsoft.Sql" } }); var registry = new Registry("pet-doctor-acr", new RegistryArgs { ResourceGroupName = resourceGroup.Name, Name = "petdoctoracr", Sku = "Standard", AdminEnabled = true, Tags = tags }); var aksServicePrincipalPassword = new RandomPassword("pet-doctor-aks-ad-sp-password", new RandomPasswordArgs { Length = 20, Special = true, }).Result; var clusterAdApp = new Application("pet-doctor-aks-ad-app", new ApplicationArgs { Name = "petdoctoraks" }); var clusterAdServicePrincipal = new ServicePrincipal("aks-app-sp", new ServicePrincipalArgs { ApplicationId = clusterAdApp.ApplicationId }); var clusterAdServicePrincipalPassword = new ServicePrincipalPassword("aks-app-sp-pwd", new ServicePrincipalPasswordArgs { ServicePrincipalId = clusterAdServicePrincipal.ObjectId, EndDate = "2099-01-01T00:00:00Z", Value = aksServicePrincipalPassword }); // Grant networking permissions to the SP (needed e.g. to provision Load Balancers) var subnetAssignment = new Assignment("pet-doctor-aks-sp-subnet-assignment", new AssignmentArgs { PrincipalId = clusterAdServicePrincipal.Id, RoleDefinitionName = "Network Contributor", Scope = subnet.Id }); var acrAssignment = new Assignment("pet-doctor-aks-sp-acr-assignment", new AssignmentArgs { PrincipalId = clusterAdServicePrincipal.Id, RoleDefinitionName = "AcrPull", Scope = registry.Id }); var logAnalyticsWorkspace = new AnalyticsWorkspace("pet-doctor-aks-log-analytics", new AnalyticsWorkspaceArgs { ResourceGroupName = resourceGroup.Name, Name = "petdoctorloganalytics", Sku = "PerGB2018", Tags = tags }); var logAnalyticsSolution = new AnalyticsSolution("pet-doctor-aks-analytics-solution", new AnalyticsSolutionArgs { ResourceGroupName = resourceGroup.Name, SolutionName = "ContainerInsights", WorkspaceName = logAnalyticsWorkspace.Name, WorkspaceResourceId = logAnalyticsWorkspace.Id, Plan = new AnalyticsSolutionPlanArgs { Product = "OMSGallery/ContainerInsights", Publisher = "Microsoft" } }); var sshPublicKey = new PrivateKey("ssh-key", new PrivateKeyArgs { Algorithm = "RSA", RsaBits = 4096, }); var cluster = new KubernetesCluster("pet-doctor-aks", new KubernetesClusterArgs { ResourceGroupName = resourceGroup.Name, Name = "petdoctoraks", DnsPrefix = "dns", KubernetesVersion = kubernetesVersion, DefaultNodePool = new KubernetesClusterDefaultNodePoolArgs { Name = "aksagentpool", NodeCount = kubernetesNodeCount, VmSize = "Standard_D2_v2", OsDiskSizeGb = 30, VnetSubnetId = subnet.Id }, LinuxProfile = new KubernetesClusterLinuxProfileArgs { AdminUsername = "******", SshKey = new KubernetesClusterLinuxProfileSshKeyArgs { KeyData = sshPublicKey.PublicKeyOpenssh } }, ServicePrincipal = new KubernetesClusterServicePrincipalArgs { ClientId = clusterAdApp.ApplicationId, ClientSecret = clusterAdServicePrincipalPassword.Value }, RoleBasedAccessControl = new KubernetesClusterRoleBasedAccessControlArgs { Enabled = true }, NetworkProfile = new KubernetesClusterNetworkProfileArgs { NetworkPlugin = "azure", ServiceCidr = "10.2.0.0/24", DnsServiceIp = "10.2.0.10", DockerBridgeCidr = "172.17.0.1/16" }, AddonProfile = new KubernetesClusterAddonProfileArgs { OmsAgent = new KubernetesClusterAddonProfileOmsAgentArgs { Enabled = true, LogAnalyticsWorkspaceId = logAnalyticsWorkspace.Id } }, Tags = tags }); var sqlServer = new SqlServer("pet-doctor-sql", new SqlServerArgs { ResourceGroupName = resourceGroup.Name, Name = "petdoctorsql", Tags = tags, Version = "12.0", AdministratorLogin = sqlUser, AdministratorLoginPassword = sqlPassword }); var sqlvnetrule = new VirtualNetworkRule("pet-doctor-sql", new VirtualNetworkRuleArgs { ResourceGroupName = resourceGroup.Name, Name = "petdoctorsql", ServerName = sqlServer.Name, SubnetId = subnet.Id, }); var appInsights = new Insights("pet-doctor-ai", new InsightsArgs { ApplicationType = "web", Name = "petdoctor", ResourceGroupName = resourceGroup.Name, Tags = tags }); var provider = new Provider("pet-doctor-aks-provider", new ProviderArgs { KubeConfig = cluster.KubeConfigRaw }); return(new AzureResourceBag { ResourceGroup = resourceGroup, SqlServer = sqlServer, Cluster = cluster, ClusterProvider = provider, AppInsights = appInsights, AksServicePrincipal = clusterAdServicePrincipal, Subnet = subnet, Registry = registry, Tags = tags }); }
internal static DatabaseAccountData DeserializeDatabaseAccountData(JsonElement element) { Optional <DatabaseAccountKind> kind = default; Optional <ManagedServiceIdentity> identity = default; IDictionary <string, string> tags = default; AzureLocation location = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; Optional <string> provisioningState = default; Optional <string> documentEndpoint = default; Optional <string> databaseAccountOfferType = default; Optional <IList <IPAddressOrRange> > ipRules = default; Optional <bool> isVirtualNetworkFilterEnabled = default; Optional <bool> enableAutomaticFailover = default; Optional <ConsistencyPolicy> consistencyPolicy = default; Optional <IList <DatabaseAccountCapability> > capabilities = default; Optional <IReadOnlyList <DatabaseAccountLocation> > writeLocations = default; Optional <IReadOnlyList <DatabaseAccountLocation> > readLocations = default; Optional <IReadOnlyList <DatabaseAccountLocation> > locations = default; Optional <IReadOnlyList <FailoverPolicy> > failoverPolicies = default; Optional <IList <VirtualNetworkRule> > virtualNetworkRules = default; Optional <IReadOnlyList <PrivateEndpointConnectionData> > privateEndpointConnections = default; Optional <bool> enableMultipleWriteLocations = default; Optional <bool> enableCassandraConnector = default; Optional <ConnectorOffer> connectorOffer = default; Optional <bool> disableKeyBasedMetadataWriteAccess = default; Optional <Uri> keyVaultKeyUri = default; Optional <string> defaultIdentity = default; Optional <PublicNetworkAccess> publicNetworkAccess = default; Optional <bool> enableFreeTier = default; Optional <ApiProperties> apiProperties = default; Optional <bool> enableAnalyticalStorage = default; Optional <AnalyticalStorageConfiguration> analyticalStorageConfiguration = default; Optional <string> instanceId = default; Optional <CreateMode> createMode = default; Optional <RestoreParameters> restoreParameters = default; Optional <BackupPolicy> backupPolicy = default; Optional <IList <CorsPolicy> > cors = default; Optional <NetworkAclBypass> networkAclBypass = default; Optional <IList <string> > networkAclBypassResourceIds = default; Optional <bool> disableLocalAuth = default; Optional <Capacity> capacity = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("kind")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } kind = new DatabaseAccountKind(property.Value.GetString()); continue; } if (property.NameEquals("identity")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } var serializeOptions = new JsonSerializerOptions { Converters = { new ManagedServiceIdentityTypeV3Converter() } }; identity = JsonSerializer.Deserialize <ManagedServiceIdentity>(property.Value.ToString(), serializeOptions); 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("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); 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")) { provisioningState = property0.Value.GetString(); continue; } if (property0.NameEquals("documentEndpoint")) { documentEndpoint = property0.Value.GetString(); continue; } if (property0.NameEquals("databaseAccountOfferType")) { databaseAccountOfferType = property0.Value.GetString(); continue; } if (property0.NameEquals("ipRules")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <IPAddressOrRange> array = new List <IPAddressOrRange>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(IPAddressOrRange.DeserializeIPAddressOrRange(item)); } ipRules = array; continue; } if (property0.NameEquals("isVirtualNetworkFilterEnabled")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } isVirtualNetworkFilterEnabled = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("enableAutomaticFailover")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } enableAutomaticFailover = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("consistencyPolicy")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } consistencyPolicy = ConsistencyPolicy.DeserializeConsistencyPolicy(property0.Value); continue; } if (property0.NameEquals("capabilities")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <DatabaseAccountCapability> array = new List <DatabaseAccountCapability>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(DatabaseAccountCapability.DeserializeDatabaseAccountCapability(item)); } capabilities = array; continue; } if (property0.NameEquals("writeLocations")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <DatabaseAccountLocation> array = new List <DatabaseAccountLocation>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(DatabaseAccountLocation.DeserializeDatabaseAccountLocation(item)); } writeLocations = array; continue; } if (property0.NameEquals("readLocations")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <DatabaseAccountLocation> array = new List <DatabaseAccountLocation>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(DatabaseAccountLocation.DeserializeDatabaseAccountLocation(item)); } readLocations = array; continue; } if (property0.NameEquals("locations")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <DatabaseAccountLocation> array = new List <DatabaseAccountLocation>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(DatabaseAccountLocation.DeserializeDatabaseAccountLocation(item)); } locations = array; continue; } if (property0.NameEquals("failoverPolicies")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <FailoverPolicy> array = new List <FailoverPolicy>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(FailoverPolicy.DeserializeFailoverPolicy(item)); } failoverPolicies = array; continue; } if (property0.NameEquals("virtualNetworkRules")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <VirtualNetworkRule> array = new List <VirtualNetworkRule>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(VirtualNetworkRule.DeserializeVirtualNetworkRule(item)); } virtualNetworkRules = array; 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("enableMultipleWriteLocations")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } enableMultipleWriteLocations = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("enableCassandraConnector")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } enableCassandraConnector = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("connectorOffer")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } connectorOffer = new ConnectorOffer(property0.Value.GetString()); continue; } if (property0.NameEquals("disableKeyBasedMetadataWriteAccess")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } disableKeyBasedMetadataWriteAccess = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("keyVaultKeyUri")) { if (property0.Value.ValueKind == JsonValueKind.Null) { keyVaultKeyUri = null; continue; } keyVaultKeyUri = new Uri(property0.Value.GetString()); continue; } if (property0.NameEquals("defaultIdentity")) { defaultIdentity = property0.Value.GetString(); continue; } if (property0.NameEquals("publicNetworkAccess")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } publicNetworkAccess = new PublicNetworkAccess(property0.Value.GetString()); continue; } if (property0.NameEquals("enableFreeTier")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } enableFreeTier = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("apiProperties")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } apiProperties = ApiProperties.DeserializeApiProperties(property0.Value); continue; } if (property0.NameEquals("enableAnalyticalStorage")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } enableAnalyticalStorage = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("analyticalStorageConfiguration")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } analyticalStorageConfiguration = AnalyticalStorageConfiguration.DeserializeAnalyticalStorageConfiguration(property0.Value); continue; } if (property0.NameEquals("instanceId")) { instanceId = property0.Value.GetString(); continue; } if (property0.NameEquals("createMode")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } createMode = new CreateMode(property0.Value.GetString()); continue; } if (property0.NameEquals("restoreParameters")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } restoreParameters = RestoreParameters.DeserializeRestoreParameters(property0.Value); continue; } if (property0.NameEquals("backupPolicy")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } backupPolicy = BackupPolicy.DeserializeBackupPolicy(property0.Value); continue; } if (property0.NameEquals("cors")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <CorsPolicy> array = new List <CorsPolicy>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(CorsPolicy.DeserializeCorsPolicy(item)); } cors = array; continue; } if (property0.NameEquals("networkAclBypass")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } networkAclBypass = property0.Value.GetString().ToNetworkAclBypass(); continue; } if (property0.NameEquals("networkAclBypassResourceIds")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <string> array = new List <string>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(item.GetString()); } networkAclBypassResourceIds = array; continue; } if (property0.NameEquals("disableLocalAuth")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } disableLocalAuth = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("capacity")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } capacity = Capacity.DeserializeCapacity(property0.Value); continue; } } continue; } } return(new DatabaseAccountData(id, name, type, systemData, tags, location, Optional.ToNullable(kind), identity, provisioningState.Value, documentEndpoint.Value, databaseAccountOfferType.Value, Optional.ToList(ipRules), Optional.ToNullable(isVirtualNetworkFilterEnabled), Optional.ToNullable(enableAutomaticFailover), consistencyPolicy.Value, Optional.ToList(capabilities), Optional.ToList(writeLocations), Optional.ToList(readLocations), Optional.ToList(locations), Optional.ToList(failoverPolicies), Optional.ToList(virtualNetworkRules), Optional.ToList(privateEndpointConnections), Optional.ToNullable(enableMultipleWriteLocations), Optional.ToNullable(enableCassandraConnector), Optional.ToNullable(connectorOffer), Optional.ToNullable(disableKeyBasedMetadataWriteAccess), keyVaultKeyUri.Value, defaultIdentity.Value, Optional.ToNullable(publicNetworkAccess), Optional.ToNullable(enableFreeTier), apiProperties.Value, Optional.ToNullable(enableAnalyticalStorage), analyticalStorageConfiguration.Value, instanceId.Value, Optional.ToNullable(createMode), restoreParameters.Value, backupPolicy.Value, Optional.ToList(cors), Optional.ToNullable(networkAclBypass), Optional.ToList(networkAclBypassResourceIds), Optional.ToNullable(disableLocalAuth), capacity.Value)); }
public static void ValidateVirtualNetworkRule(VirtualNetworkRule expected, VirtualNetworkRule actual, string name) { Assert.NotNull(actual.Id); Assert.Equal(expected.VirtualNetworkSubnetId, actual.VirtualNetworkSubnetId); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); if (ShouldProcess(this.Name, "Add Cognitive Services Account NetworkRules")) { var account = this.CognitiveServicesClient.Accounts.GetProperties( this.ResourceGroupName, this.Name); NetworkRuleSet accountACL = account.Properties.NetworkAcls; if (accountACL == null) { accountACL = new NetworkRuleSet(); } 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 CognitiveServicesAccountProperties(); properties.NetworkAcls = accountACL; this.CognitiveServicesClient.Accounts.Update( this.ResourceGroupName, this.Name, new CognitiveServicesAccount() { Properties = properties } ); account = this.CognitiveServicesClient.Accounts.GetProperties(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 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; } 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; } } }
public PSVirtualNetworkRule(VirtualNetworkRule virtualNetworkRule) { Id = virtualNetworkRule.Id; IgnoreMissingVNetServiceEndpoint = virtualNetworkRule.IgnoreMissingVNetServiceEndpoint; }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); if (ShouldProcess(this.Name, "Add Storage Account NetworkRules")) { var storageAccount = this.StorageClient.StorageAccounts.GetProperties( this.ResourceGroupName, this.Name); NetworkRuleSet storageACL = storageAccount.NetworkRuleSet; if (storageACL == null) { storageACL = new NetworkRuleSet(); } bool ruleChanged = false; switch (ParameterSetName) { case NetWorkRuleStringParameterSet: if (storageACL.VirtualNetworkRules == null) { storageACL.VirtualNetworkRules = new List <VirtualNetworkRule>(); } foreach (string s in VirtualNetworkResourceId) { bool ruleExist = false; foreach (VirtualNetworkRule originRule in storageACL.VirtualNetworkRules) { if (originRule.VirtualNetworkResourceId.Equals(s, System.StringComparison.InvariantCultureIgnoreCase)) { ruleExist = true; WriteDebug(string.Format("Skip add VirtualNetworkRule as it already exist: {0}", s)); break; } } if (!ruleExist) { VirtualNetworkRule rule = new VirtualNetworkRule(s); storageACL.VirtualNetworkRules.Add(rule); ruleChanged = true; } } break; case IpRuleStringParameterSet: if (storageACL.IpRules == null) { storageACL.IpRules = new List <IPRule>(); } foreach (string s in IPAddressOrRange) { bool ruleExist = false; foreach (IPRule originRule in storageACL.IpRules) { if (originRule.IPAddressOrRange.Equals(s, System.StringComparison.InvariantCultureIgnoreCase)) { ruleExist = true; WriteDebug(string.Format("Skip add IPAddressOrRange as it already exist: {0}", s)); break; } } if (!ruleExist) { IPRule rule = new IPRule(s); storageACL.IpRules.Add(rule); ruleChanged = true; } } break; case ResourceAccessRuleStringParameterSet: if (storageACL.ResourceAccessRules == null) { storageACL.ResourceAccessRules = new List <ResourceAccessRule>(); } bool ResourceAccessruleExist = false; foreach (ResourceAccessRule originRule in storageACL.ResourceAccessRules) { if (originRule.TenantId.Equals(this.TenantId, System.StringComparison.InvariantCultureIgnoreCase) && originRule.ResourceId.Equals(this.ResourceId, System.StringComparison.InvariantCultureIgnoreCase)) { ResourceAccessruleExist = true; WriteDebug(string.Format("Skip add ResourceAccessRule as it already exist, TenantId: {0}, ResourceId: {1}", this.TenantId, this.ResourceId)); break; } } if (!ResourceAccessruleExist) { ResourceAccessRule rule = new ResourceAccessRule(this.TenantId, this.ResourceId); storageACL.ResourceAccessRules.Add(rule); ruleChanged = true; } break; case NetworkRuleObjectParameterSet: if (storageACL.VirtualNetworkRules == null) { storageACL.VirtualNetworkRules = new List <VirtualNetworkRule>(); } foreach (PSVirtualNetworkRule rule in VirtualNetworkRule) { bool ruleExist = false; foreach (VirtualNetworkRule originRule in storageACL.VirtualNetworkRules) { if (originRule.VirtualNetworkResourceId.Equals(rule.VirtualNetworkResourceId, System.StringComparison.InvariantCultureIgnoreCase)) { ruleExist = true; WriteDebug(string.Format("Skip add IPAddressOrRange as it already exist: {0}", rule.VirtualNetworkResourceId)); break; } } if (!ruleExist) { storageACL.VirtualNetworkRules.Add(PSNetworkRuleSet.ParseStorageNetworkRuleVirtualNetworkRule(rule)); ruleChanged = true; } } break; case ResourceAccessRuleObjectParameterSet: if (storageACL.ResourceAccessRules == null) { storageACL.ResourceAccessRules = new List <ResourceAccessRule>(); } foreach (PSResourceAccessRule rule in ResourceAccessRule) { bool ruleExist = false; foreach (ResourceAccessRule originRule in storageACL.ResourceAccessRules) { if (originRule.TenantId.Equals(rule.TenantId, System.StringComparison.InvariantCultureIgnoreCase) && originRule.ResourceId.Equals(rule.ResourceId, System.StringComparison.InvariantCultureIgnoreCase)) { ruleExist = true; WriteDebug(string.Format("Skip add ResourceAccessRule as it already exist, TenantId: {0}, ResourceId: {1}", rule.TenantId, rule.ResourceId)); break; } } if (!ruleExist) { storageACL.ResourceAccessRules.Add(PSNetworkRuleSet.ParseStorageResourceAccessRule(rule)); ruleChanged = true; } } break; case IpRuleObjectParameterSet: if (storageACL.IpRules == null) { storageACL.IpRules = new List <IPRule>(); } foreach (PSIpRule rule in IPRule) { bool ruleExist = false; foreach (IPRule originRule in storageACL.IpRules) { if (originRule.IPAddressOrRange.Equals(rule.IPAddressOrRange, System.StringComparison.InvariantCultureIgnoreCase)) { ruleExist = true; WriteDebug(string.Format("Skip add IPAddressOrRange as it already exist: {0}", rule.IPAddressOrRange)); break; } } if (!ruleExist) { storageACL.IpRules.Add(PSNetworkRuleSet.ParseStorageNetworkRuleIPRule(rule)); ruleChanged = true; } } break; } if (ruleChanged) { 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; } } }
/// <summary> /// Creates or updates an existing virtual network rule. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group that contains the resource. You can obtain /// this value from the Azure Resource Manager API or the portal. /// </param> /// <param name='serverName'> /// The name of the server. /// </param> /// <param name='virtualNetworkRuleName'> /// The name of the virtual network rule. /// </param> /// <param name='parameters'> /// The requested virtual Network Rule Resource state. /// </param> public static VirtualNetworkRule CreateOrUpdate(this IVirtualNetworkRulesOperations operations, string resourceGroupName, string serverName, string virtualNetworkRuleName, VirtualNetworkRule parameters) { return(operations.CreateOrUpdateAsync(resourceGroupName, serverName, virtualNetworkRuleName, parameters).GetAwaiter().GetResult()); }
/// <summary> /// Creates or updates an existing virtual network rule. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group that contains the resource. You can obtain /// this value from the Azure Resource Manager API or the portal. /// </param> /// <param name='serverName'> /// The name of the server. /// </param> /// <param name='virtualNetworkRuleName'> /// The name of the virtual network rule. /// </param> /// <param name='parameters'> /// The requested virtual Network Rule Resource state. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <VirtualNetworkRule> BeginCreateOrUpdateAsync(this IVirtualNetworkRulesOperations operations, string resourceGroupName, string serverName, string virtualNetworkRuleName, VirtualNetworkRule parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, virtualNetworkRuleName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public PSVirtualNetworkRule(VirtualNetworkRule rule) { Action = rule.Action; VirtualNetworkResourceId = rule.VirtualNetworkResourceId; Validate(); }
bool GetRuleForSubnet(NetworkRuleSet networkRuleSet, string subnetId, Microsoft.Azure.Management.Storage.Fluent.Models.Action action, out VirtualNetworkRule virtualNetworkRule) { foreach (var curRule in networkRuleSet.VirtualNetworkRules.Where(r => r.VirtualNetworkResourceId == subnetId && r.Action == action)) { virtualNetworkRule = curRule; return(true); } virtualNetworkRule = null; return(false); }