def validate_pairing_code(pairing_code): cache_key = 'pairing.code:' + pairing_code cache = SeleneCache() pairing_cache = cache.get(cache_key) if pairing_cache is None: raise ValidationError('pairing code not found')
def validate_pairing_code_removal(context): """Ensure that the endpoint removed the pairing code entry from the cache.""" cache = SeleneCache() pairing_data = cache.get( DEVICE_PAIRING_CODE_KEY.format(pairing_code=context.pairing_code) ) assert_that(pairing_data, none())
class UpdateDeviceLastContact(SeleneScript): def __init__(self): super(UpdateDeviceLastContact, self).__init__(__file__) self.cache = SeleneCache() def _run(self): device_repo = DeviceRepository(self.db) devices_updated = 0 for device in device_repo.get_all_device_ids(): last_contact_ts = self._get_ts_from_cache(device.id) if last_contact_ts is not None: devices_updated += 1 device_repo.update_last_contact_ts(device.id, last_contact_ts) self.log.info(str(devices_updated) + ' devices were active today') def _get_ts_from_cache(self, device_id): last_contact_ts = None cache_key = DEVICE_LAST_CONTACT_KEY.format(device_id=device_id) value = self.cache.get(cache_key) if value is not None: last_contact_ts = datetime.strptime(value.decode(), '%Y-%m-%d %H:%M:%S.%f') self.cache.delete(cache_key) return last_contact_ts
def validate_pairing_code(pairing_code): """Ensure the pairing code exists in the cache of valid pairing codes.""" cache_key = DEVICE_PAIRING_CODE_KEY.format(pairing_code=pairing_code) cache = SeleneCache() pairing_cache = cache.get(cache_key) if pairing_cache is None: raise ValidationError("pairing code not found")
def validate_pairing_code(pairing_code): """Ensure the pairing code exists in the cache of valid pairing codes.""" cache_key = "pairing.code:" + pairing_code cache = SeleneCache() pairing_cache = cache.get(cache_key) if pairing_cache is None: raise ValidationError("pairing code not found")
def validate_pairing_token(context): device_id = context.response.data.decode() cache = SeleneCache() pairing_data = cache.get("pairing.token:this is a token") pairing_data = json.loads(pairing_data) assert_that(pairing_data["uuid"], equal_to(device_id)) assert_that(pairing_data["state"], equal_to(context.pairing_data["state"])) assert_that(pairing_data["token"], equal_to(context.pairing_data["token"]))
def validate_pairing_token(context): device_id = context.response.data.decode() cache = SeleneCache() pairing_data = cache.get('pairing.token:this is a token') pairing_data = json.loads(pairing_data) assert_that(pairing_data['uuid'], equal_to(device_id)) assert_that(pairing_data['state'], equal_to(context.pairing_data['state'])) assert_that(pairing_data['token'], equal_to(context.pairing_data['token']))
def validate_pairing_token(context): """Validate the pairing token data was added to the cache as expected.""" device_id = context.response.data.decode() cache = SeleneCache() pairing_data = cache.get( DEVICE_PAIRING_TOKEN_KEY.format(pairing_token="this is a token")) pairing_data = json.loads(pairing_data) assert_that(pairing_data["uuid"], equal_to(device_id)) assert_that(pairing_data["state"], equal_to(context.pairing_data["state"])) assert_that(pairing_data["token"], equal_to(context.pairing_data["token"]))
def delete_device_login(device_id: str, cache: SeleneCache): session = cache.get("device.session:{uuid}".format(uuid=device_id)) if session is not None: session = json.loads(session) access_token = session["accessToken"] cache.delete( "device.token.access:{access}".format(access=access_token)) refresh_token = session["refreshToken"] cache.delete( "device.refresh.token:{refresh}".format(refresh=refresh_token)) cache.delete("device.session:{uuid}".format(uuid=device_id))
def validate_pairing_code_removal(context): cache = SeleneCache() pairing_data = cache.get("pairing.code:ABC123") assert_that(pairing_data, none())