Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jan 14, 2024
1 parent 1768c0d commit ef4d137
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace DotNext.Maintenance;

using Buffers;
using Collections.Specialized;
using Security.Principal;
using static IO.TextStreamExtensions;
using static Runtime.InteropServices.UnixDomainSocketInterop;
Expand Down Expand Up @@ -236,7 +237,7 @@ protected sealed override async Task ExecuteAsync(CancellationToken token)
}
}

private sealed class MaintenanceSession : Dictionary<string, object>, IMaintenanceSession
private sealed class MaintenanceSession : TypeMap, IMaintenanceSession
{
private object? identityOrPrincipal;

Expand All @@ -263,7 +264,7 @@ internal MaintenanceSession(Socket socket, Encoding encoding, BufferWriter<byte>

public TextWriter ResponseWriter { get; }

IDictionary<string, object> IMaintenanceSession.Context => this;
ITypeMap IMaintenanceSession.Context => this;

private void Dispose(bool disposing)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static async Task AuthenticateAsync(this IAuthenticationHandler handler
{
var session = (context.Console as IMaintenanceConsole)?.Session;

if (session?.Principal is { Identity: { IsAuthenticated: true } })
if (session?.Principal is { Identity.IsAuthenticated: true })
{
// already authenticated
await next(context).ConfigureAwait(false);
Expand All @@ -33,7 +33,7 @@ internal static async Task AuthenticateAsync(this IAuthenticationHandler handler

internal static Task SetDefaultPrincipal(InvocationContext context, Func<InvocationContext, Task> next)
{
if ((context.Console as IMaintenanceConsole)?.Session is { Principal: null } session)
if (context.Console is IMaintenanceConsole { Session: { Principal: null } session })
{
session.Principal = new GenericPrincipal(session.Identity, roles: null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace DotNext.Maintenance.CommandLine.Authorization;

using Collections.Specialized;

/// <summary>
/// Represents authorization rule.
/// </summary>
Expand All @@ -11,4 +13,4 @@ namespace DotNext.Maintenance.CommandLine.Authorization;
/// <param name="context">Maintenance session context.</param>
/// <param name="token">The token that can be used to cancel the operation.</param>
/// <returns><see langword="true"/> if authorization passed successfully; otherwise, <see langword="false"/>.</returns>
public delegate ValueTask<bool> AuthorizationCallback(IPrincipal principal, CommandResult target, IDictionary<string, object> context, CancellationToken token);
public delegate ValueTask<bool> AuthorizationCallback(IPrincipal principal, CommandResult target, ITypeMap context, CancellationToken token);
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace DotNext.Maintenance;

using Collections.Specialized;

/// <summary>
/// Represents AMI interaction session.
/// </summary>
Expand All @@ -15,7 +17,7 @@ public interface IMaintenanceSession
/// <summary>
/// Gets a context that can be used to exchange information between command executions.
/// </summary>
IDictionary<string, object> Context { get; }
ITypeMap Context { get; }

/// <summary>
/// Gets command response writer.
Expand Down

0 comments on commit ef4d137

Please sign in to comment.