Esempio n. 1
0
        public override void ExecuteCmdlet()
        {
            var existingProfile = FrontDoorManagementClient.FrontDoors.ListByResourceGroup(ResourceGroupName)
                                  .Where(p => p.Name.ToLower() == Name.ToLower());

            if (existingProfile.Count() != 0)
            {
                throw new PSArgumentException(string.Format(Resources.Error_CreateExistingFrontDoor,
                                                            Name,
                                                            ResourceGroupName));
            }
            var updateParameters = new Management.FrontDoor.Models.FrontDoorModel(
                id: null,
                name: Name,
                type: null,
                location: "global",
                tags: Tag.ToDictionaryTags(),
                friendlyName: Name,
                routingRules: RoutingRule?.Select(x => x.ToSdkRoutingRule()).ToList(),
                loadBalancingSettings: LoadBalancingSetting?.Select(x => x.ToSdkLoadBalancingSetting()).ToList(),
                healthProbeSettings: HealthProbeSetting?.Select(x => x.ToSdkHealthProbeSetting()).ToList(),
                backendPools: BackendPool?.Select(x => x.ToSdkBackendPool()).ToList(),
                frontendEndpoints: FrontendEndpoint?.Select(x => x.ToSdkFrontendEndpoints()).ToList(),
                enabledState: !this.IsParameterBound(c => c.EnabledState)? "Enabled" : EnabledState.ToString(),
                backendPoolsSettings: new Management.FrontDoor.Models.BackendPoolsSettings(
                    DisableCertificateNameCheck ? PSEnforceCertificateNameCheck.Disabled.ToString() : PSEnforceCertificateNameCheck.Enabled.ToString())
                );

            updateParameters.ToPSFrontDoor().ValidateFrontDoor(ResourceGroupName, this.DefaultContext.Subscription.Id);
            if (ShouldProcess(Resources.FrontDoorTarget, string.Format(Resources.CreateFrontDoor, Name)))
            {
                try
                {
                    var frontDoor = FrontDoorManagementClient.FrontDoors.CreateOrUpdate(
                        ResourceGroupName,
                        Name,
                        updateParameters
                        );
                    WriteObject(frontDoor.ToPSFrontDoor());
                }
                catch (Microsoft.Azure.Management.FrontDoor.Models.ErrorResponseException e)
                {
                    throw new PSArgumentException(string.Format(Resources.Error_ErrorResponseFromServer,
                                                                e.Response.Content));
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ObjectParameterSet)
            {
                ResourceIdentifier identifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = identifier.ResourceGroupName;
                Name = InputObject.Name;
            }
            else if (ParameterSetName == ResourceIdParameterSet)
            {
                ResourceIdentifier identifier = new ResourceIdentifier(ResourceId);
                ResourceGroupName = identifier.ResourceGroupName;
                Name = InputObject.Name;
            }


            var existingFrontDoor = FrontDoorManagementClient.FrontDoors.ListByResourceGroup(ResourceGroupName)
                                    .FirstOrDefault(fd => fd.Name.ToLower() == Name.ToLower());


            if (existingFrontDoor == null)
            {
                throw new PSArgumentException(string.Format(
                                                  Resources.Error_FrontDoorNotFound,
                                                  Name,
                                                  ResourceGroupName));
            }

            PSFrontDoor updateParameters;

            if (ParameterSetName == ObjectParameterSet)
            {
                updateParameters = InputObject;
            }
            else
            {
                updateParameters = existingFrontDoor.ToPSFrontDoor();
            }

            // update each field based on optional input.
            if (this.IsParameterBound(c => c.RoutingRule))
            {
                updateParameters.RoutingRules = RoutingRule.ToList();
            }

            if (this.IsParameterBound(c => c.FrontendEndpoint))
            {
                updateParameters.FrontendEndpoints = FrontendEndpoint.ToList();
            }

            if (this.IsParameterBound(c => c.HealthProbeSetting))
            {
                updateParameters.HealthProbeSettings = HealthProbeSetting.ToList();
            }

            if (this.IsParameterBound(c => c.LoadBalancingSetting))
            {
                updateParameters.LoadBalancingSettings = LoadBalancingSetting.ToList();
            }

            if (this.IsParameterBound(c => c.BackendPool))
            {
                updateParameters.BackendPools = BackendPool.ToList();
            }

            if (this.IsParameterBound(c => c.Tag))
            {
                updateParameters.Tags = Tag;
            }

            if (this.IsParameterBound(c => c.EnabledState))
            {
                updateParameters.EnabledState = EnabledState;
            }

            if (this.IsParameterBound(c => c.DisableCertificateNameCheck))
            {
                updateParameters.EnforceCertificateNameCheck = DisableCertificateNameCheck ? PSEnforceCertificateNameCheck.Disabled : PSEnforceCertificateNameCheck.Enabled;
            }

            updateParameters.ValidateFrontDoor(ResourceGroupName, this.DefaultContext.Subscription.Id);
            if (ShouldProcess(Resources.FrontDoorTarget, string.Format(Resources.FrontDoorChangeWarning, Name)))
            {
                try
                {
                    var frontDoor = FrontDoorManagementClient.FrontDoors.CreateOrUpdate(
                        ResourceGroupName,
                        Name,
                        updateParameters.ToSdkFrontDoor()
                        );
                    WriteObject(frontDoor.ToPSFrontDoor());
                }
                catch (Microsoft.Azure.Management.FrontDoor.Models.ErrorResponseException e)
                {
                    throw new PSArgumentException(string.Format(
                                                      Resources.Error_ErrorResponseFromServer,
                                                      e.Response.Content));
                }
            }
        }