[dummy_domain] add async routes, and routes that use arguments

This commit is contained in:
Maxime Alves LIRMM@home 2021-11-29 08:37:52 +01:00
parent ac4aadc2df
commit e203552876
5 changed files with 102 additions and 5 deletions

View File

@ -49,10 +49,10 @@ class DomainMiddleware(BaseHTTPMiddleware):
if 'args' in request.scope: if 'args' in request.scope:
# Set the http headers "x-args-required" and "x-args-optional" # Set the http headers "x-args-required" and "x-args-optional"
if 'required' in request.scope['args']: if len(request.scope['args'].get('required', set())):
response.headers['x-args-required'] = \ response.headers['x-args-required'] = \
','.join(request.scope['args']['required']) ','.join(request.scope['args']['required'])
if 'optional' in request.scope['args']: if len(request.scope['args'].get('optional', set())):
response.headers['x-args-optional'] = \ response.headers['x-args-optional'] = \
','.join(request.scope['args']['optional']) ','.join(request.scope['args']['optional'])

View File

@ -0,0 +1,5 @@
ROUTES = {
'': {
'SUBROUTES': ['async']
}
}

View File

@ -1,8 +1,11 @@
from halfapi.lib import acl
from halfapi.lib.acl import public
from random import randint from random import randint
public = lambda *args: True
random = lambda *args: randint(0,1) == 1 def random():
return randint(0,1) == 1
denied = lambda *args: False def denied():
return False

View File

@ -0,0 +1,38 @@
from ... import acl
from halfapi.logging import logger
ACLS = {
'GET' : [
{
'acl':acl.public,
'args': {
'required': {
'foo', 'bar'
},
'optional': {
'x'
}
}
},
{
'acl':acl.random,
'args': {
'required': {
'foo', 'baz'
},
'optional': {
'truebidoo'
}
}
},
]
}
def get(halfapi, data):
"""
description:
returns the configuration of the domain
"""
logger.error('%s', data['foo'])
return {'foo': data['foo'], 'bar': data['bar']}

View File

@ -0,0 +1,51 @@
from halfapi.lib.responses import ORJSONResponse
from ... import acl
ROUTES = {
'abc/alphabet/{test:uuid}': {
'GET': [{'acl': acl.public}]
},
'abc/pinnochio': {
'GET': [{'acl': acl.public}]
},
'config': {
'GET': [{'acl': acl.public}]
},
'arguments': {
'GET': [{
'acl': acl.public,
'args': {
'required': {'foo', 'bar'},
'optional': {}
}
}]
},
}
async def get_abc_alphabet_TEST(request, *args, **kwargs):
"""
description: Not implemented
"""
raise NotImplementedError
async def get_abc_pinnochio(request, *args, **kwargs):
"""
description: Not implemented
"""
raise NotImplementedError
async def get_config(request, *args, **kwargs):
"""
description: Not implemented
"""
raise NotImplementedError
async def get_arguments(request, *args, **kwargs):
"""
description: Liste des datatypes.
"""
return ORJSONResponse({
'foo': kwargs.get('foo'),
'bar': kwargs.get('bar')
})