mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-06-11 11:03:23 +02:00
improved tests and error handling
This commit is contained in:
@ -98,6 +98,7 @@ namespace FabAccessAPI {
|
||||
}
|
||||
|
||||
public class UnauthorizedException : Exception{}
|
||||
public class UnsupportedMechanismException : Exception{}
|
||||
|
||||
/// <summary>
|
||||
/// THIS IS VERY INCOMPLETE!
|
||||
|
@ -2,6 +2,7 @@
|
||||
using FabAccessAPI.Schema;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FabAccessAPI {
|
||||
@ -14,6 +15,8 @@ namespace FabAccessAPI {
|
||||
private Machines? _machines = null;
|
||||
#endregion
|
||||
|
||||
public TcpRpcClient? RpcClient => _rpcClient;
|
||||
|
||||
#region Log
|
||||
private static readonly log4net.ILog _Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
#endregion
|
||||
@ -40,9 +43,11 @@ namespace FabAccessAPI {
|
||||
var authCap = await _bootstrapCap.Auth();
|
||||
_auth = new Auth(authCap);
|
||||
var mechs = await _auth.GetMechanisms().ConfigureAwait(false);
|
||||
_Log.Debug($"The Server supports the following auth mechs: {mechs}");
|
||||
_Log.Debug($"The Server supports the following auth mechs: {string.Join(", ", mechs)}");
|
||||
|
||||
// TODO: Check that the requested auth mech is actually available.
|
||||
if (!mechs.Contains(mech)) {
|
||||
throw new UnsupportedMechanismException();
|
||||
}
|
||||
|
||||
await _auth.Authenticate(mech, kvs).ConfigureAwait(false);
|
||||
}
|
||||
|
@ -5,6 +5,9 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FabAccessAPI {
|
||||
|
||||
public class MachineException : Exception { }
|
||||
|
||||
/// <summary>
|
||||
/// Wraps a capability for accessing the Machines subsystem of BFFH
|
||||
/// </summary>
|
||||
@ -43,7 +46,7 @@ namespace FabAccessAPI {
|
||||
var mach = (await _machinesCap.GetMachine(name).ConfigureAwait(false)).Item1;
|
||||
if (mach == null) {
|
||||
//TODO: Throw a more specific exception!
|
||||
throw new Exception();
|
||||
throw new MachineException();
|
||||
}
|
||||
return new Machine(mach);
|
||||
}
|
||||
|
Reference in New Issue
Block a user