Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
async Task<string> PasswordFor(string siteName){
var password = string.Empty;
Information($"Retrieving publishing profile for {siteName}...");
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://management.azure.com/");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
var content = new StringContent(
"{\"PublishingProfileFormat\":\"WebDeploy\"}",
Encoding.UTF8,
"application/json");
var response = await client.PostAsync(
$"subscriptions/{azureSubscriptionId}/resourceGroups/loanbrokerage-testing/providers/
Microsoft.Web/sites/{siteName}/publishxml?api-version=2016-03-01",
new StringContent(string.Empty));
if (response.IsSuccessStatusCode)
{
var xml = await response.Content.ReadAsStringAsync();
string pattern = @"userPWD=""(\w)+""";
RegexOptions options = RegexOptions.Multiline;
Match match = Regex.Match(xml, pattern, options);
password = match
.Value
.Replace("userPWD=\"", string.Empty)
.Replace("\"", string.Empty);
}
}
return password;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment