Exemple #1
0
        public void FindAService()
        {
            var identity = new CloudIdentity {
                Username = "******", APIKey = "{api-key}"
            };
            IIdentityProvider identityProvider = new CloudIdentityProvider(identity);
            var service = new ContentDeliveryNetworkService(identityProvider, "DFW");

            IPage <Service> currentPage = service.ListServices();

            Service myService;

            do
            {
                myService = currentPage.FirstOrDefault(x => x.Name == "MyService");
                if (myService != null)
                {
                    break;
                }

                currentPage = currentPage.GetNextPage();
            } while (currentPage.Any());

            if (myService == null)
            {
                Console.Error.WriteLine("Could not find MyService!");
                return;
            }

            Console.WriteLine("MyService: {0}", myService.Status);
        }
        public ContentDeliveryNetworkServiceTests(ITestOutputHelper testLog)
        {
            OpenStackNet.Tracing.Http.Listeners.Add(new XunitTraceListener(testLog));

            var authenticationProvider = TestIdentityProvider.GetIdentityProvider();

            _cdnService = new ContentDeliveryNetworkService(authenticationProvider, "DFW");
        }
        public async void When401AuthenticationFailsMultipleTimes_ThrowException()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith((int)HttpStatusCode.Unauthorized, "Your token has expired");
                httpTest.RespondWith((int)HttpStatusCode.Unauthorized, "Your token has expired");

                var service = new ContentDeliveryNetworkService(Stubs.AuthenticationProvider, "DFW");
                await Assert.ThrowsAsync <FlurlHttpException>(() => service.GetFlavorAsync("flavor-id"));
            }
        }
        public async void When401UnauthorizedIsReturned_RetryRequest()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith((int)HttpStatusCode.Unauthorized, "Your token has expired");
                httpTest.RespondWithJson(new Flavor());

                var service = new ContentDeliveryNetworkService(Stubs.AuthenticationProvider, "DFW");
                var flavor  = await service.GetFlavorAsync("flavor-id");

                Assert.NotNull(flavor);
            }
        }
Exemple #5
0
        public async static void ExampleDoc()
        {
            // Authenticate
            var identity = new CloudIdentity
            {
                APIKey   = "{apikey}",
                Username = "******"
            };
            var authProvider = new CloudIdentityProvider(identity);
            var cdnService   = new ContentDeliveryNetworkService(authProvider, "{region}");

            // List Flavors
            IEnumerable <Flavor> flavors = await cdnService.ListFlavorsAsync();

            // Get Flavor
            Flavor flavor = await cdnService.GetFlavorAsync("{flavorId}");

            // Create Service
            ServiceDefinition serviceDefinition = new ServiceDefinition("example_site", "{flavorId}",
                                                                        domains: new[] { new ServiceDomain("www.example.com") },
                                                                        origins: new[] { new ServiceOrigin("example.com") });
            string serviceId = await cdnService.CreateServiceAsync(serviceDefinition);

            await cdnService.WaitForServiceDeployedAsync(serviceId);

            // List Services
            IPage <Service> services = await cdnService.ListServicesAsync();

            // Get Service
            Service service = await cdnService.GetServiceAsync("{serviceId}");

            // Purge All Service Assets
            await cdnService.PurgeCachedAssetsAsync("{serviceId}");

            // Purge a Specific Service Asset
            await cdnService.PurgeCachedAssetAsync("{serviceId}", "{relativeUrlOfAsset}");

            // Update Service
            var patch = new JsonPatchDocument <ServiceDefinition>();

            patch.Replace(svc => svc.Name, "newServiceName");
            await cdnService.UpdateServiceAsync("{serviceId}", patch);

            await cdnService.WaitForServiceDeployedAsync("{serviceId}");

            // Delete Service
            await cdnService.DeleteServiceAsync("{serviceId}");

            await cdnService.WaitForServiceDeletedAsync("{serviceId}");
        }
Exemple #6
0
        static void Main(string[] args)
        {
            var identity = new CloudIdentity
            {
                Username = Environment.GetEnvironmentVariable("OPENSTACKNET_USER"),
                APIKey   = Environment.GetEnvironmentVariable("OPENSTACKNET_APIKEY")
            };

            var authProvider = new CloudIdentityProvider(identity);


            Console.WriteLine("--- Servers ---");
            var serversProvider = new CloudServersProvider(identity);
            var servers         = serversProvider.ListServers();

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Id\t\t\t\t\tName");
            Console.ResetColor();
            Console.WriteLine();
            foreach (var server in servers)
            {
                Console.WriteLine("{0}\t{1}", server.Id, server.Name);
            }
            Console.WriteLine();

            Console.WriteLine("--- CDN Services ---");
            var cdnService = new ContentDeliveryNetworkService(authProvider, "DFW");
            var cdns       = cdnService.ListServices();

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Id\t\t\t\t\tName");
            Console.ResetColor();
            Console.WriteLine();
            foreach (var cdn in cdns)
            {
                Console.WriteLine("{0}\t{1}", cdn.Id, cdn.Name);
            }
            Console.WriteLine();

            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }
Exemple #7
0
        public async Task Run(string username, string apiKey)
        {
            // Authenticate
            var identity = new CloudIdentity
            {
                APIKey   = apiKey,
                Username = username
            };
            var authProvider = new CloudIdentityProvider(identity);
            var cdnService   = new ContentDeliveryNetworkService(authProvider, "DFW");

            // List Flavors
            Console.WriteLine();
            Console.WriteLine("List Flavors...");
            IEnumerable <Flavor> flavors = await cdnService.ListFlavorsAsync();

            foreach (Flavor f in flavors)
            {
                Console.WriteLine("{0}\t{1}", f.Id, f.Providers.First().Name);
            }

            // Get Flavor
            Console.WriteLine();
            Console.WriteLine("Get Flavor...");
            Flavor flavor = await cdnService.GetFlavorAsync(flavors.First().Id);

            Console.WriteLine("{0}\t{1}", flavor.Id, flavor.Providers.First().Name);

            // Create Service
            Console.WriteLine();
            Console.WriteLine("Create Service...");
            ServiceDefinition serviceDefinition = new ServiceDefinition("example_site", flavor.Id,
                                                                        domains: new[] { new ServiceDomain("www.example.com") },
                                                                        origins: new[] { new ServiceOrigin("example.com") });
            string serviceId = await cdnService.CreateServiceAsync(serviceDefinition);

            await cdnService.WaitForServiceDeployedAsync(serviceId);

            Console.WriteLine("Service Created: {0}", serviceId);

            // List Services
            Console.WriteLine();
            Console.WriteLine("List Services..");
            IPage <Service> services = await cdnService.ListServicesAsync();

            foreach (Service s in services)
            {
                Console.WriteLine("{0}\t{1}", s.Id, s.Name);
            }

            // Get Service
            Console.WriteLine();
            Console.WriteLine("Get Service");
            Service service = await cdnService.GetServiceAsync(serviceId);

            Console.WriteLine("{0}\t{1}", service.Id, service.Name);

            // Purge All Service Assets
            Console.WriteLine();
            Console.WriteLine("Purge All Service Assets...");
            await cdnService.PurgeCachedAssetsAsync(serviceId);

            // Purge a Specific Service Asset
            Console.WriteLine();
            Console.WriteLine("Purge a Specific Service Asset...");
            await cdnService.PurgeCachedAssetAsync(serviceId, "index.html");

            // Update Service
            Console.WriteLine();
            Console.WriteLine("Update Service...");
            var patch = new JsonPatchDocument <ServiceDefinition>();

            patch.Replace(svc => svc.Name, "newServiceName");
            await cdnService.UpdateServiceAsync(serviceId, patch);

            await cdnService.WaitForServiceDeployedAsync(serviceId);

            // Delete Service
            Console.WriteLine();
            Console.WriteLine("Delete Service...");
            await cdnService.DeleteServiceAsync(serviceId);

            await cdnService.WaitForServiceDeletedAsync(serviceId);
        }