public async Task Delete( string name) { FunctionAppOs os = GetOsFromResourceLabel(name); string resourceGroup = GetResourceGroupName(os); Uri uri = new Uri($"{ManagementURL}/subscriptions/{SubscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{name}?api-version=2018-11-01"); var response = await ArmClient.HttpInvoke("DELETE", uri, AccessToken); if (response.IsSuccessStatusCode) { RemoveFromResources(name, os); } else { string statusCode = response.StatusCode.ToString(); string message = await response.Content.ReadAsStringAsync(); throw new Exception($"Failed to remove function app {name}: ({statusCode}) {message}"); } }
internal static async Task <string> GetResourceIDFromArg(IEnumerable <string> subIds, string query, string accessToken, string managementURL) { var url = new Uri($"{managementURL}/{ArmUriTemplates.ArgUri}?api-version={ArmUriTemplates.ArgApiVersion}"); var bodyObject = new { subscriptions = subIds, query }; var response = await ArmClient.HttpInvoke(HttpMethod.Post, url, accessToken, objectPayload : bodyObject); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); var argResponse = JsonConvert.DeserializeObject <ArgResponse>(result); // we need the first item of the first row return(argResponse.Data?.Rows?.FirstOrDefault()?.FirstOrDefault() ?? throw new CliException("Error finding the Azure Resource information.")); }
public static async Task <HttpResult <Dictionary <string, string>, string> > UpdateFunctionAppAppSettings(Site site, string accessToken, string managementURL) { var url = new Uri($"{managementURL}{site.SiteId}/config/AppSettings?api-version={ArmUriTemplates.WebsitesApiVersion}"); var response = await ArmClient.HttpInvoke(HttpMethod.Put, url, accessToken, new { properties = site.AzureAppSettings }); if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsAsync <ArmWrapper <Dictionary <string, string> > >(); return(new HttpResult <Dictionary <string, string>, string>(result.properties)); } else { var result = await response.Content.ReadAsStringAsync(); var parsedResult = JsonConvert.DeserializeObject <JObject>(result); var errorMessage = parsedResult["Message"].ToString(); return(string.IsNullOrEmpty(errorMessage) ? new HttpResult <Dictionary <string, string>, string>(null, result) : new HttpResult <Dictionary <string, string>, string>(null, errorMessage)); } }
public async Task <ListKeysResponse> ListKeys( string name) { FunctionAppOs os = GetOsFromResourceLabel(name); string resourceGroup = GetResourceGroupName(os); Uri uri = new Uri($"{ManagementURL}subscriptions/{SubscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Storage/storageAccounts/{name}/listkeys?api-version=2019-06-01"); var response = await ArmClient.HttpInvoke("POST", uri, AccessToken); if (response.IsSuccessStatusCode) { string json = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <ListKeysResponse>(json)); } else { string statusCode = response.StatusCode.ToString(); string message = await response.Content.ReadAsStringAsync(); throw new Exception($"Failed to list keys for storage account {name}: ({statusCode}) {message}"); } }
public static async Task <HttpResult <string, string> > UpdateWebSettings(Site site, Dictionary <string, string> webSettings, string accessToken, string managementURL) { var url = new Uri($"{managementURL}{site.SiteId}/config/web?api-version={ArmUriTemplates.WebsitesApiVersion}"); var response = await ArmClient.HttpInvoke(HttpMethod.Put, url, accessToken, new { properties = webSettings }); if (response.IsSuccessStatusCode) { // Simply reading it as a string because we do not care about the result content particularly var result = await response.Content.ReadAsStringAsync(); return(new HttpResult <string, string>(result)); } else { var result = await response.Content.ReadAsStringAsync(); var parsedResult = JsonConvert.DeserializeObject <JObject>(result); var errorMessage = parsedResult["Message"].ToString(); return(string.IsNullOrEmpty(errorMessage) ? new HttpResult <string, string>(null, result) : new HttpResult <string, string>(null, errorMessage)); } }
private static async Task ArmHttpAsync(HttpMethod method, Uri uri, string accessToken, object payload = null) { var response = await ArmClient.HttpInvoke(method, uri, accessToken, payload, retryCount : 3); response.EnsureSuccessStatusCode(); }
public static Task <HttpResponseMessage> SyncTriggers(Site functionApp, string accessToken, string managementURL) { var url = new Uri($"{managementURL}{functionApp.SiteId}/host/default/sync?api-version={ArmUriTemplates.WebsitesApiVersion}"); return(ArmClient.HttpInvoke(HttpMethod.Post, url, accessToken)); }
public static Task <HttpResponseMessage> SyncTriggers(Site functionApp, string accessToken) { var url = new Uri($"{ArmUriTemplates.ArmUrl}{functionApp.SiteId}/hostruntime/admin/host/synctriggers?api-version={ArmUriTemplates.WebsitesApiVersion}"); return(ArmClient.HttpInvoke(HttpMethod.Post, url, accessToken)); }