public override void ExecuteCmdlet() { string zoneName = null; string resourceGroupName = null; PSPrivateDnsRecordSet result = null; if (RecordType == RecordType.SOA) { throw new System.ArgumentException(ProjectResources.Error_AddRecordSOA); } switch (this.ParameterSetName) { case FieldsParameterSetName: zoneName = this.ZoneName; resourceGroupName = this.ResourceGroupName; break; case ObjectParameterSetName: zoneName = this.Zone.Name; resourceGroupName = this.Zone.ResourceGroupName; break; case ResourceParameterSetName: PrivateDnsUtils.GetResourceGroupNameAndZoneNameFromResourceId(this.ParentResourceId, out resourceGroupName, out zoneName); break; } if (zoneName != null && this.Name.EndsWith(zoneName)) { this.WriteWarning(string.Format(ProjectResources.Error_RecordSetNameEndsWithZoneName, this.Name, zoneName)); } zoneName = TrimTrailingDotInZoneName(zoneName); ConfirmAction( ProjectResources.Progress_CreatingRecordSet, this.Name, () => { result = this.PrivateDnsClient.CreatePrivateDnsRecordSet( zoneName, resourceGroupName, this.Name, this.Ttl, this.RecordType, this.Metadata, this.Overwrite, this.PrivateDnsRecord); if (result != null) { WriteVerbose(ProjectResources.Success); WriteVerbose(string.Format(ProjectResources.Success_NewRecordSet, this.Name, zoneName, this.RecordType)); WriteVerbose(string.Format(ProjectResources.Success_RecordSetFqdn, this.Name, zoneName, this.RecordType)); } WriteObject(result); }); }
public override void ExecuteCmdlet() { PSPrivateDnsZone result = null; PSPrivateDnsZone zoneToUpdate = null; if (this.ParameterSetName == FieldsParameterSetName || this.ParameterSetName == ResourceParameterSetName) { if (!string.IsNullOrEmpty(this.ResourceId)) { PrivateDnsUtils.GetResourceGroupNameAndZoneNameFromResourceId(this.ResourceId, out var resourceGroupName, out var zoneName); this.ResourceGroupName = resourceGroupName; this.Name = zoneName; } if (this.Name.EndsWith(".")) { this.Name = this.Name.TrimEnd('.'); this.WriteWarning($"Modifying Private DNS zone name to remove terminating '.'. Zone name used is \"{this.Name}\"."); } zoneToUpdate = this.PrivateDnsClient.GetPrivateDnsZone(this.Name, this.ResourceGroupName); zoneToUpdate.Etag = "*"; } else if (this.ParameterSetName == ObjectParameterSetName) { if ((string.IsNullOrWhiteSpace(this.PrivateZone.Etag) || this.PrivateZone.Etag == "*") && !this.Overwrite.IsPresent) { throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(PSPrivateDnsZone).Name)); } zoneToUpdate = this.PrivateZone; } if (zoneToUpdate == null) { throw new PSArgumentException(string.Format(ProjectResources.Error_ZoneNotFound), this.Name); } zoneToUpdate.Tags = this.Tag; if (zoneToUpdate.Name != null && zoneToUpdate.Name.EndsWith(".")) { zoneToUpdate.Name = zoneToUpdate.Name.TrimEnd('.'); this.WriteWarning($"Modifying Private DNS zone name to remove terminating '.'. Zone name used is \"{zoneToUpdate.Name}\"."); } ConfirmAction( ProjectResources.Progress_Modifying, zoneToUpdate?.Name, () => { bool overwrite = this.Overwrite.IsPresent || this.ParameterSetName != ObjectParameterSetName; result = this.PrivateDnsClient.UpdatePrivateDnsZone(zoneToUpdate, overwrite); WriteVerbose(ProjectResources.Success); WriteObject(result); }); }
public override void ExecuteCmdlet() { PSPrivateDnsVirtualNetworkLink result = null; PSPrivateDnsVirtualNetworkLink linkToUpdate = null; switch (this.ParameterSetName) { case FieldsParameterSetName: case ResourceParameterSetName: { 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; } this.ZoneName = TrimTrailingDotInZoneName(this.ZoneName); linkToUpdate = this.PrivateDnsClient.GetPrivateDnsLink(this.Name, this.ResourceGroupName, this.ZoneName); linkToUpdate.Etag = "*"; linkToUpdate.ZoneName = this.ZoneName; break; } case ObjectParameterSetName when(string.IsNullOrWhiteSpace(this.InputObject.Etag) || this.InputObject.Etag == "*") && !this.Overwrite.IsPresent: throw new PSArgumentException(string.Format(ProjectResources.Error_EtagNotSpecified, typeof(PSPrivateDnsVirtualNetworkLink).Name)); case ObjectParameterSetName: linkToUpdate = this.InputObject; break; } if (this.Tag != null) { linkToUpdate.Tags = this.Tag; } if (this.IsRegistrationEnabled != null) { linkToUpdate.RegistrationEnabled = this.IsRegistrationEnabled.Value; } ConfirmAction( ProjectResources.Progress_Modifying, linkToUpdate?.Name, () => { var overwrite = this.Overwrite.IsPresent || this.ParameterSetName != ObjectParameterSetName; result = this.PrivateDnsClient.UpdatePrivateDnsLink(linkToUpdate, overwrite); WriteVerbose(ProjectResources.Success); WriteObject(result); }); }
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); } }); }
private static PSPrivateDnsZone ToPrivateDnsZone(PrivateZone zone) { PrivateDnsUtils.GetResourceGroupNameFromResourceId(zone.Id, out var resourceGroupName); return(new PSPrivateDnsZone() { Name = zone.Name, ResourceId = zone.Id, ResourceGroupName = resourceGroupName, Etag = zone.Etag, Tags = TagsConversionHelper.CreateTagHashtable(zone.Tags), NumberOfRecordSets = zone.NumberOfRecordSets, MaxNumberOfRecordSets = zone.MaxNumberOfRecordSets, }); }
private static PSPrivateDnsVirtualNetworkLink ToPrivateDnsLink(VirtualNetworkLink link) { PrivateDnsUtils.ParseVirtualNetworkId(link.Id, out var resourceGroupName, out var zoneName, out var linkName); return(new PSPrivateDnsVirtualNetworkLink() { Name = link.Name, ResourceId = link.Id, ResourceGroupName = resourceGroupName, ZoneName = zoneName, Etag = link.Etag, Tags = TagsConversionHelper.CreateTagHashtable(link.Tags), VirtualNetworkId = link.VirtualNetwork.Id, RegistrationEnabled = link.RegistrationEnabled != null && (bool)link.RegistrationEnabled, ProvisioningState = link.ProvisioningState, VirtualNetworkLinkState = link.VirtualNetworkLinkState, }); }
public override void ExecuteCmdlet() { string zoneName = null; string resourceGroupName = null; switch (this.ParameterSetName) { case FieldsParameterSetName: case FieldsWithNoNameParameterSetName: zoneName = this.ZoneName; resourceGroupName = this.ResourceGroupName; break; case ResourceParameterSetName: case ResourceWithNoNameParameterSetName: PrivateDnsUtils.GetResourceGroupNameAndZoneNameFromResourceId(this.ParentResourceId, out resourceGroupName, out zoneName); break; default: zoneName = this.Zone.Name; resourceGroupName = this.Zone.ResourceGroupName; break; } zoneName = TrimTrailingDotInZoneName(zoneName); if (this.Name != null) { if (this.RecordType == null) { throw new PSArgumentException(ProjectResources.Error_RecordTypeNotSpecified); } var result = this.PrivateDnsClient.GetPrivateDnsRecordSet(this.Name, zoneName, resourceGroupName, this.RecordType.Value); this.WriteObject(result); } else { List <PSPrivateDnsRecordSet> result = null; result = this.RecordType == null?this.PrivateDnsClient.ListRecordSets(zoneName, resourceGroupName) : this.PrivateDnsClient.ListRecordSets(zoneName, resourceGroupName, this.RecordType.Value); this.WriteObject(result, 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); } }); }