Skip to content

Commit

Permalink
Resolved issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesRandall committed Oct 4, 2018
1 parent 7edf63d commit 597c776
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>FunctionMonkey.Compiler</id>
<version>0.15.1-beta000</version>
<version>0.15.2-beta000</version>
<authors>James Randall</authors>
<description>Generates Azure Functions from command registrations</description>
<licenseUrl>https://raw.githubusercontent.com/JamesRandall/AzureFromTheTrenches.Commanding/master/LICENSE</licenseUrl>
Expand Down
33 changes: 17 additions & 16 deletions Source/FunctionMonkey.Compiler/Templates/http.csharp.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,23 @@ namespace {{Namespace}}
ILogger log,
ExecutionContext executionContext)
{
log.LogInformation("HTTP trigger function {{Name}} processed a request.");
log.LogInformation("HTTP trigger function {{Name}} processed a request.");

string requestUrl = GetRequestUrl(req);
var contextSetter = (FunctionMonkey.Abstractions.IContextSetter)
FunctionMonkey.Runtime.ServiceProvider.GetService(typeof(FunctionMonkey.Abstractions.IContextSetter));
contextSetter.SetExecutionContext(executionContext.FunctionDirectory,
executionContext.FunctionAppDirectory,
executionContext.FunctionName,
executionContext.InvocationId);
var headerDictionary = new Dictionary<string, IReadOnlyCollection<string>>();
foreach (var headerKeyValuesPair in req.Headers)
{
string[] values = headerKeyValuesPair.Value.ToArray();
headerDictionary.Add(headerKeyValuesPair.Key, values);
}
contextSetter.SetHttpContext(requestUrl, headerDictionary);

System.Security.Claims.ClaimsPrincipal principal = null;
// If we validate tokens then we need to read the header, validate it and retrieve a claims principal. Returning unauthorized if
// there are any issues
Expand All @@ -48,7 +64,6 @@ namespace {{Namespace}}
}
{{/if}}

string requestUrl = GetRequestUrl(req);
{{#if AuthorizesClaims}}
var claimsPrincipalAuthorization = ({{ClaimsPrincipalAuthorizationTypeName}})
FunctionMonkey.Runtime.ServiceProvider.GetService(typeof({{ClaimsPrincipalAuthorizationTypeName}}));
Expand Down Expand Up @@ -139,20 +154,6 @@ namespace {{Namespace}}
return CreateResponse(400, validationResult);
}
{{/if}}

var contextSetter = (FunctionMonkey.Abstractions.IContextSetter)
FunctionMonkey.Runtime.ServiceProvider.GetService(typeof(FunctionMonkey.Abstractions.IContextSetter));
contextSetter.SetExecutionContext(executionContext.FunctionDirectory,
executionContext.FunctionAppDirectory,
executionContext.FunctionName,
executionContext.InvocationId);
var headerDictionary = new Dictionary<string, IReadOnlyCollection<string>>();
foreach (var headerKeyValuesPair in req.Headers)
{
string[] values = headerKeyValuesPair.Value.ToArray();
headerDictionary.Add(headerKeyValuesPair.Key, values);
}
contextSetter.SetHttpContext(requestUrl, headerDictionary);

try
{
Expand Down

0 comments on commit 597c776

Please sign in to comment.