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 static void VerifyOriginUpdated(AFDOriginUpdateParameters originUpdateProperties, AFDOrigin origin) { Assert.NotNull(origin); Assert.Equal(originUpdateProperties.HostName, origin.HostName); Assert.Equal(originUpdateProperties.OriginHostHeader, origin.OriginHostHeader); Assert.Equal(originUpdateProperties.HttpPort, origin.HttpPort); Assert.Equal(originUpdateProperties.HttpsPort, origin.HttpsPort); Assert.Equal(originUpdateProperties.Priority, origin.Priority); Assert.Equal(originUpdateProperties.Weight, origin.Weight); }
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); }
public void AFDOriginUpdateTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); string originGroupName = TestUtilities.GenerateName("originGroupName"); var originGroupCreateParameters = new AFDOriginGroup(name: originGroupName) { LoadBalancingSettings = new LoadBalancingSettingsParameters { SampleSize = 5, SuccessfulSamplesRequired = 4, AdditionalLatencyInMilliseconds = 200, }, HealthProbeSettings = new HealthProbeParameters { ProbeIntervalInSeconds = 1, ProbePath = "/", ProbeProtocol = ProbeProtocol.Https, ProbeRequestType = HealthProbeRequestType.GET }, }; var originGroup = cdnMgmtClient.AFDOriginGroups.Create(resourceGroupName, profileName, originGroupName, originGroupCreateParameters); Assert.NotNull(originGroup); Assert.Equal(originGroupName, originGroup.Name); string originName = TestUtilities.GenerateName("originName"); var hostName = "en.wikipedia.org"; var originCreateParameters = new AFDOrigin(hostName: hostName) { OriginHostHeader = hostName, HttpPort = 80, HttpsPort = 443, Priority = 1, Weight = 1000, }; var origin = cdnMgmtClient.AFDOrigins.Create(resourceGroupName, profileName, originGroupName, originName, originCreateParameters); VerifyOriginCreated(originName, originCreateParameters, origin); var originUpdateProperties = new AFDOriginUpdateParameters { HostName = "update." + hostName, OriginHostHeader = "update." + hostName, HttpPort = 81, HttpsPort = 443, Priority = 2, Weight = 100, }; var updatedOrigin = cdnMgmtClient.AFDOrigins.Update(resourceGroupName, profileName, originGroupName, originName, originUpdateProperties); VerifyOriginUpdated(originUpdateProperties, updatedOrigin); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
/// <summary> /// Updates an existing origin within an origin group. /// </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='profileName'> /// Name of the CDN profile which is unique within the resource group. /// </param> /// <param name='originGroupName'> /// Name of the origin group which is unique within the profile. /// </param> /// <param name='originName'> /// Name of the origin which is unique within the profile. /// </param> /// <param name='originUpdateProperties'> /// Origin properties /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <AFDOrigin> BeginUpdateAsync(this IAFDOriginsOperations operations, string resourceGroupName, string profileName, string originGroupName, string originName, AFDOriginUpdateParameters originUpdateProperties, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginUpdateWithHttpMessagesAsync(resourceGroupName, profileName, originGroupName, originName, originUpdateProperties, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Updates an existing origin within an origin group. /// </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='profileName'> /// Name of the CDN profile which is unique within the resource group. /// </param> /// <param name='originGroupName'> /// Name of the origin group which is unique within the profile. /// </param> /// <param name='originName'> /// Name of the origin which is unique within the profile. /// </param> /// <param name='originUpdateProperties'> /// Origin properties /// </param> public static AFDOrigin BeginUpdate(this IAFDOriginsOperations operations, string resourceGroupName, string profileName, string originGroupName, string originName, AFDOriginUpdateParameters originUpdateProperties) { return(operations.BeginUpdateAsync(resourceGroupName, profileName, originGroupName, originName, originUpdateProperties).GetAwaiter().GetResult()); }