Allow device routing without pinning
This commit is contained in:
@@ -314,7 +314,7 @@ export function createDeviceInventoryService({
|
||||
}
|
||||
|
||||
function policyIdentity(device) {
|
||||
return device?.pinned && device.confidence !== 'ambiguous'
|
||||
return Boolean(device) && device.confidence !== 'ambiguous'
|
||||
&& net.isIPv4(String(device.ip || '')) && MAC_PATTERN.test(device.mac)
|
||||
&& isDeviceInterface(device.interface);
|
||||
}
|
||||
@@ -783,11 +783,6 @@ export function createDeviceInventoryService({
|
||||
if (state.revision !== expectedRevision) throw new HarborError('STATE_CONFLICT');
|
||||
const index = state.devices.findIndex((device) => device.id === id);
|
||||
if (index < 0) throw new HarborError('DEVICE_NOT_FOUND');
|
||||
const currentPolicy = policyFor(state, state.devices[index].mac);
|
||||
if (pinProvided && patch.pinned === false
|
||||
&& (currentPolicy.desired === 'direct' || currentPolicy.applied === 'direct')) {
|
||||
throw new HarborError('REQUEST_INVALID');
|
||||
}
|
||||
const devices = [...state.devices];
|
||||
devices[index] = {
|
||||
...devices[index],
|
||||
@@ -809,7 +804,6 @@ export function createDeviceInventoryService({
|
||||
if (state.revision !== expectedRevision) throw new HarborError('STATE_CONFLICT');
|
||||
const device = state.devices.find((candidate) => candidate.id === id);
|
||||
if (!device) throw new HarborError('DEVICE_NOT_FOUND');
|
||||
if (mode === 'direct' && !device.pinned) throw new HarborError('DEVICE_POLICY_REQUIRES_PIN');
|
||||
if (mode === 'direct' && !policyIdentity(device)) throw new HarborError('DEVICE_IDENTITY_AMBIGUOUS');
|
||||
const current = policyFor(state, device.mac);
|
||||
if (current.desired === mode && current.status === 'applied') return state;
|
||||
|
||||
Reference in New Issue
Block a user