-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feedback and issues around transactions and the command line #173
Comments
Another one came up. I'm using Pact to verify the contract between my API and an Angular client. I cannot use Alba because Pact requires a real TCP socket to make requests. The fixture to spin up the website looks like this: public class WebFixture : IAsyncLifetime
{
readonly ITestOutputHelper _testOutputHelper;
public readonly Uri BackendUri = new("http://localhost:9001");
WebApplication? _app;
public WebFixture(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}
public Task InitializeAsync()
{
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
EnvironmentName = "ProviderTests",
});
builder.Logging
.Services
.AddSingleton<ILoggerProvider>(_ => new XUnitLoggerProvider(_testOutputHelper));
var startup = new StartupWrapper();
startup.ConfigureServices(builder);
_app = builder.Build();
_app.Urls.Add(BackendUri.ToString());
startup.ConfigureRequestPipeline(_app);
return _app.StartAsync();
}
public Task DisposeAsync()
=> _app?.DisposeAsync().AsTask() ?? Task.CompletedTask;
} What happens here is nothing special, just the normal bootstrapping and small additional services and middleware ( The test is successful apart from this being logged:
|
@agross Oh man, thank you so much for taking all this time. Might take a bit for me to get to think on this enough to respond, but I wanted you to know that I at least saw this come in. |
Hi @jeremydmiller, at the risk of flooding you with feedback (take your time!), I today tried to Wolverine-ify RBAC on the granularity of a command (still talking about I use KeyCloak for authentication and there is an excellent NuGet with an example to implement RBAC with a Mediatr behavior.. The code has a comment From my understanding, the Wolverine equivalent of using System.Runtime.CompilerServices;
using Application.Authorization;
using JasperFx.CodeGeneration;
using JasperFx.CodeGeneration.Frames;
using Lamar;
using Microsoft.Extensions.Logging;
using Wolverine.Configuration;
using Wolverine.Runtime.Handlers;
namespace Infrastructure.Authorization;
public class AuthorizationPolicy : IHandlerPolicy
{
static readonly Dictionary<Type, string[]> MessageTypeToPolicies = new();
public void Apply(HandlerGraph graph, GenerationRules rules, IContainer container)
{
foreach (var chain in graph.Chains)
{
Apply(chain);
}
}
void Apply(HandlerChain chain)
{
var policies = chain.MessageType
.GetCustomAttributes(typeof(AuthorizeAttribute), true)
.Cast<AuthorizeAttribute>()
.Select(x => x.Policy)
.Where(x => !string.IsNullOrWhiteSpace(x))
.ToArray();
if (!policies.Any())
{
return;
}
MessageTypeToPolicies.Add(chain.MessageType, policies!);
var method = GetType()
.GetMethod(nameof(EnforcePolicy))
.MakeGenericMethod(chain.MessageType);
var methodCall = new MethodCall(GetType(), method);
chain.Middleware.Add(methodCall);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async Task EnforcePolicy<T>(IIdentityService identityService, ILogger logger, T message)
{
var policies = MessageTypeToPolicies[message.GetType()];
foreach (var policy in policies)
{
if (await identityService.AuthorizeAsync(policy))
{
continue;
}
logger.LogWarning("Failed {Policy} policy authorization with user {User} for {Message}",
policy,
identityService.UserId,
message);
throw new UnauthorizedAccessException();
}
}
} The As you can see the handler policy uses a dictionary to cache the roles per message, but my ultimate goal would be to pass the list of roles directly to I tried that for a couple of hours, even cloned JasperFx.CodeGeneration, but I could not find a way to make the first argument a constant expression. Perhaps another way is to register "required roles per message" in the container, but that seems a bit too overboard. It would be great if you could share your ideas! |
Spawning #218 from this for the transactions |
I fixed the "Handlers with return values log FailureAcknowledgement" today, that came in from Discord as well. |
Spawning JasperFx/oakton#78 for the Oakton issue. |
Spawning #219 for the release global lock issue |
I'm technically closing this, but only after spawning a bunch of smaller issues:-) Thanks for all the feedback! |
Thank you for all the work you put into your OSS! 👍 |
Hello!
I recently started a new project and was interested in trying out Wolverine after following @jeremydmiller's blog posts. He was asking for feedback so here are my experiences.
The project is a Web API with hexagonal architecture. I'll be using Marten for document storage and right now am interested in the mediator bits of Wolverine. Perhaps async messaging will be added at some point in time when the need arises. The setup relevant Marten / Wolverine looks like this:
Automatic transactions around handlers
These are the handler bits I'll be referring to.
The documentation states
My testing found that the "or has some dependency that itself depends on
IDocumentSession
" bit is currently not true. TheBuildingRepository
stores theBuildingDto
, but that is never committed. Only after injecting the session into the handler and moving thesession.Store
call right into it the document is inserted into the database.Handlers with return values log
FailureAcknowledgement
There is another handler to retrieve all stored buildings.
Whenever this runs the following is logged:
I do not know whether this is to be expected, but
FailureAcknowledgement
does not sound good to me.Every time this happens a "Handled" row appears in
wolverine_incoming_envelopes
with data that looks like this:Command line failures
While researching why automatic transactions are not applied I was interested in seeing the code generated for the handler, similar to what @jeremydmiller uses in his blog posts (e.g. last code snippet here).
This is probably related to JasperFx/oakton#75, so I tried the
--launch-profile
workaround.Using Paket
I prefer to use Paket for NuGet dependency management. There might be some issues with open version constraints, for example
Spectre.Console >= 0.45
required byOakton 6.0
. Paket will always use the newest version that satisfies>= 0.45
, as opposed to NuGet which preferred the oldest version that matches the version constraint the last time I used it.The
paket.lock
file below does not contain packages starting withSystem.
orMicrosoft.
(I removed them for brevity).Spectre.Console 0.45
causes the sameSystem.Security.VerificationException
above.The text was updated successfully, but these errors were encountered: