Example #1
0
        public override void ExecuteCmdlet()
        {
            var result = CdnManagementClient.ValidateProbe(ProbeUrl);

            WriteVerbose(Resources.Success);
            WriteObject(result.ToPsValideProbeOutput());
        }
        public override void ExecuteCmdlet()
        {
            var result = CdnManagementClient.CheckNameAvailability(EndpointName);

            WriteVerbose(Resources.Success);
            WriteObject(result.ToPsCheckNameAvailabilityOutput());
        }
        static void Main(string[] args)
        {
            //Get a token
            AuthenticationResult authResult = GetAccessToken();

            // Create CDN client
            CdnManagementClient cdn = new CdnManagementClient(new TokenCredentials(authResult.AccessToken))
            {
                SubscriptionId = subscriptionId
            };

            ListProfilesAndEndpoints(cdn);

            // Create CDN Profile
            CreateCdnProfile(cdn);

            // Create CDN Endpoint
            CreateCdnEndpoint(cdn);

            Console.WriteLine();

            // Purge CDN Endpoint
            PromptPurgeCdnEndpoint(cdn);

            // Delete CDN Endpoint
            PromptDeleteCdnEndpoint(cdn);

            // Delete CDN Profile
            PromptDeleteCdnProfile(cdn);

            Console.WriteLine("Press Enter to end program.");
            Console.ReadLine();
        }
        /// <summary>
        /// Lists all of the CDN profiles and endpoints for a given resource group.
        /// </summary>
        /// <param name="cdn">Authenticated CdnManagementClient</param>
        private static void ListProfilesAndEndpoints(CdnManagementClient cdn)
        {
            // List all the CDN profiles in this resource group
            var profileList = cdn.Profiles.ListByResourceGroup(resourceGroupName);

            foreach (Profile p in profileList)
            {
                Console.WriteLine("CDN profile {0}", p.Name);
                if (p.Name.Equals(profileName, StringComparison.OrdinalIgnoreCase))
                {
                    // Hey, that's the name of the CDN profile we want to create!
                    profileAlreadyExists = true;
                }

                //List all the CDN endpoints on this CDN profile
                Console.WriteLine("Endpoints:");
                var endpointList = cdn.Endpoints.ListByProfile(p.Name, resourceGroupName);
                foreach (Endpoint e in endpointList)
                {
                    Console.WriteLine("-{0} ({1})", e.Name, e.HostName);
                    if (e.Name.Equals(endpointName, StringComparison.OrdinalIgnoreCase))
                    {
                        // The unique endpoint name already exists.
                        endpointAlreadyExists = true;
                    }
                }
                Console.WriteLine();
            }
        }
Example #5
0
        public override void ExecuteCmdlet()
        {
            var resourceUsages = CdnManagementClient.CheckResourceUsage().Select(r => r.ToPsResourceUsage());

            WriteVerbose(Resources.Success);
            WriteObject(resourceUsages);
        }
Example #6
0
        protected void SetupManagementClients(MockContext context)
        {
            ResourceManagementClient = GetResourceManagementClient(context);
            CdnManagementClient      = GetCdnManagementClient(context);

            _helper.SetupManagementClients(
                ResourceManagementClient,
                CdnManagementClient);
        }
 /// <summary>
 /// Prompts the user to delete the CDN endpoint, then carries it out.
 /// </summary>
 /// <param name="cdn">An authenticated CdnManagementClient</param>
 private static void PromptDeleteCdnEndpoint(CdnManagementClient cdn)
 {
     if (PromptUser(String.Format("Delete CDN endpoint {0} on profile {1}?", endpointName, profileName)))
     {
         Console.WriteLine("Deleting endpoint. Please wait...");
         cdn.Endpoints.DeleteIfExists(endpointName, profileName, resourceGroupName);
         Console.WriteLine("Done.");
         Console.WriteLine();
     }
 }
 /// <summary>
 /// Prompts the user to delete the CDN profile, then carries it out.
 /// </summary>
 /// <param name="cdn">An authenticated CdnManagementClient</param>
 private static void PromptDeleteCdnProfile(CdnManagementClient cdn)
 {
     if (PromptUser(String.Format("Delete CDN profile {0}?", profileName)))
     {
         Console.WriteLine("Deleting profile. Please wait...");
         cdn.Profiles.DeleteIfExists(profileName, resourceGroupName);
         Console.WriteLine("Done.");
         Console.WriteLine();
     }
 }
Example #9
0
        public CdnHelper(string subscriptionId)
        {
            var azureServiceTokenProvider = new AzureServiceTokenProvider();
            var token = azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com/").GetAwaiter().GetResult();

            cdnManagementClient = new CdnManagementClient(new TokenCredentials(token))
            {
                SubscriptionId = subscriptionId
            };
            this.subscriptionId = subscriptionId;
        }
 /// <summary>
 /// Purges the CDN endpoint.
 /// </summary>
 /// <param name="cdn">An authenticated CdnManagementClient</param>
 private static void PromptPurgeCdnEndpoint(CdnManagementClient cdn)
 {
     if (PromptUser(String.Format("Purge CDN endpoint {0}?", endpointName)))
     {
         Console.WriteLine("Purging endpoint. Please wait...");
         cdn.Endpoints.PurgeContent(endpointName, profileName, resourceGroupName, new List <string>()
         {
             "/*"
         });
         Console.WriteLine("Done.");
         Console.WriteLine();
     }
 }
Example #11
0
        public static CdnManagementClient GetCdnManagementClient(MockContext context, RecordedDelegatingHandler handler)
        {
            CdnManagementClient cdnClient;

            if (IsTestTenant)
            {
                cdnClient = new CdnManagementClient(new TokenCredentials("xyz"), GetHandler());
                cdnClient.SubscriptionId = testSubscription;
                cdnClient.BaseUri        = testUri;
            }
            else
            {
                handler.IsPassThrough = true;
                cdnClient             = context.GetServiceClient <CdnManagementClient>(handlers: handler);
            }
            return(cdnClient);
        }
 /// <summary>
 /// Creates a CDN profile.
 /// </summary>
 /// <param name="cdn">An authenticated CdnManagementClient</param>
 private static void CreateCdnProfile(CdnManagementClient cdn)
 {
     if (profileAlreadyExists)
     {
         Console.WriteLine("Profile {0} already exists.", profileName);
     }
     else
     {
         Console.WriteLine("Creating profile {0}.", profileName);
         ProfileCreateParameters profileParms =
             new ProfileCreateParameters()
         {
             Location = resourceLocation, Sku = new Sku(SkuName.StandardVerizon)
         };
         cdn.Profiles.Create(profileName, profileParms, resourceGroupName);
     }
 }
        public AzureCdnManagementService(
            IConfiguration config
            )
        {
            CdnResourceGroupName = config.CdnResourceGroupName();
            CdnProfileName       = config.CdnProfileName();
            CdnEndpointName      = config.CdnEndpointName();
            AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
            var mslogin    = new MSILoginInformation(MSIResourceType.AppService);
            var credential = new AzureCredentials(mslogin, AzureEnvironment.AzureGlobalCloud);
            var client     = RestClient.Configure()
                             .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
                             .WithCredentials(credential)
                             .Build();

            CdnClient = new CdnManagementClient(client);
        }
Example #14
0
        public AzureCdnManagementService(
            IConfiguration config,
            ILogger <AzureCdnManagementService> logger
            )
        {
            Logger = logger;
            Logger.LogInformation($"{nameof(AzureCdnManagementService)} constructor");
            CdnResourceGroupName = config.CdnResourceGroupName();
            CdnProfileName       = config.CdnProfileName();
            CdnEndpointName      = config.CdnEndpointName();
            var mslogin    = new MSILoginInformation(MSIResourceType.AppService);
            var credential = new AzureCredentials(mslogin, AzureEnvironment.AzureGlobalCloud);
            var client     = RestClient.Configure()
                             .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
                             .WithCredentials(credential)
                             .Build();

            CdnClient = new CdnManagementClient(client);
        }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ObjectParameterSet)
            {
                ProfileName       = CdnProfile.Name;
                ResourceGroupName = CdnProfile.ResourceGroupName;
                Location          = CdnProfile.Location;
            }

            var checkExists = CdnManagementClient.CheckNameAvailability(EndpointName);

            if (!checkExists.NameAvailable.Value)
            {
                throw new PSArgumentException(string.Format(
                                                  Resources.Error_CreateExistingEndpoint,
                                                  EndpointName));
            }

            ConfirmAction(MyInvocation.InvocationName,
                          EndpointName,
                          () => NewEndpoint());
        }
 /// <summary>
 /// Creates the CDN endpoint.
 /// </summary>
 /// <param name="cdn">An authenticated CdnManagementClient</param>
 private static void CreateCdnEndpoint(CdnManagementClient cdn)
 {
     if (endpointAlreadyExists)
     {
         Console.WriteLine("Profile {0} already exists.", profileName);
     }
     else
     {
         Console.WriteLine("Creating endpoint {0} on profile {1}.", endpointName, profileName);
         EndpointCreateParameters endpointParms =
             new EndpointCreateParameters()
         {
             Origins = new List <DeepCreatedOrigin>()
             {
                 new DeepCreatedOrigin("Contoso", "www.contoso.com")
             },
             IsHttpAllowed  = true,
             IsHttpsAllowed = true,
             Location       = resourceLocation
         };
         cdn.Endpoints.Create(endpointName, endpointParms, profileName, resourceGroupName);
     }
 }
 public CdnRotationFunction(CertificateClientFactory certificateClientFactory, CdnManagementClient cdnManagementClient)
 {
     _certificateClientFactory = certificateClientFactory;
     _cdnManagementClient      = cdnManagementClient;
 }