Esempio n. 1
0
        public static UpdateAppSettingsCommand CreateAppSettingsCommand(Webapp target, ServicePrincipal servicePrincipal, IDictionary <string, string> requestedSettings, bool includeDeletion)
        {
            var webapp           = new AzureWebapp(target, servicePrincipal);
            var settingsInTarget = webapp.GetAppSettings();
            var operations       = GetOperations(requestedSettings, settingsInTarget, includeDeletion);

            return(new UpdateAppSettingsCommand {
                Webapp = target, ServicePrincipal = servicePrincipal, Operations = operations
            });
        }
Esempio n. 2
0
        private Task UpdateAppSettingsAsync(Webapp webapp, Dictionary <string, string> settings)
        {
            var url = $"https://management.azure.com/{webapp.AppResourceId}/config/appsettings?api-version=2019-08-01";

            return(UpdateAsync(url, settings));
        }
Esempio n. 3
0
 public AzureWebapp(Webapp target, ServicePrincipal servicePrincipal)
 {
     _target           = target;
     _servicePrincipal = servicePrincipal;
 }
Esempio n. 4
0
        private Task <Dictionary <string, string> > ListAppSettingsAsync(Webapp webapp)
        {
            var url = $"https://management.azure.com/{webapp.AppResourceId}/config/appsettings/list?api-version=2019-08-01";

            return(ListAsync(url));
        }
Esempio n. 5
0
        static async Task RunAsync()
        {
            // Enable TLS 1.1 & TLS 1.2
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            using (var client = new HttpClient())
            {
                var form = new Dictionary <string, string>
                {
                    { "client_id", ConfigurationManager.AppSettings["client_id"] },
                    { "client_secret", ConfigurationManager.AppSettings["client_secret"] }
                };
                Console.WriteLine("...Testing POST api/oauth/token");
                var tokenRes = await client.PostAsync("https://dojo.zenedge.com/api/oauth/token", new FormUrlEncodedContent(form));

                if (!tokenRes.IsSuccessStatusCode)
                {
                    Console.WriteLine("There was an error generating an access token");
                    return;
                }

                var token = await tokenRes.Content.ReadAsAsync <Token>(new[] { new JsonMediaTypeFormatter() });

                Console.WriteLine("Got access token: {0}", token.AccessToken);

                var demoWebApp = new Webapp
                {
                    Domain        = "demowebapp.net",
                    OriginServers = new List <OriginServer>
                    {
                        new OriginServer
                        {
                            Ip     = "222.111.222.111",
                            Port   = 3456,
                            Weight = 1
                        }
                    }
                };

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
                Console.WriteLine("...Testing POST api/v2/webapps");
                var authRes = await client.PostAsJsonAsync("https://dojo.zenedge.com/api/v2/webapps", demoWebApp);

                if (!authRes.IsSuccessStatusCode)
                {
                    Console.WriteLine("There was an error creating a webapp, maybe it already exists");
                    return;
                }

                var webappRes = await authRes.Content.ReadAsAsync <WebappResponse>(new[] { new JsonMediaTypeFormatter() });

                Console.WriteLine("Created webapp with id: {0}", webappRes.Id);

                var demoPurge = new PurgeAll
                {
                    WebappDomain = "demowebapp.net"
                };

                Console.WriteLine("...Testing PUT api/v2/webapps/<webapp_id>/purge_all");
                authRes = await client.PutAsJsonAsync(string.Format("https://dojo.zenedge.com/api/v2/webapps/{0}/purge_all", webappRes.Id), demoPurge);

                if (!authRes.IsSuccessStatusCode)
                {
                    Console.WriteLine("There was an error purging the cash");
                    return;
                }

                var taskRes = await authRes.Content.ReadAsAsync <TaskResponse>(new[] { new JsonMediaTypeFormatter() });

                Console.WriteLine("Purge all webapp cache task id: {0}", taskRes.TaskId);

                Console.WriteLine("...Testing DELETE api/v2/webapps/<webapp_id>");
                authRes = await client.DeleteAsync(string.Format("https://dojo.zenedge.com/api/v2/webapps/{0}", webappRes.Id));

                if (!authRes.IsSuccessStatusCode)
                {
                    Console.WriteLine("There was an error deleting the webapp");
                    return;
                }

                taskRes = await authRes.Content.ReadAsAsync <TaskResponse>(new[] { new JsonMediaTypeFormatter() });

                Console.WriteLine("Deleting webapp task id: {0}", taskRes.TaskId);
            }
        }