Exemplo n.º 1
0
        private void CreateAfdCustomDomain()
        {
            try
            {
                AFDDomain afdCustomDomain = new AFDDomain
                {
                    HostName = this.HostName,
                };

                if (MyInvocation.BoundParameters.ContainsKey("AzureDnsZoneId"))
                {
                    afdCustomDomain.AzureDnsZone = new ResourceReference(this.AzureDnsZoneId);
                }

                if (ParameterSetName == AfdParameterSet.AfdCustomDomainCustomerCertificate)
                {
                    afdCustomDomain.TlsSettings = new AFDDomainHttpsParameters
                    {
                        CertificateType   = "CustomerCertificate",
                        MinimumTlsVersion = AfdUtilities.CreateMinimumTlsVersion(this.MinimumTlsVersion),
                        Secret            = new ResourceReference(this.SecretId)
                    };
                }

                PSAfdCustomDomain psAfdCustomDomain = this.CdnManagementClient.AFDCustomDomains.Create(this.ResourceGroupName, this.ProfileName, this.CustomDomainName, afdCustomDomain).ToPSAfdCustomDomain();

                WriteObject(psAfdCustomDomain);
            }
            catch (AfdErrorResponseException errorResponse)
            {
                throw new PSArgumentException(errorResponse.Response.Content);
            }
        }
        private HealthProbeParameters CreateHealthProbeSettingsByObject(PSAfdOriginGroup currentPsAfdOriginGroup, PSAfdOriginGroup proposedPsAfdOriginGroup)
        {
            HealthProbeParameters healthProbeSettings = new HealthProbeParameters
            {
                ProbeIntervalInSeconds = currentPsAfdOriginGroup.ProbeIntervalInSeconds,
                ProbePath        = currentPsAfdOriginGroup.ProbePath,
                ProbeProtocol    = AfdUtilities.CreateProbeProtocol(currentPsAfdOriginGroup.ProbeProtocol),
                ProbeRequestType = AfdUtilities.CreateProbeRequestType(currentPsAfdOriginGroup.ProbeRequestType)
            };

            if (proposedPsAfdOriginGroup.ProbeIntervalInSeconds != currentPsAfdOriginGroup.ProbeIntervalInSeconds)
            {
                healthProbeSettings.ProbeIntervalInSeconds = proposedPsAfdOriginGroup.ProbeIntervalInSeconds;
            }

            if (proposedPsAfdOriginGroup.ProbePath != currentPsAfdOriginGroup.ProbePath)
            {
                healthProbeSettings.ProbePath = proposedPsAfdOriginGroup.ProbePath;
            }

            if (proposedPsAfdOriginGroup.ProbeProtocol != currentPsAfdOriginGroup.ProbeProtocol)
            {
                healthProbeSettings.ProbeProtocol = AfdUtilities.CreateProbeProtocol(proposedPsAfdOriginGroup.ProbeProtocol);
            }

            if (proposedPsAfdOriginGroup.ProbeRequestType != currentPsAfdOriginGroup.ProbeRequestType)
            {
                healthProbeSettings.ProbeRequestType = AfdUtilities.CreateProbeRequestType(proposedPsAfdOriginGroup.ProbeRequestType);
            }

            return(healthProbeSettings);
        }
Exemplo n.º 3
0
        private void CreateAfdProfile()
        {
            try
            {
                Sku afdSku = AfdUtilities.GenerateAfdProfileSku(this.Sku);

                if (afdSku == null)
                {
                    throw new PSArgumentException($"{this.Sku} is not a valid SKU. Please use {AfdSkuConstants.PremiumAzureFrontDoor} or {AfdSkuConstants.StandardAzureFrontDoor}.");
                }

                Management.Cdn.Models.Profile afdProfile = new Management.Cdn.Models.Profile
                {
                    Location = AfdResourceConstants.AfdResourceLocation,
                    Sku      = afdSku,
                    Tags     = TagsConversionHelper.CreateTagDictionary(this.Tag, true)
                };

                PSAfdProfile psAfdProfile = this.CdnManagementClient.Profiles.Create(this.ResourceGroupName, this.ProfileName, afdProfile).ToPSAfdProfile();

                WriteObject(psAfdProfile);
            }
            catch (AfdErrorResponseException errorResponseException)
            {
                throw new PSArgumentException(errorResponseException.Response.Content);
            }
        }
Exemplo n.º 4
0
        private void UpdateAfdProfile()
        {
            PSAfdProfile profile = CdnManagementClient.Profiles.Get(this.ResourceGroupName, this.ProfileName).ToPSAfdProfile();

            if (!AfdUtilities.IsAfdProfile(profile))
            {
                throw new PSArgumentException($"You are attempting to update a {profile.Sku} profile. Please use Set-AzCdnProfile instead.");
            }

            Dictionary <string, string> afdProfileTags = TagsConversionHelper.CreateTagDictionary(this.Tags, true);

            PSAfdProfile psAfdProfile = this.CdnManagementClient.Profiles.Update(this.ResourceGroupName, this.ProfileName, afdProfileTags).ToPSAfdProfile();

            WriteObject(psAfdProfile);
        }
Exemplo n.º 5
0
        private HealthProbeParameters CreateHealthProbeSettings(bool isProbePath, bool isProbeRequestType, bool isProbeProtocol, bool isProbeIntervalInSeconds)
        {
            if (!isProbePath && !isProbeRequestType && !isProbeProtocol && !isProbeIntervalInSeconds)
            {
                return(null);
            }

            HealthProbeParameters healthProbeSettings = new HealthProbeParameters
            {
                ProbePath              = isProbePath ? this.ProbePath : "/",
                ProbeRequestType       = isProbeRequestType ? AfdUtilities.CreateProbeRequestType(this.ProbeRequestType) : HealthProbeRequestType.HEAD,
                ProbeProtocol          = isProbeProtocol ? AfdUtilities.CreateProbeProtocol(this.ProbeProtocol) : Management.Cdn.Models.ProbeProtocol.Http,
                ProbeIntervalInSeconds = isProbeIntervalInSeconds ? this.ProbeIntervalInSeconds : 240
            };

            return(healthProbeSettings);
        }
Exemplo n.º 6
0
        private void FieldsParameterSetCmdlet()
        {
            if (AfdUtilities.IsValuePresent(this.ResourceGroupName) && AfdUtilities.IsValuePresent(this.ProfileName))
            {
                PSAfdProfile psAfdProfile = CdnManagementClient.Profiles.Get(this.ResourceGroupName, this.ProfileName).ToPSAfdProfile();
                WriteObject(psAfdProfile);
            }
            else if (AfdUtilities.IsValuePresent(this.ResourceGroupName) && this.ProfileName == null)
            {
                List <PSAfdProfile> psAfdProfiles = CdnManagementClient.Profiles.ListByResourceGroup(this.ResourceGroupName)
                                                    .Where(afdProfile => (afdProfile.Sku.Name == AfdSkuConstants.PremiumAzureFrontDoor || afdProfile.Sku.Name == AfdSkuConstants.StandardAzureFrontDoor))
                                                    .Select(afdProfile => afdProfile.ToPSAfdProfile())
                                                    .ToList();
                WriteObject(psAfdProfiles);
            }
            else if (this.ResourceGroupName == null && AfdUtilities.IsValuePresent(this.ProfileName))
            {
                // not all profiles are delivered by the payload, limitation somewhere in the RP?

                List <PSAfdProfile> psAfdProfiles = CdnManagementClient.Profiles.List()
                                                    .Where(afdProfile => afdProfile.Name == this.ProfileName)
                                                    .Select(afdProfile => afdProfile.ToPSAfdProfile())
                                                    .ToList();

                PSAfdProfile psAfdProfile = psAfdProfiles.Count > 0 ? psAfdProfiles.First() : null;

                WriteObject(psAfdProfile);
            }
            else
            {
                // both resource group and profile name are null
                // show all profiles in the subscription
                // not all profiles are delivered by the payload, limitation somewhere in the RP?

                List <PSAfdProfile> psAfdProfiles = CdnManagementClient.Profiles.List()
                                                    .Where(afdProfile => (afdProfile.Sku.Name == AfdSkuConstants.PremiumAzureFrontDoor || afdProfile.Sku.Name == AfdSkuConstants.StandardAzureFrontDoor))
                                                    .Select(afdProfile => afdProfile.ToPSAfdProfile())
                                                    .ToList();

                WriteObject(psAfdProfiles);
            }
        }
        private void FieldsParameterSetCmdlet()
        {
            if (AfdUtilities.IsValuePresent(this.CustomDomainName))
            {
                // all fields are present (mandatory + optional)

                PSAfdCustomDomain psAfdCustomDomain = this.CdnManagementClient.AFDCustomDomains.Get(this.ResourceGroupName, this.ProfileName, this.CustomDomainName).ToPSAfdCustomDomain();

                WriteObject(psAfdCustomDomain);
            }
            else
            {
                // only the mandatory fields are present

                List <PSAfdCustomDomain> psAfdCustomDomains = this.CdnManagementClient.AFDCustomDomains.ListByProfile(this.ResourceGroupName, this.ProfileName)
                                                              .Select(afdCustomDomain => afdCustomDomain.ToPSAfdCustomDomain())
                                                              .ToList();

                WriteObject(psAfdCustomDomains);
            }
        }
        private void FieldsParameterSetCmdlet()
        {
            if (AfdUtilities.IsValuePresent(this.EndpointName))
            {
                // all fields are present (mandatory + optional)

                PSAfdEndpoint psAfdEndpoint = CdnManagementClient.AFDEndpoints.Get(this.ResourceGroupName, this.ProfileName, this.EndpointName).ToPSAfdEndpoint();

                WriteObject(psAfdEndpoint);
            }
            else
            {
                // only the mandatory fields are present

                List <PSAfdEndpoint> psAfdEndpoints = CdnManagementClient.AFDEndpoints.ListByProfile(this.ResourceGroupName, this.ProfileName)
                                                      .Select(afdEndpoint => afdEndpoint.ToPSAfdEndpoint())
                                                      .ToList();

                WriteObject(psAfdEndpoints);
            }
        }
Exemplo n.º 9
0
        private void FieldsParameterSetCmdlet()
        {
            if (AfdUtilities.IsValuePresent(this.OriginGroupName))
            {
                // all fields are present (mandatory + optional)

                PSAfdOriginGroup psAfdOriginGroup = this.CdnManagementClient.AFDOriginGroups.Get(this.ResourceGroupName, this.ProfileName, this.OriginGroupName).ToPSAfdOriginGroup();

                WriteObject(psAfdOriginGroup);
            }
            else
            {
                // only the mandatory fields are present

                List <PSAfdOriginGroup> pSAfdOriginGroups = this.CdnManagementClient.AFDOriginGroups.ListByProfile(this.ResourceGroupName, this.ProfileName)
                                                            .Select(afdOriginGroup => afdOriginGroup.ToPSAfdOriginGroup())
                                                            .ToList();

                WriteObject(pSAfdOriginGroups);
            }
        }
Exemplo n.º 10
0
        private void DeleteAfdProfile()
        {
            try
            {
                PSAfdProfile profile = this.CdnManagementClient.Profiles.Get(this.ResourceGroupName, this.ProfileName).ToPSAfdProfile();

                if (!AfdUtilities.IsAfdProfile(profile))
                {
                    throw new PSArgumentException($"You are attempting to delete a {profile.Sku} profile. Please use Remove-AzCdnProfile instead.");
                }

                this.CdnManagementClient.Profiles.Delete(this.ResourceGroupName, this.ProfileName);
            }
            catch (Microsoft.Azure.Management.Cdn.Models.AfdErrorResponseException errorResponseException)
            {
                throw new PSArgumentException(errorResponseException.Response.Content);
            }

            if (this.PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
        private HealthProbeParameters CreateHealthProbeSettingsByFields(PSAfdOriginGroup currentPsAfdOriginGroup, bool isProbePath, bool isProbeRequestType, bool isProbeProtocol, bool isProbeIntervalInSeconds)
        {
            if (!isProbePath && !isProbeRequestType && !isProbeProtocol && !isProbeIntervalInSeconds)
            {
                return(null);
            }

            HealthProbeParameters healthProbeSettings = new HealthProbeParameters
            {
                ProbeIntervalInSeconds = currentPsAfdOriginGroup.ProbeIntervalInSeconds,
                ProbePath        = currentPsAfdOriginGroup.ProbePath,
                ProbeProtocol    = AfdUtilities.CreateProbeProtocol(currentPsAfdOriginGroup.ProbeProtocol),
                ProbeRequestType = AfdUtilities.CreateProbeRequestType(currentPsAfdOriginGroup.ProbeRequestType)
            };

            if (isProbePath)
            {
                healthProbeSettings.ProbePath = this.ProbePath;
            }

            if (isProbeRequestType)
            {
                healthProbeSettings.ProbeRequestType = AfdUtilities.CreateProbeRequestType(this.ProbeRequestType);
            }

            if (isProbeProtocol)
            {
                healthProbeSettings.ProbeProtocol = AfdUtilities.CreateProbeProtocol(this.ProbeProtocol);
            }

            if (isProbeIntervalInSeconds)
            {
                healthProbeSettings.ProbeIntervalInSeconds = this.ProbeIntervalInSeconds;
            }

            return(healthProbeSettings);
        }
        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 RouteUpdateParameters CreateAfdRouteUpdateByFields(PSAfdRoute currentPsAfdRoute)
        {
            bool isCustomDomainId             = this.MyInvocation.BoundParameters.ContainsKey("CustomDomainId");
            bool isSupportedProtocols         = this.MyInvocation.BoundParameters.ContainsKey("SupportedProtocol");
            bool isHttpsRedirect              = this.MyInvocation.BoundParameters.ContainsKey("HttpsRedirect");
            bool isOriginGroupId              = this.MyInvocation.BoundParameters.ContainsKey("OriginGroupId");
            bool isOriginPath                 = this.MyInvocation.BoundParameters.ContainsKey("OriginPath");
            bool isForwardingProtocol         = this.MyInvocation.BoundParameters.ContainsKey("ForwardingProtocol");
            bool isQueryStringCachingBehavior = this.MyInvocation.BoundParameters.ContainsKey("QueryStringCachingBehavior");
            bool isRuleSetIds                 = this.MyInvocation.BoundParameters.ContainsKey("RuleSetId");

            RouteUpdateParameters afdRouteUpdateParameters = new RouteUpdateParameters
            {
                CustomDomains              = currentPsAfdRoute.CustomDomainIds,
                SupportedProtocols         = currentPsAfdRoute.SupportedProtocols,
                HttpsRedirect              = currentPsAfdRoute.HttpsRedirect,
                OriginGroup                = new ResourceReference(currentPsAfdRoute.OriginGroupId),
                OriginPath                 = currentPsAfdRoute.OriginPath,
                ForwardingProtocol         = currentPsAfdRoute.ForwardingProtocol,
                RuleSets                   = currentPsAfdRoute.RuleSetIds,
                QueryStringCachingBehavior = AfdUtilities.CreateQueryStringCachingBehavior(currentPsAfdRoute.QueryStringCachingBehavior)
            };

            if (isCustomDomainId)
            {
                foreach (string customDomainId in this.CustomDomainId)
                {
                    afdRouteUpdateParameters.CustomDomains.Add(new ResourceReference(customDomainId));
                }
            }

            if (isSupportedProtocols)
            {
                afdRouteUpdateParameters.SupportedProtocols = this.SupportedProtocol;
            }

            if (isHttpsRedirect)
            {
                afdRouteUpdateParameters.HttpsRedirect = AfdUtilities.CreateHttpsRedirect(this.HttpsRedirect);
            }

            if (isOriginGroupId)
            {
                afdRouteUpdateParameters.OriginGroup = new ResourceReference(this.OriginGroupId);
            }

            if (isOriginPath)
            {
                afdRouteUpdateParameters.OriginPath = this.OriginPath;
            }

            if (isForwardingProtocol)
            {
                afdRouteUpdateParameters.ForwardingProtocol = AfdUtilities.CreateForwardingProtocol(this.ForwardingProtocol);
            }

            if (isQueryStringCachingBehavior)
            {
                afdRouteUpdateParameters.QueryStringCachingBehavior = AfdUtilities.CreateQueryStringCachingBehavior(this.QueryStringCachingBehavior);
            }

            if (isRuleSetIds)
            {
                foreach (string ruleSetId in this.RuleSetId)
                {
                    afdRouteUpdateParameters.RuleSets.Add(new ResourceReference(ruleSetId));
                }
            }

            return(afdRouteUpdateParameters);
        }