diff options
author | vnugent <public@vaughnnugent.com> | 2023-03-09 01:48:39 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-03-09 01:48:39 -0500 |
commit | 03f3226ea055dca3565bb859437624ef04a236fd (patch) | |
tree | c3aae503ae9b459a6fcaf9a18891d11ee8e1d1d8 /plugins/VNLib.Plugins.Essentials.Content.Routing/src | |
parent | 0e78874a09767aa53122a7242a8da7021020c1a2 (diff) |
Omega cache, session, and account provider complete overhaul
Diffstat (limited to 'plugins/VNLib.Plugins.Essentials.Content.Routing/src')
-rw-r--r-- | plugins/VNLib.Plugins.Essentials.Content.Routing/src/PageRouterEntry.cs | 31 | ||||
-rw-r--r-- | plugins/VNLib.Plugins.Essentials.Content.Routing/src/Router.cs | 28 |
2 files changed, 28 insertions, 31 deletions
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/PageRouterEntry.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/PageRouterEntry.cs index 10b7075..0c04047 100644 --- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/PageRouterEntry.cs +++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/PageRouterEntry.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.Content.Routing @@ -23,32 +23,33 @@ */ using System; -using System.Threading.Tasks; -using System.Collections.Generic; +using System.ComponentModel.Design; using VNLib.Utils.Logging; +using VNLib.Plugins.Attributes; +using VNLib.Plugins.Extensions.Loading; + namespace VNLib.Plugins.Essentials.Content.Routing { - public sealed class PageRouterEntry : PluginBase, IPageRouter + public sealed class PageRouterEntry : PluginBase { public override string PluginName => "Essentials.Router"; private Router PageRouter; - public ValueTask<FileProcessArgs> RouteAsync(HttpEntity entity) => PageRouter.RouteAsync(entity); + + [ServiceConfigurator] + public void ConfigureServices(IServiceContainer services) + { + //Deploy the page router to the host + services.AddService(typeof(IPageRouter), PageRouter); + } protected override void OnLoad() { - try - { - //Init router - PageRouter = new(this); - Log.Information("Plugin loaded"); - } - catch (KeyNotFoundException knf) - { - Log.Error("Plugin failed to load, missing required configuration variables {err}", knf.Message); - } + //Init router + PageRouter = this.GetOrCreateSingleton<Router>(); + Log.Information("Plugin loaded"); } protected override void OnUnLoad() diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Router.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Router.cs index 7620809..31f1e0e 100644 --- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Router.cs +++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Router.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.Content.Routing @@ -25,33 +25,32 @@ using System; using System.Linq; using System.Buffers; -using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; using System.Collections.Concurrent; using System.Collections.ObjectModel; -using VNLib.Net.Http; -using VNLib.Utils.Logging; +using VNLib.Plugins.Essentials.Accounts; +using VNLib.Plugins.Extensions.Loading; using VNLib.Plugins.Extensions.Loading.Sql; -using VNLib.Plugins.Extensions.Loading.Events; using VNLib.Plugins.Essentials.Content.Routing.Model; using static VNLib.Plugins.Essentials.Accounts.AccountUtil; + namespace VNLib.Plugins.Essentials.Content.Routing { - internal class Router : IPageRouter, IIntervalScheduleable + [ConfigurationName("page_router", Required = false)] + internal class Router : IPageRouter { private static readonly RouteComparer Comparer = new(); private readonly RouteStore Store; - private readonly ConcurrentDictionary<IWebRoot, Task<ReadOnlyCollection<Route>>> RouteTable; + private readonly ConcurrentDictionary<IWebProcessor, Task<ReadOnlyCollection<Route>>> RouteTable; public Router(PluginBase plugin) { Store = new(plugin.GetContextOptions()); - plugin.ScheduleInterval(this, TimeSpan.FromSeconds(30)); RouteTable = new(); } @@ -59,11 +58,13 @@ namespace VNLib.Plugins.Essentials.Content.Routing public async ValueTask<FileProcessArgs> RouteAsync(HttpEntity entity) { ulong privilage = READ_MSK; - //Only select privilages for logged-in users - if (entity.Session.IsSet && entity.LoginCookieMatches() || entity.TokenMatches()) + + //Only select privilages for logged-in users, this is a medium security check since we may not have all data available + if (entity.Session.IsSet && entity.IsClientAuthorized(AuthorzationCheckLevel.Medium)) { privilage = entity.Session.Privilages; } + //Get the routing table for the current host ReadOnlyCollection<Route> routes = await RouteTable.GetOrAdd(entity.RequestedRoot, LoadRoutesAsync); //Find the proper routine for the connection @@ -75,7 +76,7 @@ namespace VNLib.Plugins.Essentials.Content.Routing /// </summary> public void ResetRoutes() => RouteTable.Clear(); - private async Task<ReadOnlyCollection<Route>> LoadRoutesAsync(IWebRoot root) + private async Task<ReadOnlyCollection<Route>> LoadRoutesAsync(IWebProcessor root) { List<Route> collection = new(); //Load all routes @@ -152,10 +153,5 @@ namespace VNLib.Plugins.Essentials.Content.Routing //Test if the level and group privilages match for the current routine return (privilages & LEVEL_MSK) >= (route.Privilage & LEVEL_MSK) && (route.Privilage & GROUP_MSK) == (privilages & GROUP_MSK); } - - Task IIntervalScheduleable.OnIntervalAsync(ILogProvider log, CancellationToken cancellationToken) - { - return Task.CompletedTask; - } } } |