def list_available_devices( config_dir: Path) -> List[Tuple[OrganizationID, DeviceID, str, Path]]: try: candidate_pathes = list(get_devices_dir(config_dir).iterdir()) except FileNotFoundError: return [] # Sanity checks devices = [] for device_path in candidate_pathes: slug = device_path.name try: organization_id, device_id = LocalDevice.load_slug(slug) except ValueError: continue key_file = device_path / f"{slug}.keys" try: cipher = get_cipher_info(key_file) devices.append((organization_id, device_id, cipher, key_file)) except (LocalDeviceNotFoundError, LocalDeviceCryptoError): continue return devices
def _load_legacy_device_file(key_file_path: Path) -> Optional[AvailableDevice]: # For the legacy device files, the slug is contained in the device filename slug = key_file_path.stem try: organization_id, device_id = LocalDevice.load_slug(slug) except ValueError: # Not a valid slug, ignore this file return None try: data = legacy_key_file_serializer.loads(key_file_path.read_bytes()) except (FileNotFoundError, LocalDeviceError): # Not a valid device file, ignore this file return None return AvailableDevice( key_file_path=key_file_path, organization_id=organization_id, device_id=device_id, human_handle=data["human_handle"], device_label=data["device_label"], slug=slug, type=data["type"], )
def list_available_devices(config_dir: Path) -> List[AvailableDevice]: try: candidate_pathes = list(get_devices_dir(config_dir).iterdir()) except FileNotFoundError: return [] # Sanity checks devices = [] for device_folder_path in candidate_pathes: slug = device_folder_path.name key_file_path = device_folder_path / f"{slug}.keys" try: organization_id, device_id = LocalDevice.load_slug(slug) # Not a valid slug, ignore this folder except ValueError: continue try: data = key_file_serializer.loads(key_file_path.read_bytes()) except (FileNotFoundError, LocalDeviceError): # Not a valid device file, ignore this folder continue devices.append( AvailableDevice( key_file_path=key_file_path, organization_id=organization_id, device_id=device_id, human_handle=data["human_handle"], device_label=data["device_label"], )) return devices