-
-
Save pfsscott/2499a1d69c8acb364d49ef52971990e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webJobsAppService = new WebApp(...yadda yadda yadda...); | |
// Midnight Client Local | |
var someTrigger = CreateRecurringTriggeredWebJobWorkflow( | |
webJobName: "SomeJobName", | |
resourceGroup: resourceGroup, | |
appService: webJobsAppService, | |
state: AzureNative.Logic.WorkflowState.Disabled, | |
interval: 1, | |
frequency: "Hour", | |
startTime: DateTime.Parse("2019-10-01T00:00:00"), | |
timeZoneId: someTimeZoneId); | |
private AzureNative.Logic.Workflow CreateRecurringTriggeredWebJobWorkflow( | |
string webJobName, | |
AzureNative.Logic.WorkflowState state, | |
ResourceGroup resourceGroup, | |
WebApp appService, | |
string frequency, | |
int interval, | |
DateTimeOffset startTime, | |
TimeZoneId timeZoneId | |
) | |
{ | |
return new AzureNative.Logic.Workflow($"workflow-{webJobName}", new AzureNative.Logic.WorkflowArgs | |
{ | |
ResourceGroupName = resourceGroup.Name, | |
Location = resourceGroup.Location, | |
WorkflowName = $"Trigger-{webJobName}", | |
State = state, | |
Definition = Output.Tuple(appService.Name, resourceGroup.Name).Apply<object>(async data => | |
{ | |
var webJobsAppServiceName = data.Item1; | |
var resourceGroupName = data.Item2; | |
var (username, password) = await GetPublishProfileUserPass(resourceGroupName, webJobsAppServiceName); | |
# ... use the username and password here... | |
return new JsonDocument(); | |
}) | |
}); | |
} | |
private async Task<(string Username, string Password)> GetPublishProfileUserPass(string resourceGroupName, string appServiceName) | |
{ | |
var config = await GetClientConfig.InvokeAsync(); | |
var token = await GetClientToken.InvokeAsync(); | |
var httpClient = new HttpClient(); | |
var url = $"https://management.azure.com/subscriptions/{config.SubscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{appServiceName}/publishxml?api-version=2021-02-01"; | |
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Token); | |
var emptyContent = new StringContent(string.Empty); | |
emptyContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded"); | |
var response = await httpClient.PostAsync(url, emptyContent); | |
if (!response.IsSuccessStatusCode) | |
{ | |
throw new Exception($"Request failed with {response.StatusCode}"); | |
} | |
var xmlResponseBody = await response.Content.ReadAsStringAsync(); | |
var xmlElement = XElement.Parse(xmlResponseBody); | |
return xmlElement.Descendants().Select(publishProfileElement => (publishProfileElement.Attribute("userName").Value, publishProfileElement.Attribute("userPWD").Value)).FirstOrDefault(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This fails during
pulumi up
whenCreateRecurringTriggeredWebJobWorkflow
is called.GetPublishProfileUserPass
is called, but fails because the appService doesn't exist yet, causing the Azure API call in GetPublishProfileUserPass to fail.