public override void ExecuteCmdlet() { const bool deleted = true; var overwrite = this.Overwrite.IsPresent || this.ParameterSetName != ObjectParameterSetName; if (!string.IsNullOrEmpty(this.ResourceId)) { PrivateDnsUtils.ParseVirtualNetworkId(this.ResourceId, out var resourceGroupName, out var zoneName, out var linkName); this.ResourceGroupName = resourceGroupName; this.ZoneName = zoneName; this.Name = linkName; } if (!string.IsNullOrEmpty((this.ZoneName))) { this.ZoneName = TrimTrailingDotInZoneName(this.ZoneName); } var linkToDelete = (this.ParameterSetName != ObjectParameterSetName) ? this.PrivateDnsClient.GetLinkHandleNonExistentLink(this.ZoneName, this.ResourceGroupName, this.Name) : this.InputObject; if (linkToDelete == null) { this.WriteWarning(ProjectResources.Warning_InvalidLinkDetailsSpecified); return; } if ((string.IsNullOrWhiteSpace(linkToDelete.Etag) || linkToDelete.Etag == "*") && !overwrite) { throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(PSPrivateDnsVirtualNetworkLink).Name)); } if (!string.IsNullOrEmpty((linkToDelete.ZoneName))) { linkToDelete.ZoneName = TrimTrailingDotInZoneName(linkToDelete.ZoneName); } ConfirmAction( ProjectResources.Progress_RemovingLink, linkToDelete.Name, () => { PrivateDnsClient.DeletePrivateDnsLink(linkToDelete, overwrite); WriteVerbose(ProjectResources.Success); WriteVerbose(string.Format(ProjectResources.Success_RemoveLink, linkToDelete.Name, linkToDelete.ResourceGroupName)); if (this.PassThru) { WriteObject(deleted); } }); }
public override void ExecuteCmdlet() { const bool deleted = true; var overwrite = this.Overwrite.IsPresent || this.ParameterSetName != ObjectParameterSetName; if (!string.IsNullOrEmpty(this.ResourceId)) { PrivateDnsUtils.GetResourceGroupNameAndZoneNameFromResourceId(this.ResourceId, out var resourceGroupName, out var zoneName); this.ResourceGroupName = resourceGroupName; this.Name = zoneName; } if (!string.IsNullOrEmpty(this.Name) && this.Name.EndsWith(".")) { this.Name = this.Name.TrimEnd('.'); this.WriteWarning($"Modifying Private DNS zone name to remove terminating '.'. Zone name used is \"{this.Name}\"."); } var zoneToDelete = (this.ParameterSetName != ObjectParameterSetName) ? this.PrivateDnsClient.GetDnsZoneHandleNonExistentZone(this.Name, this.ResourceGroupName) : this.PrivateZone; if (zoneToDelete == null) { throw new PSArgumentException(string.Format(ProjectResources.Error_ZoneNotFound, this.Name)); } if ((string.IsNullOrWhiteSpace(zoneToDelete.Etag) || zoneToDelete.Etag == "*") && !overwrite) { throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(PSPrivateDnsZone).Name)); } if (zoneToDelete.Name != null && zoneToDelete.Name.EndsWith(".")) { zoneToDelete.Name = zoneToDelete.Name.TrimEnd('.'); this.WriteWarning($"Modifying Private DNS zone name to remove terminating '.'. Zone name used is \"{zoneToDelete.Name}\"."); } ConfirmAction( ProjectResources.Progress_RemovingZone, zoneToDelete.Name, () => { PrivateDnsClient.DeletePrivateDnsZone(zoneToDelete, overwrite); WriteVerbose(ProjectResources.Success); WriteVerbose(string.Format(ProjectResources.Success_RemoveZone, zoneToDelete.Name, zoneToDelete.ResourceGroupName)); if (this.PassThru) { WriteObject(deleted); } }); }
public override void ExecuteCmdlet() { AppServiceEnvironmentResource ase = WebsitesClient.GetAppServiceEnvironment(ResourceGroupName, Name); string shouldProcessMessage = ""; if (ase.Kind.ToLower() == "asev2") { shouldProcessMessage = SkipDns ? "No changes will be made" : $"Create Private DNS Zone and A Records for {Name}"; } else if (ase.Kind.ToLower() == "asev3") { shouldProcessMessage = SkipDns ? $"Disable Network Policy in Subnet and create private endpoint for {Name}" : $"Disable Network Policy in Subnet, create private endpoint, and create Private DNS Zone and A Records for {Name}"; } if (ShouldProcess(Name, shouldProcessMessage)) { switch (ParameterSetName) { case SubnetNameParameterSet: case SubnetIdParameterSet: var subnet = ParameterSetName == SubnetNameParameterSet ? SubnetName : SubnetId; //Fetch RG of given Subnet var subnetResourceGroupName = NetworkClient.GetSubnetResourceGroupName(subnet, VirtualNetworkName); //If unable to fetch Subnet rg from above step, use the input RG to get validation error from api call. subnetResourceGroupName = !String.IsNullOrEmpty(subnetResourceGroupName) ? subnetResourceGroupName : ResourceGroupName; var subnetResourceId = NetworkClient.ValidateSubnet(subnet, VirtualNetworkName, subnetResourceGroupName, DefaultContext.Subscription.Id); if (ase != null) { string inboundIPAddress = ""; if (ase.Kind.ToLower() == "asev2") { // Internal ASEv2 if (ase.InternalLoadBalancingMode != "None") { var vipInfo = WebsitesClient.GetAppServiceEnvironmentAddresses(ResourceGroupName, Name); inboundIPAddress = vipInfo.InternalIpAddress; } else { throw new Exception("Private DNS Zone is not compatible with External App Service Environment"); } } else if (ase.Kind.ToLower() == "asev3") { // Create private endpoint var aseResourceId = ase.Id; var aseGroupId = "hostingEnvironments"; NetworkClient.EnsureSubnetPrivateEndpointPolicy(subnetResourceId, false); var pe = NetworkClient.CreatePrivateEndpoint(ResourceGroupName, Name, aseResourceId, aseGroupId, subnetResourceId, ase.Location); var nicId = pe.NetworkInterfaces[0].Id; inboundIPAddress = NetworkClient.GetNetworkInterfacePrivateIPAddress(nicId); } if (!SkipDns) { // Create Private DNS Zone and records var virtualNetworkResourceId = NetworkClient.GetVirtualNetworkResourceId(subnetResourceId); PrivateDnsClient.CreateAppServiceEnvironmentPrivateDnsZone(ResourceGroupName, Name, virtualNetworkResourceId, inboundIPAddress); } } break; } if (PassThru) { WriteObject(true); } } }
public override void ExecuteCmdlet() { var deleted = false; PSPrivateDnsRecordSet recordSetToDelete = null; switch (this.ParameterSetName) { case FieldsParameterSetName: case MixedParameterSetName: { if (this.Name.EndsWith(".")) { this.Name = this.Name.TrimEnd('.'); this.WriteWarning(string.Format(ProjectResources.Progress_ModifyingRecordSetNameTrimDot, this.Name)); } recordSetToDelete = new PSPrivateDnsRecordSet { Name = this.Name, Etag = null, RecordType = this.RecordType, ResourceGroupName = (this.ParameterSetName == FieldsParameterSetName) ? this.ResourceGroupName : this.Zone.ResourceGroupName, ZoneName = (this.ParameterSetName == FieldsParameterSetName) ? this.ZoneName : this.Zone.Name, }; break; } case ObjectParameterSetName when(string.IsNullOrWhiteSpace(this.RecordSet.Etag) || this.RecordSet.Etag == "*") && !this.Overwrite.IsPresent: throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(PSPrivateDnsRecordSet).Name)); case ObjectParameterSetName: recordSetToDelete = this.RecordSet; break; case ResourceParameterSetName: { PrivateDnsUtils.GetResourceGroupNameZoneNameRecordNameAndRecordTypeFromResourceId(ResourceId, out var resourceGroupName, out var zoneName, out var recordName, out var recordType); recordSetToDelete = new PSPrivateDnsRecordSet { Name = recordName, Etag = null, RecordType = (RecordType)Enum.Parse(typeof(RecordType), recordType, true), ResourceGroupName = resourceGroupName, ZoneName = zoneName, }; break; } } if (recordSetToDelete?.ZoneName != null) { recordSetToDelete.ZoneName = TrimTrailingDotInZoneName(recordSetToDelete.ZoneName); } var overwrite = this.Overwrite.IsPresent || this.ParameterSetName != ObjectParameterSetName; ConfirmAction( ProjectResources.Progress_RemovingRecordSet, this.Name, () => { deleted = PrivateDnsClient.DeletePrivateDnsRecordSet(recordSetToDelete, overwrite); if (deleted) { WriteVerbose(ProjectResources.Success); WriteVerbose(ProjectResources.Success_RemoveRecordSet); } if (this.PassThru) { WriteObject(deleted); } }); }