From 5a15f3caf209cc3f418abd662ad5b75066cd3a5c Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 25 Apr 2019 20:55:06 -0300 Subject: [PATCH] schemas: add proper validation of voice_region type --- litecord/schemas.py | 11 +++++------ litecord/voice/lvsp_manager.py | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/litecord/schemas.py b/litecord/schemas.py index a65ec8f..288dd20 100644 --- a/litecord/schemas.py +++ b/litecord/schemas.py @@ -18,10 +18,12 @@ along with this program. If not, see . """ import re +import asyncio from typing import Union, Dict, List from cerberus import Validator from logbook import Logger +from quart import current_app as app from .errors import BadRequest from .permissions import Permissions @@ -97,12 +99,9 @@ class LitecordValidator(Validator): return False def _validate_type_voice_region(self, value: str) -> bool: - # TODO: call voice manager for regions instead of hardcoding - - # I'm sure the context would be there at least in a basic level, so - # we can access the app. - return value.lower() in ('brazil', 'us-east', 'us-west', - 'us-south', 'russia') + # NOTE: when this code is being ran, there is a small chance the + # app context injected by quart still exists + return value.lower() in app.voice.lvsp.regions.keys() def _validate_type_verification_level(self, value: int) -> bool: return _in_enum(VerificationLevel, value) diff --git a/litecord/voice/lvsp_manager.py b/litecord/voice/lvsp_manager.py index e96e1b0..30407dc 100644 --- a/litecord/voice/lvsp_manager.py +++ b/litecord/voice/lvsp_manager.py @@ -54,7 +54,7 @@ class LVSPManager: self.assign = {} # quick storage for Region dataclass instances. - self._regions = {} + self.regions = {} self.app.sched.spawn(self._spawn()) @@ -75,7 +75,7 @@ class LVSPManager: for region in regions: # store it locally for region() function - self._regions[region.id] = region + self.regions[region.id] = region self.app.loop.create_task( self._spawn_region(region) @@ -161,5 +161,5 @@ class LVSPManager: self.assign[key] = hostname def region(self, region_id: str) -> Optional[Region]: - """Get a :class:`Region` instance:wq:wq""" - return self._regions.get(region_id) + """Get a :class:`Region` instance""" + return self.regions.get(region_id)