Add Code for v0.2.2

This commit is contained in:
TheJoKlLa
2022-01-03 21:13:03 +00:00
parent f14dab06c4
commit 8be154ab7a
123 changed files with 7334 additions and 2120 deletions

View File

@ -111,44 +111,44 @@ namespace FabAccessAPI
//private static readonly log4net.ILog _Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
private IAuthenticationSystem _authCap;
private readonly IAuthenticationSystem _AuthCap;
public Auth(IAuthenticationSystem authCap)
{
_authCap = authCap;
_AuthCap = authCap;
}
public Task<IReadOnlyList<string>> GetMechanisms()
{
return _authCap.Mechanisms();
return _AuthCap.Mechanisms();
}
public async Task<bool> Authenticate(string mech, Dictionary<string, object> properties)
{
var m = SaslFactory.Create(mech);
SaslMechanism? m = SaslFactory.Create(mech);
foreach (KeyValuePair<string, object> entry in properties)
{
m.Properties.Add(entry.Key, entry.Value);
}
var initialResponse = new Request.initialResponse();
Request.initialResponse? initialResponse = new Request.initialResponse();
if (m.HasInitial)
{
initialResponse.Initial = m.GetResponse(new byte[0]);
}
var req = new Request
Request? req = new Request
{
Mechanism = m.Name,
InitialResponse = initialResponse
};
var resp = await _authCap.Start(req);
Response? resp = await _AuthCap.Start(req);
while (!m.IsCompleted)
{
if (resp.which == Response.WHICH.Challence)
{
var additional = m.GetResponse(resp.Challence.ToArray());
resp = await _authCap.Step(additional);
byte[]? additional = m.GetResponse(resp.Challence.ToArray());
resp = await _AuthCap.Step(additional);
}
else
{

View File

@ -10,29 +10,29 @@ namespace FabAccessAPI
{
public class Connection
{
#region private variables
private readonly TcpRpcClient? _rpcClient = null;
private readonly IBootstrap? _bootstrapCap = null;
private Auth? _auth = null;
#endregion
public TcpRpcClient? RpcClient => _rpcClient;
#region Log
//private static readonly log4net.ILog _Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Private Fields
private readonly IBootstrap? _BootstrapCap = null;
private Auth? _Auth = null;
#endregion
#region Constructors
/// <summary>
///
/// </summary>
/// <param name="rpcClient">Should be an already configured and connected TcpRpcClient</param>
public Connection(TcpRpcClient rpcClient)
{
_rpcClient = rpcClient;
_bootstrapCap = _rpcClient.GetMain<IBootstrap>();
RpcClient = rpcClient;
_BootstrapCap = RpcClient.GetMain<IBootstrap>();
//_Log.Debug($"Done bootstraping API connection.");
}
#endregion
#region Fields
public TcpRpcClient? RpcClient { get; } = null;
#endregion
#region Methods
/// <summary>
/// Authenticate this connection.
/// Calling this more then once is UB
@ -42,22 +42,19 @@ namespace FabAccessAPI
/// <returns></returns>
public async Task<bool> Auth(string mech, Dictionary<string, object> kvs, CancellationToken cancellationToken_ = default)
{
// _bootstrapCap = await _bootstrapCap.Unwrap();
if(_auth == null)
if(_Auth == null)
{
var authCap = await _bootstrapCap.AuthenticationSystem(cancellationToken_);
_auth = new Auth(authCap);
IAuthenticationSystem? authCap = await _BootstrapCap.AuthenticationSystem(cancellationToken_).ConfigureAwait(false);
_Auth = new Auth(authCap);
}
var mechs = await _auth.GetMechanisms();
//_Log.Debug($"The Server supports the following auth mechs: {string.Join(", ", mechs)}");
IReadOnlyList<string>? mechs = await _Auth.GetMechanisms();
if (!mechs.Contains(mech))
{
throw new UnsupportedMechanismException();
}
return await _auth.Authenticate(mech, kvs);
return await _Auth.Authenticate(mech, kvs);
}
/// <summary>
@ -66,7 +63,7 @@ namespace FabAccessAPI
/// <returns>A wrapped capability to interact with machines</returns>
public async Task<IMachineSystem> AccessMachineSystem()
{
return await _bootstrapCap.MachineSystem();
return await _BootstrapCap.MachineSystem();
}
/// <summary>
@ -75,7 +72,7 @@ namespace FabAccessAPI
/// <returns>A wrapped capability to interact with users</returns>
public async Task<IUserSystem> AccessUserSystem()
{
return await _bootstrapCap.UserSystem();
return await _BootstrapCap.UserSystem();
}
/// <summary>
@ -84,7 +81,8 @@ namespace FabAccessAPI
/// <returns>A wrapped capability to interact with permissions</returns>
public async Task<IPermissionSystem> AccessPermissionSystem()
{
return await _bootstrapCap.PermissionSystem();
return await _BootstrapCap.PermissionSystem();
}
#endregion
}
}

View File

@ -12,8 +12,8 @@
<ItemGroup>
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.118" />
<PackageReference Include="log4net" Version="2.0.12" />
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="5.0.4" />
<PackageReference Include="log4net" Version="2.0.13" />
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.0.0" />
</ItemGroup>
<ItemGroup>