This repository has been archived by the owner on Nov 26, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from goncalo-oliveira/develop
added support for controller functions.
- Loading branch information
Showing
18 changed files
with
224 additions
and
87 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Hosting; | ||
using Newtonsoft.Json.Converters; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace OpenFaaS.Api | ||
{ | ||
public class Startup : IPluginStartup | ||
{ | ||
public Startup( IConfiguration configuration ) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
public void ConfigureServices( IServiceCollection services ) | ||
{ | ||
var mvcBuilder = services.AddControllers( options => | ||
{ | ||
} ); | ||
|
||
mvcBuilder.AddNewtonsoftJson( options => | ||
{ | ||
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); | ||
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; | ||
options.SerializerSettings.Converters.Add( new StringEnumConverter( new CamelCaseNamingStrategy(), false ) ); | ||
}); | ||
// Replaced with Newtonsoft because Microsoft's serializer doesn't do polymorphic serialization | ||
|
||
mvcBuilder.AddPluginControllers(); | ||
} | ||
|
||
public void Configure( IApplicationBuilder app, IWebHostEnvironment env ) | ||
{ | ||
if ( env.IsDevelopment() ) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseRouting(); | ||
|
||
if ( !Configuration.GetValue<bool>( "Args:SkipAuth" ) ) | ||
{ | ||
app.UseAuthentication(); | ||
app.UseAuthorization(); | ||
} | ||
|
||
// allow api implementation to customize the pipeline | ||
app.ConfigurePlugin( env ); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllers(); | ||
}); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
3 changes: 2 additions & 1 deletion
3
src/HttpMethodAttributeExtensions.cs → ...unctions/HttpMethodAttributeExtensions.cs
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
2 changes: 1 addition & 1 deletion
2
src/HttpRequestHandlerOptions.cs → src/Functions/HttpRequestHandlerOptions.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using System; | ||
|
||
namespace OpenFaaS | ||
namespace OpenFaaS.Functions | ||
{ | ||
internal class HttpRequestHandlerOptions | ||
{ | ||
|
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
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
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
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
2 changes: 1 addition & 1 deletion
2
src/Middleware/Routing/IRouteMatcher.cs → ...tions/Middleware/Routing/IRouteMatcher.cs
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace OpenFaaS.Functions | ||
{ | ||
public class Startup : IPluginStartup | ||
{ | ||
public Startup( IConfiguration configuration ) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices( IServiceCollection services ) | ||
{ | ||
services.AddMvc() | ||
.AddNewtonsoftJson( options => | ||
{ | ||
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); | ||
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; | ||
} ); | ||
// Replaced with Newtonsoft because Microsoft's serializer doesn't do polymorphic serialization | ||
|
||
services.AddSingleton<ISystemClock, SystemClock>(); | ||
|
||
// add root request handler to the container | ||
services.AddSingleton<Middleware.IRouteMatcher, Middleware.RouteMatcher>(); | ||
services.TryAddScoped<Middleware.HttpAuthenticationHandler>(); | ||
services.Configure<HttpRequestHandlerOptions>( options => | ||
{ | ||
options.SkipAuth = Configuration.GetValue<bool>( "Args:SkipAuth" ); | ||
if ( options.SkipAuth ) | ||
{ | ||
Console.WriteLine( "Skipping authentication and authorization" ); | ||
} | ||
} ); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure( IApplicationBuilder app, IWebHostEnvironment env ) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
|
||
Console.WriteLine(); | ||
Console.WriteLine( "Running..." ); | ||
|
||
app.UseMiddleware<Middleware.RoutingMiddleware>() | ||
.UseMiddleware<Middleware.AuthenticationMiddleware>() | ||
.UseMiddleware<Middleware.AuthorizationMiddleware>() | ||
.UseMiddleware<Middleware.FunctionMiddleware>(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace OpenFaaS | ||
{ | ||
public interface IPluginStartup | ||
{ | ||
void ConfigureServices( IServiceCollection services ); | ||
void Configure( IApplicationBuilder app, IWebHostEnvironment env ); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Reflection; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace OpenFaaS | ||
{ | ||
internal static class PluginServiceExtensions | ||
{ | ||
private static readonly string typeName = "OpenFaaS.Startup"; | ||
|
||
private static object startup; | ||
|
||
public static void AddPluginControllers( this IMvcBuilder builder ) | ||
{ | ||
builder.AddApplicationPart( AssemblyResolver.Default.Assembly ); | ||
} | ||
|
||
public static IServiceCollection ConfigurePluginServices( this IServiceCollection services, IConfiguration configuration ) | ||
{ | ||
startup = AssemblyResolver.Default.Assembly.CreateInstance( typeName, false, BindingFlags.CreateInstance, null, new object[] | ||
{ | ||
configuration | ||
}, null, null ); | ||
|
||
startup.GetType().InvokeMember( "ConfigureServices", BindingFlags.InvokeMethod, null, startup, new object[] | ||
{ | ||
services | ||
} ); | ||
|
||
return ( services ); | ||
} | ||
|
||
public static IApplicationBuilder ConfigurePlugin( this IApplicationBuilder app, IWebHostEnvironment env ) | ||
{ | ||
var type = startup.GetType(); | ||
|
||
var configureMethod = type.GetMethod( "Configure", BindingFlags.Public | BindingFlags.Instance, null, new Type[] | ||
{ | ||
typeof( IApplicationBuilder ), typeof( bool ) | ||
}, null ); | ||
|
||
// the Configure( IApplicationBuilder, bool ) method is optional | ||
|
||
configureMethod?.Invoke( startup, new object[] | ||
{ | ||
app, env.IsDevelopment() | ||
} ); | ||
|
||
return ( app ); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.