Skip to content

Commit

Permalink
plugin configuration methods are now public.
Browse files Browse the repository at this point in the history
added base classes for authN and authZ.
removed Log dependency from authN provider factory.
  • Loading branch information
RagingKore committed May 22, 2024
1 parent eca0063 commit 3a35e89
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Routing;

namespace EventStore.Plugins.Authentication;

public abstract class AuthenticationProviderBase(PluginOptions options) : Plugin(options), IAuthenticationProvider {
protected AuthenticationProviderBase(
string? name = null,
string? version = null,
string? licensePublicKey = null,
string? diagnosticsName = null,
params KeyValuePair<string, object?>[] diagnosticsTags
) : this(new() {
Name = name,
Version = version,
LicensePublicKey = licensePublicKey,
DiagnosticsName = diagnosticsName,
DiagnosticsTags = diagnosticsTags
}) { }

public virtual Task Initialize() => Task.CompletedTask;

public abstract void Authenticate(AuthenticationRequest authenticationRequest);

public virtual IEnumerable<KeyValuePair<string, string>> GetPublicProperties() => [];

public virtual void ConfigureEndpoints(IEndpointRouteBuilder endpointRouteBuilder) { }

public virtual IReadOnlyList<string> GetSupportedAuthenticationSchemes() => [];
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Microsoft.Extensions.Logging;

namespace EventStore.Plugins.Authentication;

public interface IAuthenticationProviderFactory {
Expand All @@ -9,6 +7,5 @@ public interface IAuthenticationProviderFactory {
/// <param name="logFailedAuthenticationAttempts">
/// Whether the Authentication Provider should log failed authentication attempts
/// </param>
/// <param name="logger">The <see cref="ILogger" /> to use when logging in the plugin</param>
IAuthenticationProvider Build(bool logFailedAuthenticationAttempts, ILogger logger);
IAuthenticationProvider Build(bool logFailedAuthenticationAttempts);
}
21 changes: 21 additions & 0 deletions src/EventStore.Plugins/Authorization/AuthorizationProviderBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Security.Claims;

namespace EventStore.Plugins.Authorization;

public abstract class AuthorizationProviderBase(PluginOptions options) : Plugin(options), IAuthorizationProvider {
protected AuthorizationProviderBase(
string? name = null,
string? version = null,
string? licensePublicKey = null,
string? diagnosticsName = null,
params KeyValuePair<string, object?>[] diagnosticsTags
) : this(new() {
Name = name,
Version = version,
LicensePublicKey = licensePublicKey,
DiagnosticsName = diagnosticsName,
DiagnosticsTags = diagnosticsTags
}) { }

public abstract ValueTask<bool> CheckAccessAsync(ClaimsPrincipal principal, Operation operation, CancellationToken cancellationToken);
}
5 changes: 5 additions & 0 deletions src/EventStore.Plugins/IPlugableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public interface IPlugableComponent {
/// </summary>
bool Enabled { get; }

/// <summary>
/// The public key used for licensing.
/// </summary>
string? LicensePublicKey { get; }

/// <summary>
/// Configures the services using the provided IServiceCollection and IConfiguration.
/// </summary>
Expand Down
12 changes: 5 additions & 7 deletions src/EventStore.Plugins/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected Plugin(PluginOptions options) : this(
options.DiagnosticsName,
options.DiagnosticsTags) { }

string? LicensePublicKey { get; }
public string? LicensePublicKey { get; }

DiagnosticListener DiagnosticListener { get; }

Expand All @@ -78,11 +78,11 @@ protected Plugin(PluginOptions options) : this(
/// <inheritdoc />
public bool Enabled => IsEnabledResult.Enabled;

protected virtual void ConfigureServices(IServiceCollection services, IConfiguration configuration) { }
public virtual void ConfigureServices(IServiceCollection services, IConfiguration configuration) { }

protected virtual void ConfigureApplication(IApplicationBuilder app, IConfiguration configuration) { }
public virtual void ConfigureApplication(IApplicationBuilder app, IConfiguration configuration) { }

protected virtual (bool Enabled, string EnableInstructions) IsEnabled(IConfiguration configuration) => (true, "");
public virtual (bool Enabled, string EnableInstructions) IsEnabled(IConfiguration configuration) => (true, "");

IServiceCollection IPlugableComponent.ConfigureServices(IServiceCollection services, IConfiguration configuration) {
Configuration = configuration;
Expand Down Expand Up @@ -140,7 +140,5 @@ protected internal void PublishDiagnosticsEvent<T>(T pluginEvent) =>
DiagnosticListener.Write(typeof(T).Name, pluginEvent);

/// <inheritdoc />
public void Dispose() {
DiagnosticListener.Dispose();
}
public void Dispose() => DiagnosticListener.Dispose();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void can_receive_metrics_from_plugin() {
class AdamSmasherPlugin(params KeyValuePair<string, object?>[] diagnosticsTags) : Plugin(diagnosticsTags: diagnosticsTags) {
public Counter<int> TestCounter { get; private set; } = null!;

protected override void ConfigureApplication(IApplicationBuilder app, IConfiguration configuration) {
public override void ConfigureApplication(IApplicationBuilder app, IConfiguration configuration) {
var meterFactory = app.ApplicationServices.GetRequiredService<IMeterFactory>();

var meter = meterFactory.Create(DiagnosticsName, Version, DiagnosticsTags);
Expand Down

0 comments on commit 3a35e89

Please sign in to comment.