Skip to content

Commit

Permalink
Plugins WiP #1
Browse files Browse the repository at this point in the history
  • Loading branch information
spetz committed Sep 11, 2019
1 parent d8ad20a commit 0bdf676
Show file tree
Hide file tree
Showing 87 changed files with 650 additions and 348 deletions.
62 changes: 47 additions & 15 deletions Ntrada.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{10BC7168-BE1
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ntrada", "src\Ntrada\Ntrada.csproj", "{BD735FBA-1D9C-45AD-8BDD-1E89B059E4CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ntrada.Handlers.RabbitMq", "src\Ntrada.Handlers.RabbitMq\Ntrada.Handlers.RabbitMq.csproj", "{EE7F8EBC-9603-4A30-898E-7C606BC534E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ntrada.Host", "src\Ntrada.Host\Ntrada.Host.csproj", "{0B949CC3-A1AF-4460-A942-D03ADA500BC0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{D1922E6F-C1D9-4C38-B667-36E417734DE8}"
Expand All @@ -21,6 +19,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{3672
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ntrada.Samples.Api", "samples\Ntrada.Samples.Api\Ntrada.Samples.Api.csproj", "{5195DD55-8257-4238-9B92-33E8574BBAA0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "extensions", "extensions", "{6E8C9C7B-7249-41CD-A466-C11A8644400B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ntrada.Extensions.Jwt", "extensions\Ntrada.Extensions.Jwt\Ntrada.Extensions.Jwt.csproj", "{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ntrada.Core", "src\Ntrada.Core\Ntrada.Core.csproj", "{78C6AEEB-522C-485B-843B-16ADB8A8157F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ntrada.Extensions.RabbitMq", "extensions\Ntrada.Extensions.RabbitMq\Ntrada.Extensions.RabbitMq.csproj", "{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -46,18 +52,6 @@ Global
{BD735FBA-1D9C-45AD-8BDD-1E89B059E4CC}.Release|x64.Build.0 = Release|Any CPU
{BD735FBA-1D9C-45AD-8BDD-1E89B059E4CC}.Release|x86.ActiveCfg = Release|Any CPU
{BD735FBA-1D9C-45AD-8BDD-1E89B059E4CC}.Release|x86.Build.0 = Release|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Debug|x64.ActiveCfg = Debug|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Debug|x64.Build.0 = Debug|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Debug|x86.ActiveCfg = Debug|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Debug|x86.Build.0 = Debug|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Release|Any CPU.Build.0 = Release|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Release|x64.ActiveCfg = Release|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Release|x64.Build.0 = Release|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Release|x86.ActiveCfg = Release|Any CPU
{EE7F8EBC-9603-4A30-898E-7C606BC534E7}.Release|x86.Build.0 = Release|Any CPU
{0B949CC3-A1AF-4460-A942-D03ADA500BC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B949CC3-A1AF-4460-A942-D03ADA500BC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B949CC3-A1AF-4460-A942-D03ADA500BC0}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -106,13 +100,51 @@ Global
{5195DD55-8257-4238-9B92-33E8574BBAA0}.Release|x64.Build.0 = Release|Any CPU
{5195DD55-8257-4238-9B92-33E8574BBAA0}.Release|x86.ActiveCfg = Release|Any CPU
{5195DD55-8257-4238-9B92-33E8574BBAA0}.Release|x86.Build.0 = Release|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Debug|x64.ActiveCfg = Debug|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Debug|x64.Build.0 = Debug|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Debug|x86.ActiveCfg = Debug|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Debug|x86.Build.0 = Debug|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Release|Any CPU.Build.0 = Release|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Release|x64.ActiveCfg = Release|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Release|x64.Build.0 = Release|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Release|x86.ActiveCfg = Release|Any CPU
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536}.Release|x86.Build.0 = Release|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Debug|x64.ActiveCfg = Debug|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Debug|x64.Build.0 = Debug|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Debug|x86.ActiveCfg = Debug|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Debug|x86.Build.0 = Debug|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Release|Any CPU.Build.0 = Release|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Release|x64.ActiveCfg = Release|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Release|x64.Build.0 = Release|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Release|x86.ActiveCfg = Release|Any CPU
{78C6AEEB-522C-485B-843B-16ADB8A8157F}.Release|x86.Build.0 = Release|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Debug|x64.ActiveCfg = Debug|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Debug|x64.Build.0 = Debug|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Debug|x86.ActiveCfg = Debug|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Debug|x86.Build.0 = Debug|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Release|Any CPU.Build.0 = Release|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Release|x64.ActiveCfg = Release|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Release|x64.Build.0 = Release|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Release|x86.ActiveCfg = Release|Any CPU
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BD735FBA-1D9C-45AD-8BDD-1E89B059E4CC} = {10BC7168-BE16-4A3C-A7CC-F122C83E08F5}
{EE7F8EBC-9603-4A30-898E-7C606BC534E7} = {10BC7168-BE16-4A3C-A7CC-F122C83E08F5}
{0B949CC3-A1AF-4460-A942-D03ADA500BC0} = {10BC7168-BE16-4A3C-A7CC-F122C83E08F5}
{8A8B41A2-9EAB-4E7C-9BDA-2DB93636CD2A} = {D1922E6F-C1D9-4C38-B667-36E417734DE8}
{254EE5DD-ACA8-4BE0-B8DD-5594C2C03D6C} = {D1922E6F-C1D9-4C38-B667-36E417734DE8}
{5195DD55-8257-4238-9B92-33E8574BBAA0} = {367233AC-1E0D-4FA2-8701-09702663DD54}
{B606AE04-E5B7-4912-AEB1-CCEDD3CBA536} = {6E8C9C7B-7249-41CD-A466-C11A8644400B}
{78C6AEEB-522C-485B-843B-16ADB8A8157F} = {10BC7168-BE16-4A3C-A7CC-F122C83E08F5}
{4C88EF7A-90AC-4E3E-A819-2CC4CCC17402} = {6E8C9C7B-7249-41CD-A466-C11A8644400B}
EndGlobalSection
EndGlobal
41 changes: 41 additions & 0 deletions extensions/Ntrada.Extensions.Jwt/JwtExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using Ntrada.Core;

namespace Ntrada.Extensions.Jwt
{
internal class JwtExtension : IExtension
{
public string Name => "jwt";
public string Description => "JSON Web Token authentication";

public void Add(IServiceCollection services, IOptionsProvider optionsProvider)
{
var options = optionsProvider.GetForExtension<JwtOptions>(Name);
services.AddAuthorization();
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(cfg =>
{
cfg.TokenValidationParameters = new TokenValidationParameters
{
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(options.Key)),
ValidIssuer = options.Issuer,
ValidIssuers = options.Issuers,
ValidAudience = options.Audience,
ValidAudiences = options.Audiences,
ValidateIssuer = options.ValidateIssuer,
ValidateAudience = options.ValidateAudience,
ValidateLifetime = options.ValidateLifetime
};
});
}

public void Use(IApplicationBuilder app, IOptionsProvider optionsProvider)
{
app.UseAuthentication();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System.Collections.Generic;
using System.Linq;
using Ntrada.Core;

namespace Ntrada.Configuration
namespace Ntrada.Extensions.Jwt
{
public class Jwt
internal class JwtOptions : IOptions
{
public string Key { get; set; }
public string Issuer { get; set; }
public bool ValidateIssuer { get; set; }
public IEnumerable<string> Issuers { get; set; } = Enumerable.Empty<string>();
public IEnumerable<string> Issuers { get; set; }
public string Audience { get; set; }
public IEnumerable<string> Audiences { get; set; } = Enumerable.Empty<string>();
public IEnumerable<string> Audiences { get; set; }
public bool ValidateAudience { get; set; }
public bool ValidateLifetime { get; set; }
}
Expand Down
15 changes: 15 additions & 0 deletions extensions/Ntrada.Extensions.Jwt/Ntrada.Extensions.Jwt.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Ntrada.Core\Ntrada.Core.csproj" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions extensions/Ntrada.Extensions.Jwt/jwt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
jwt:
key: eiquief5phee9pazo0Faegaez9gohThailiur5woy2befiech1oarai4aiLi6ahVecah3ie9Aiz6Peij
issuer: ntrada
issuers:
validate_issuer: true
audience:
audiences:
validate_audience: false
validate_lifetime: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Ntrada.Handlers.RabbitMq
using Ntrada.Core;

namespace Ntrada.Extensions.RabbitMq
{
public interface IContextBuilder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;

namespace Ntrada.Handlers.RabbitMq
namespace Ntrada.Extensions.RabbitMq
{
public interface IRabbitMqClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<VersionPrefix>1.2.0</VersionPrefix>
<Authors>Piotr Gankiewicz</Authors>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Title>Ntrada.Handlers.RabbitMq_</Title>
<PackageId>Ntrada.Handlers.RabbitMq_</PackageId>
<PackageTags>Ntrada.Handlers.RabbitMq_</PackageTags>
<Title>Ntrada.Extensions.RabbitMq_</Title>
<PackageId>Ntrada.Extensions.RabbitMq_</PackageId>
<PackageTags>Ntrada.Extensions.RabbitMq_</PackageTags>
<PackageProjectUrl>https://github.com/spetz/ntrada</PackageProjectUrl>
<PackageLicense>https://github.com/spetz/ntrada/blob/master/LICENSE</PackageLicense>
</PropertyGroup>
Expand All @@ -31,7 +31,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Ntrada\Ntrada.csproj" />
<ProjectReference Include="..\..\src\Ntrada.Core\Ntrada.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Ntrada.Handlers.RabbitMq
namespace Ntrada.Extensions.RabbitMq
{
internal sealed class NullContext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Ntrada.Handlers.RabbitMq
using Ntrada.Core;

namespace Ntrada.Extensions.RabbitMq
{
internal sealed class NullContextBuilder : IContextBuilder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using RawRabbit;
using RawRabbit.Enrichers.MessageContext;

namespace Ntrada.Handlers.RabbitMq
namespace Ntrada.Extensions.RabbitMq
{
public class RabbitMqClient : IRabbitMqClient
{
Expand Down
55 changes: 55 additions & 0 deletions extensions/Ntrada.Extensions.RabbitMq/RabbitMqExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Ntrada.Core;
using RawRabbit;
using RawRabbit.Configuration;
using RawRabbit.Enrichers.MessageContext;
using RawRabbit.Instantiation;

namespace Ntrada.Extensions.RabbitMq
{
public class RabbitMqExtension : IExtension
{
public string Name => "rabbitmq";
public string Description => "RabbitMQ message broker";
public void Add(IServiceCollection services, IOptionsProvider optionsProvider)
{
var options = optionsProvider.GetForExtension<RabbitMqOptions>(Name);
services.AddTransient<IRabbitMqClient, RabbitMqClient>();
services.AddTransient<RabbitMqHandler>();
// var hasContext = typeof(TContext) != typeof(NullContext);
var hasContext = false;
if (!hasContext)
{
services.AddSingleton<IContextBuilder, NullContextBuilder>();
}

services.AddSingleton(options);
var busClient = RawRabbitFactory.CreateInstanceFactory(new RawRabbitOptions
{
DependencyInjection = ioc =>
{
ioc.AddSingleton(options);
ioc.AddSingleton<RawRabbitConfiguration>(options);
},
Plugins = plugins =>
{
plugins
.UseAttributeRouting()
.UseRetryLater()
.UseContextForwarding();
// if (typeof(TContext) != typeof(NullContext))
// {
// plugins.UseMessageContext<TContext>();
// }
}
}).Create();
services.AddSingleton(busClient);
}

public void Use(IApplicationBuilder app, IOptionsProvider optionsProvider)
{
app.UseRequestHandler<RabbitMqHandler>(Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging;
using Route = Ntrada.Configuration.Route;
using Ntrada.Core;
using Route = Ntrada.Core.Configuration.Route;

namespace Ntrada.Handlers.RabbitMq
namespace Ntrada.Extensions.RabbitMq
{
public class RabbitMqHandler : IHandler
{
Expand Down
9 changes: 9 additions & 0 deletions extensions/Ntrada.Extensions.RabbitMq/RabbitMqOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Ntrada.Core;
using RawRabbit.Configuration;

namespace Ntrada.Extensions.RabbitMq
{
public class RabbitMqOptions : RawRabbitConfiguration, IOptions
{
}
}
22 changes: 22 additions & 0 deletions extensions/Ntrada.Extensions.RabbitMq/rabbitmq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
rabbitmq:
username: guest
password: guest
virtualHost: "/"
port: 5672
hostnames:
- localhost
requestTimeout: '00:00:10'
publishConfirmTimeout: '00:00:01'
recoveryInterval: '00:00:10'
persistentDeliveryMode: true
autoCloseConnection: true
automaticRecovery: true
topologyRecovery: true
exchange:
durable: true
autoDelete: false
type: Topic
queue:
autoDelete: false
durable: true
exclusive: false
12 changes: 5 additions & 7 deletions samples/Ntrada.Samples.Api/Ntrada.Samples.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<ProjectReference Include="..\..\src\Ntrada\Ntrada.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Ntrada\Ntrada.csproj" />
<None Update="ntrada.yml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Remove="ntrada.yml" />
<Content Include="ntrada.yml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="1.6.0" />
</ItemGroup>

</Project>
Loading

0 comments on commit 0bdf676

Please sign in to comment.