private void UpdateAfdOrigin() { try { PSAfdOrigin currentPsAfdOrigin = this.CdnManagementClient.AFDOrigins.Get(this.ResourceGroupName, this.ProfileName, this.OriginGroupName, this.OriginName).ToPSAfdOrigin(); AFDOriginUpdateParameters afdOrigin = new AFDOriginUpdateParameters(); if (ParameterSetName == ObjectParameterSet) { afdOrigin = this.CreateAfdOriginUpdateByObject(currentPsAfdOrigin); } if (ParameterSetName == FieldsParameterSet) { afdOrigin = this.CreateAfdOriginUpdateByFields(currentPsAfdOrigin); } PSAfdOrigin updatedPsAfdOrigin = this.CdnManagementClient.AFDOrigins.Update(this.ResourceGroupName, this.ProfileName, this.OriginGroupName, this.OriginName, afdOrigin).ToPSAfdOrigin(); updatedPsAfdOrigin.OriginGroupName = this.OriginGroupName; WriteObject(updatedPsAfdOrigin); } catch (AfdErrorResponseException errorResponse) { throw new PSArgumentException(errorResponse.Response.Content); } }
private void ResourceIdParameterSetCmdlet() { ResourceIdentifier parsedAfdOriginId = new ResourceIdentifier(this.ResourceId); this.OriginName = parsedAfdOriginId.ResourceName; this.OriginGroupName = parsedAfdOriginId.GetResourceName("origingroups"); this.ProfileName = parsedAfdOriginId.GetResourceName("profiles"); this.ResourceGroupName = parsedAfdOriginId.ResourceGroupName; PSAfdOrigin psAfdOrigin = CdnManagementClient.AFDOrigins.Get(this.ResourceGroupName, this.ProfileName, this.OriginGroupName, this.OriginName).ToPSAfdOrigin(); // add origin group name from the parameter input since its not provided by the SDK psAfdOrigin.OriginGroupName = this.OriginGroupName; WriteObject(psAfdOrigin); }
private void CreateAfdOrigin() { try { AFDOrigin afdOrigin = new AFDOrigin { HostName = this.HostName, SharedPrivateLinkResource = this.CreateSharedPrivateLinkResource() }; if (this.MyInvocation.BoundParameters.ContainsKey("HttpPort")) { afdOrigin.HttpPort = this.HttpPort; } if (this.MyInvocation.BoundParameters.ContainsKey("HttpsPort")) { afdOrigin.HttpsPort = this.HttpsPort; } if (this.MyInvocation.BoundParameters.ContainsKey("OriginHostHeader")) { afdOrigin.OriginHostHeader = this.OriginHostHeader; } if (this.MyInvocation.BoundParameters.ContainsKey("Priority")) { afdOrigin.Priority = this.Priority; } if (this.MyInvocation.BoundParameters.ContainsKey("Weight")) { afdOrigin.Weight = this.Weight; } PSAfdOrigin psAfdOrigin = this.CdnManagementClient.AFDOrigins.Create(this.ResourceGroupName, this.ProfileName, this.OriginGroupName, this.OriginName, afdOrigin).ToPSAfdOrigin(); psAfdOrigin.OriginGroupName = this.OriginGroupName; WriteObject(psAfdOrigin); } catch (AfdErrorResponseException errorResponse) { throw new PSArgumentException(errorResponse.Response.Content); } }
public void FieldsParameterSetCmdlet() { if (AfdUtilities.IsValuePresent(this.OriginName)) { // all fields are present (mandatory + optional) PSAfdOrigin psAfdOrigin = this.CdnManagementClient.AFDOrigins.Get(this.ResourceGroupName, this.ProfileName, this.OriginGroupName, this.OriginName).ToPSAfdOrigin(); // add origin group name from the parameter input since its not provided by the SDK psAfdOrigin.OriginGroupName = this.OriginGroupName; WriteObject(psAfdOrigin); } else { // only the mandatory fields are present List <PSAfdOrigin> psAfdOrigins = this.CdnManagementClient.AFDOrigins.ListByOriginGroup(this.ResourceGroupName, this.ProfileName, this.OriginGroupName) .Select(afdOrigin => afdOrigin.ToPSAfdOrigin()) .ToList(); // add the origin group name for each of the origins foreach (PSAfdOrigin psAfdOrigin in psAfdOrigins) { psAfdOrigin.OriginGroupName = this.OriginGroupName; } // sdk will not give an error if the origin group is invalid / does not exist if (psAfdOrigins.Count == 0) { WriteObject($"No origins were found in the origin group {this.OriginGroupName}. Please ensure the origin group name is correct and has origins."); } WriteObject(psAfdOrigins); } }
private AFDOriginUpdateParameters CreateAfdOriginUpdateByFields(PSAfdOrigin currentPsAfdOrigin) { bool isHostName = this.MyInvocation.BoundParameters.ContainsKey("HostName"); bool isHttpPort = this.MyInvocation.BoundParameters.ContainsKey("HttpPort"); bool isHttpsPort = this.MyInvocation.BoundParameters.ContainsKey("HttpsPort"); bool isPriority = this.MyInvocation.BoundParameters.ContainsKey("Priority"); bool isWeight = this.MyInvocation.BoundParameters.ContainsKey("Weight"); bool isOriginHostHeader = this.MyInvocation.BoundParameters.ContainsKey("OriginHostHeader"); bool isPrivateLinkId = this.MyInvocation.BoundParameters.ContainsKey("PrivateLinkId"); bool isPrivateLinkLocation = this.MyInvocation.BoundParameters.ContainsKey("PrivateLinkLocation"); bool isPrivateLinkRequestMessage = this.MyInvocation.BoundParameters.ContainsKey("PrivateLinkRequestMessage"); AFDOriginUpdateParameters afdOrigin = new AFDOriginUpdateParameters { HostName = currentPsAfdOrigin.HostName, HttpPort = currentPsAfdOrigin.HttpPort, HttpsPort = currentPsAfdOrigin.HttpsPort, OriginHostHeader = currentPsAfdOrigin.OriginHostHeader, Priority = currentPsAfdOrigin.Priority, Weight = currentPsAfdOrigin.Weight, }; if (isHostName) { afdOrigin.HostName = this.HostName; } if (isHttpPort) { afdOrigin.HttpPort = this.HttpPort; } if (isHttpsPort) { afdOrigin.HttpsPort = this.HttpsPort; } if (isPriority) { afdOrigin.Priority = this.Priority; } if (isWeight) { afdOrigin.Weight = this.Weight; } if (isOriginHostHeader) { afdOrigin.OriginHostHeader = this.OriginHostHeader; } if (isPrivateLinkId || isPrivateLinkLocation || isPrivateLinkRequestMessage) { SharedPrivateLinkResourceProperties sharedPrivateLinkResource = new SharedPrivateLinkResourceProperties { PrivateLink = new ResourceReference(currentPsAfdOrigin.PrivateLinkId), PrivateLinkLocation = currentPsAfdOrigin.PrivateLinkLocation, RequestMessage = currentPsAfdOrigin.PrivateLinkRequestMessage }; if (isPrivateLinkId) { sharedPrivateLinkResource.PrivateLink.Id = this.PrivateLinkId; afdOrigin.SharedPrivateLinkResource = sharedPrivateLinkResource; } if (isPrivateLinkLocation) { sharedPrivateLinkResource.PrivateLinkLocation = this.PrivateLinkLocation; afdOrigin.SharedPrivateLinkResource = sharedPrivateLinkResource; } if (isPrivateLinkRequestMessage) { sharedPrivateLinkResource.RequestMessage = this.PrivateLinkRequestMessage; afdOrigin.SharedPrivateLinkResource = sharedPrivateLinkResource; } } return(afdOrigin); }
private AFDOriginUpdateParameters CreateAfdOriginUpdateByObject(PSAfdOrigin currentPsAfdOrigin) { SharedPrivateLinkResourceProperties sharedPrivateLinkResource = new SharedPrivateLinkResourceProperties { PrivateLink = new ResourceReference(currentPsAfdOrigin.PrivateLinkId), PrivateLinkLocation = currentPsAfdOrigin.PrivateLinkLocation, RequestMessage = currentPsAfdOrigin.PrivateLinkRequestMessage }; AFDOriginUpdateParameters afdOrigin = new AFDOriginUpdateParameters { HostName = currentPsAfdOrigin.HostName, HttpPort = currentPsAfdOrigin.HttpPort, HttpsPort = currentPsAfdOrigin.HttpsPort, OriginHostHeader = currentPsAfdOrigin.OriginHostHeader, Priority = currentPsAfdOrigin.Priority, Weight = currentPsAfdOrigin.Weight, SharedPrivateLinkResource = sharedPrivateLinkResource }; if (this.Origin.HostName != currentPsAfdOrigin.HostName) { afdOrigin.HostName = this.Origin.HostName; } if (this.Origin.HttpPort != currentPsAfdOrigin.HttpPort) { afdOrigin.HttpPort = this.Origin.HttpPort; } if (this.Origin.HttpsPort != currentPsAfdOrigin.HttpsPort) { afdOrigin.HttpsPort = this.Origin.HttpsPort; } if (this.Origin.OriginHostHeader != currentPsAfdOrigin.OriginHostHeader) { afdOrigin.OriginHostHeader = this.Origin.OriginHostHeader; } if (this.Origin.Priority != currentPsAfdOrigin.Priority) { afdOrigin.Priority = this.Origin.Priority; } if (this.Origin.Weight != currentPsAfdOrigin.Weight) { afdOrigin.Weight = this.Origin.Weight; } if (this.Origin.PrivateLinkId != currentPsAfdOrigin.PrivateLinkId) { sharedPrivateLinkResource.PrivateLink.Id = this.Origin.PrivateLinkId; afdOrigin.SharedPrivateLinkResource = sharedPrivateLinkResource; } if (this.Origin.PrivateLinkLocation != currentPsAfdOrigin.PrivateLinkLocation) { sharedPrivateLinkResource.PrivateLinkLocation = this.Origin.PrivateLinkLocation; afdOrigin.SharedPrivateLinkResource = sharedPrivateLinkResource; } if (this.Origin.PrivateLinkRequestMessage != currentPsAfdOrigin.PrivateLinkRequestMessage) { sharedPrivateLinkResource.RequestMessage = this.Origin.PrivateLinkRequestMessage; afdOrigin.SharedPrivateLinkResource = sharedPrivateLinkResource; } return(afdOrigin); }