schemas: add proper validation of voice_region type

This commit is contained in:
Luna 2019-04-25 20:55:06 -03:00
parent 2076beb5fa
commit 5a15f3caf2
2 changed files with 9 additions and 10 deletions

View File

@ -18,10 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
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)

View File

@ -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)