public async Task UpdateHardwareVaultStatusAsync(string vaultId, string workstationId) { var remoteDevice = await ConnectDevice(vaultId, workstationId).TimeoutAfter(30_000); await remoteDevice.RefreshDeviceInfo(); if (remoteDevice == null) { throw new HideezException(HideezErrorCode.HesFailedEstablishRemoteDeviceConnection); } var vault = await _hardwareVaultService.GetVaultByIdAsync(vaultId); if (vault == null) { throw new HideezException(HideezErrorCode.HesDeviceNotFound); } switch (vault.Status) { case VaultStatus.Ready: throw new HideezException(HideezErrorCode.HesDeviceNotAssignedToAnyUser); case VaultStatus.Reserved: // Required Link if (remoteDevice.AccessLevel.IsLinkRequired) { await _remoteTaskService.LinkVaultAsync(remoteDevice, vault); break; } // Transition to Active status if (!remoteDevice.AccessLevel.IsLinkRequired && !remoteDevice.IsLocked) { await _remoteTaskService.AccessVaultAsync(remoteDevice, vault); await _hardwareVaultService.SetActiveStatusAsync(vault); break; } // Transition to Locked status if (remoteDevice.IsLocked && !remoteDevice.IsCanUnlock) { await _hardwareVaultService.SetLockedStatusAsync(vault); break; } break; case VaultStatus.Active: // Transition to Locked status if (remoteDevice.IsLocked) { await _hardwareVaultService.SetLockedStatusAsync(vault); break; } break; case VaultStatus.Locked: throw new HideezException(HideezErrorCode.HesDeviceLocked); case VaultStatus.Suspended: // Apply Suspend status if (!vault.IsStatusApplied) { await _remoteTaskService.SuspendVaultAsync(remoteDevice, vault); break; } else { // Transition to Locked status if (remoteDevice.IsLocked && !remoteDevice.IsCanUnlock) { await _hardwareVaultService.SetLockedStatusAsync(vault); break; } // Transition to Active status if (!remoteDevice.IsLocked) { await _hardwareVaultService.SetActiveStatusAsync(vault); break; } } break; case VaultStatus.Deactivated: await _remoteTaskService.WipeVaultAsync(remoteDevice, vault); await _hardwareVaultService.SetReadyStatusAsync(vault); throw new HideezException(HideezErrorCode.DeviceHasBeenWiped); case VaultStatus.Compromised: throw new HideezException(HideezErrorCode.HesDeviceCompromised); default: throw new Exception($"Unhandled vault status. ({vault.Status})"); } }