ajout des modèles dans le dépot halfAPI

This commit is contained in:
Maxime Alves LIRMM 2020-07-02 11:30:53 +02:00
parent 1a33b51904
commit d8729b1d49
15 changed files with 477 additions and 5 deletions

View File

@ -18,11 +18,11 @@ from typing import Any, Awaitable, Callable, MutableMapping
RequestResponseEndpoint = Callable[ [Request], Awaitable[Response] ] RequestResponseEndpoint = Callable[ [Request], Awaitable[Response] ]
# hop-generated classes # hop-generated classes
from apidb.api.acl_function import AclFunction from .models.api.acl_function import AclFunction
from apidb.api.domain import Domain from .models.api.domain import Domain
from apidb.api.route import Route from .models.api.route import Route
from apidb.api.view.acl import Acl as AclView from .models.api.view.acl import Acl as AclView
from apidb.api.view.route import Route as RouteView from .models.api.view.route import Route as RouteView
# module libraries # module libraries
from .lib.responses import ForbiddenResponse, NotFoundResponse from .lib.responses import ForbiddenResponse, NotFoundResponse

11
models/__init__.py Normal file
View File

@ -0,0 +1,11 @@
"""This file is part of the apidb package. It has been generated by the
command halfORM. To keep it in sync with your database structure, just rerun
halfORM.
More information on the half_orm library on https://github.com/collorg/halfORM.
"""
__all__ = [
'api',
'db_connector'
]

73
models/api.sql Normal file
View File

@ -0,0 +1,73 @@
create schema api;
create type verb as enum ('POST', 'GET', 'PUT', 'DELETE');
create table api.version (
name text primary key,
server cidr not null default '127.0.0.1',
port integer not null
);
create table api.domain (
version text references api.version(name),
name text,
primary key (version, name)
);
create table api.route (
path text, -- relative to /api/<version>/<domain>
version text,
domain text,
primary key (path, domain, version)
);
alter table api.route add constraint route_domain_fkey foreign key (version, domain) references api.domain(version, name) on update cascade on delete cascade;
create table api.acl_function (
name text,
description text,
version text,
domain text,
primary key (name, version, domain)
);
alter table api.acl_function add constraint acl_function_domain_fkey foreign key (version, domain) references api.domain(version, name) on update cascade on delete cascade;
create table api.acl (
name text,
http_verb verb,
path text not null,
version text,
domain text not null,
function text not null,
primary key (name, version, domain, function)
);
alter table api.acl add constraint acl_route_fkey foreign key (path, version, domain) references api.route(path, version, domain) on update cascade on delete cascade;
alter table api.acl add constraint acl_function_fkey foreign key (function, version, domain) references api.acl_function(name, version, domain) on update cascade on delete cascade;
create schema "api.view";
create view "api.view".route as
select
route.*,
version.name,
version.server,
version.port,
'/'::text || route.domain || route.path AS abs_path
from
api.route
join api.domain on
route.domain = domain.name
join api.version on
domain.version = version.name;
create view "api.view".acl as
select
acl.*,
acl_function.name as acl_function_name,
'/'::text || acl.domain || acl.path AS abs_path
from
api.acl
join api.acl_function on
acl.function = acl_function.name;

15
models/api/__init__.py Normal file
View File

@ -0,0 +1,15 @@
"""This file is part of the apidb package. It has been generated by the
command halfORM. To keep it in sync with your database structure, just rerun
halfORM.
More information on the half_orm library on https://github.com/collorg/halfORM.
"""
__all__ = [
'acl',
'acl_function',
'domain',
'route',
'version',
'view'
]

52
models/api/acl.py Normal file
View File

@ -0,0 +1,52 @@
#-*- coding: utf-8 -*-
# pylint: disable=wrong-import-order
"""The module apidb.api.acl povides the Acl class.
WARNING!
This file is part of the apidb package. It has been generated by the
command halfORM. To keep it in sync with your database structure, just rerun
halfORM.
More information on the half_orm library on https://github.com/collorg/halfORM.
DO NOT REMOVE OR MODIFY THE LINES BEGINING WITH:
#>>> PLACE YOUR CODE BELOW...
#<<< PLACE YOUR CODE ABOVE...
MAKE SURE YOU PLACE YOUR CODE BETWEEN THESE LINES OR AT THE END OF THE FILE.
halfORM ONLY PRESERVES THE CODE BETWEEN THESE MARKS WHEN IT IS RUN.
"""
from ..db_connector import base_relation_class
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!
#<<< PLACE YOUR CODE ABOVE THIS LINE. DO NOT REMOVE THIS LINE!
__RCLS = base_relation_class('api.acl')
class Acl( __RCLS):
"""
__RCLS: <class 'half_orm.relation.Table_ApiApiAcl'>
This class allows you to manipulate the data in the PG relation:
TABLE: "api"."api"."acl"
FIELDS:
- name: (text) PK
- http_verb: (verb)
- path: (text) NOT NULL
- version: (text) PK
- domain: (text) PK
- function: (text) PK
FOREIGN KEYS:
- acl_route_fkey: (path, version, domain)
"api"."api"."route"(path, version, domain)
- acl_function_fkey: (function, version, domain)
"api"."api"."acl_function"(name, version, domain)
"""
def __init__(self, **kwargs):
super(Acl, self).__init__(**kwargs)
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!

View File

@ -0,0 +1,50 @@
#-*- coding: utf-8 -*-
# pylint: disable=wrong-import-order
"""The module apidb.api.acl_function povides the AclFunction class.
WARNING!
This file is part of the apidb package. It has been generated by the
command halfORM. To keep it in sync with your database structure, just rerun
halfORM.
More information on the half_orm library on https://github.com/collorg/halfORM.
DO NOT REMOVE OR MODIFY THE LINES BEGINING WITH:
#>>> PLACE YOUR CODE BELOW...
#<<< PLACE YOUR CODE ABOVE...
MAKE SURE YOU PLACE YOUR CODE BETWEEN THESE LINES OR AT THE END OF THE FILE.
halfORM ONLY PRESERVES THE CODE BETWEEN THESE MARKS WHEN IT IS RUN.
"""
from ..db_connector import base_relation_class
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!
#<<< PLACE YOUR CODE ABOVE THIS LINE. DO NOT REMOVE THIS LINE!
__RCLS = base_relation_class('api.acl_function')
class AclFunction( __RCLS):
"""
__RCLS: <class 'half_orm.relation.Table_ApiApiAcl_function'>
This class allows you to manipulate the data in the PG relation:
TABLE: "api"."api"."acl_function"
FIELDS:
- name: (text) PK
- description: (text)
- version: (text) PK
- domain: (text) PK
FOREIGN KEYS:
- _reverse_fkey_api_api_acl_function_version_domain: (name, version, domain)
"api"."api"."acl"(function, version, domain)
- acl_function_domain_fkey: (version, domain)
"api"."api"."domain"(version, name)
"""
def __init__(self, **kwargs):
super(AclFunction, self).__init__(**kwargs)
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!

50
models/api/domain.py Normal file
View File

@ -0,0 +1,50 @@
#-*- coding: utf-8 -*-
# pylint: disable=wrong-import-order
"""The module apidb.api.domain povides the Domain class.
WARNING!
This file is part of the apidb package. It has been generated by the
command halfORM. To keep it in sync with your database structure, just rerun
halfORM.
More information on the half_orm library on https://github.com/collorg/halfORM.
DO NOT REMOVE OR MODIFY THE LINES BEGINING WITH:
#>>> PLACE YOUR CODE BELOW...
#<<< PLACE YOUR CODE ABOVE...
MAKE SURE YOU PLACE YOUR CODE BETWEEN THESE LINES OR AT THE END OF THE FILE.
halfORM ONLY PRESERVES THE CODE BETWEEN THESE MARKS WHEN IT IS RUN.
"""
from ..db_connector import base_relation_class
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!
#<<< PLACE YOUR CODE ABOVE THIS LINE. DO NOT REMOVE THIS LINE!
__RCLS = base_relation_class('api.domain')
class Domain( __RCLS):
"""
__RCLS: <class 'half_orm.relation.Table_ApiApiDomain'>
This class allows you to manipulate the data in the PG relation:
TABLE: "api"."api"."domain"
FIELDS:
- version: (text) PK
- name: (text) PK
FOREIGN KEYS:
- _reverse_fkey_api_api_acl_function_version_domain: (version, name)
"api"."api"."acl_function"(version, domain)
- domain_version_fkey: (version)
"api"."api"."version"(name)
- _reverse_fkey_api_api_route_version_domain: (version, name)
"api"."api"."route"(version, domain)
"""
def __init__(self, **kwargs):
super(Domain, self).__init__(**kwargs)
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!

49
models/api/route.py Normal file
View File

@ -0,0 +1,49 @@
#-*- coding: utf-8 -*-
# pylint: disable=wrong-import-order
"""The module apidb.api.route povides the Route class.
WARNING!
This file is part of the apidb package. It has been generated by the
command halfORM. To keep it in sync with your database structure, just rerun
halfORM.
More information on the half_orm library on https://github.com/collorg/halfORM.
DO NOT REMOVE OR MODIFY THE LINES BEGINING WITH:
#>>> PLACE YOUR CODE BELOW...
#<<< PLACE YOUR CODE ABOVE...
MAKE SURE YOU PLACE YOUR CODE BETWEEN THESE LINES OR AT THE END OF THE FILE.
halfORM ONLY PRESERVES THE CODE BETWEEN THESE MARKS WHEN IT IS RUN.
"""
from ..db_connector import base_relation_class
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!
#<<< PLACE YOUR CODE ABOVE THIS LINE. DO NOT REMOVE THIS LINE!
__RCLS = base_relation_class('api.route')
class Route( __RCLS):
"""
__RCLS: <class 'half_orm.relation.Table_ApiApiRoute'>
This class allows you to manipulate the data in the PG relation:
TABLE: "api"."api"."route"
FIELDS:
- path: (text) PK
- version: (text) PK
- domain: (text) PK
FOREIGN KEYS:
- _reverse_fkey_api_api_acl_path_version_domain: (path, version, domain)
"api"."api"."acl"(path, version, domain)
- route_domain_fkey: (version, domain)
"api"."api"."domain"(version, name)
"""
def __init__(self, **kwargs):
super(Route, self).__init__(**kwargs)
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!

47
models/api/version.py Normal file
View File

@ -0,0 +1,47 @@
#-*- coding: utf-8 -*-
# pylint: disable=wrong-import-order
"""The module apidb.api.version povides the Version class.
WARNING!
This file is part of the apidb package. It has been generated by the
command halfORM. To keep it in sync with your database structure, just rerun
halfORM.
More information on the half_orm library on https://github.com/collorg/halfORM.
DO NOT REMOVE OR MODIFY THE LINES BEGINING WITH:
#>>> PLACE YOUR CODE BELOW...
#<<< PLACE YOUR CODE ABOVE...
MAKE SURE YOU PLACE YOUR CODE BETWEEN THESE LINES OR AT THE END OF THE FILE.
halfORM ONLY PRESERVES THE CODE BETWEEN THESE MARKS WHEN IT IS RUN.
"""
from ..db_connector import base_relation_class
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!
#<<< PLACE YOUR CODE ABOVE THIS LINE. DO NOT REMOVE THIS LINE!
__RCLS = base_relation_class('api.version')
class Version( __RCLS):
"""
__RCLS: <class 'half_orm.relation.Table_ApiApiVersion'>
This class allows you to manipulate the data in the PG relation:
TABLE: "api"."api"."version"
FIELDS:
- name: (text) PK
- server: (cidr) NOT NULL
- port: (int4) NOT NULL
FOREIGN KEY:
- _reverse_fkey_api_api_domain_version: (name)
"api"."api"."domain"(version)
"""
def __init__(self, **kwargs):
super(Version, self).__init__(**kwargs)
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!

View File

@ -0,0 +1,11 @@
"""This file is part of the apidb package. It has been generated by the
command halfORM. To keep it in sync with your database structure, just rerun
halfORM.
More information on the half_orm library on https://github.com/collorg/halfORM.
"""
__all__ = [
'acl',
'route'
]

49
models/api/view/acl.py Normal file
View File

@ -0,0 +1,49 @@
#-*- coding: utf-8 -*-
# pylint: disable=wrong-import-order
"""The module apidb.api.view.acl povides the Acl class.
WARNING!
This file is part of the apidb package. It has been generated by the
command halfORM. To keep it in sync with your database structure, just rerun
halfORM.
More information on the half_orm library on https://github.com/collorg/halfORM.
DO NOT REMOVE OR MODIFY THE LINES BEGINING WITH:
#>>> PLACE YOUR CODE BELOW...
#<<< PLACE YOUR CODE ABOVE...
MAKE SURE YOU PLACE YOUR CODE BETWEEN THESE LINES OR AT THE END OF THE FILE.
halfORM ONLY PRESERVES THE CODE BETWEEN THESE MARKS WHEN IT IS RUN.
"""
from ...db_connector import base_relation_class
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!
#<<< PLACE YOUR CODE ABOVE THIS LINE. DO NOT REMOVE THIS LINE!
__RCLS = base_relation_class('api.view.acl')
class Acl( __RCLS):
"""
__RCLS: <class 'half_orm.relation.View_ApiApiviewAcl'>
This class allows you to manipulate the data in the PG relation:
VIEW: "api"."api.view"."acl"
FIELDS:
- name: (text)
- http_verb: (verb)
- path: (text)
- version: (text)
- domain: (text)
- function: (text)
- acl_function_name: (text)
- abs_path: (text)
"""
def __init__(self, **kwargs):
super(Acl, self).__init__(**kwargs)
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!

48
models/api/view/route.py Normal file
View File

@ -0,0 +1,48 @@
#-*- coding: utf-8 -*-
# pylint: disable=wrong-import-order
"""The module apidb.api.view.route povides the Route class.
WARNING!
This file is part of the apidb package. It has been generated by the
command halfORM. To keep it in sync with your database structure, just rerun
halfORM.
More information on the half_orm library on https://github.com/collorg/halfORM.
DO NOT REMOVE OR MODIFY THE LINES BEGINING WITH:
#>>> PLACE YOUR CODE BELOW...
#<<< PLACE YOUR CODE ABOVE...
MAKE SURE YOU PLACE YOUR CODE BETWEEN THESE LINES OR AT THE END OF THE FILE.
halfORM ONLY PRESERVES THE CODE BETWEEN THESE MARKS WHEN IT IS RUN.
"""
from ...db_connector import base_relation_class
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!
#<<< PLACE YOUR CODE ABOVE THIS LINE. DO NOT REMOVE THIS LINE!
__RCLS = base_relation_class('api.view.route')
class Route( __RCLS):
"""
__RCLS: <class 'half_orm.relation.View_ApiApiviewRoute'>
This class allows you to manipulate the data in the PG relation:
VIEW: "api"."api.view"."route"
FIELDS:
- path: (text)
- version: (text)
- domain: (text)
- name: (text)
- server: (cidr)
- port: (int4)
- abs_path: (text)
"""
def __init__(self, **kwargs):
super(Route, self).__init__(**kwargs)
#>>> PLACE YOUR CODE BELLOW THIS LINE. DO NOT REMOVE THIS LINE!

17
models/db_connector.py Normal file
View File

@ -0,0 +1,17 @@
#-*- coding: utf-8 -*-
"""This module exports the fonction base_relation_class which is
imported by all modules in the package apidb.
"""
from half_orm.model import Model
__all__ = ['base_relation_class']
MODEL = Model('api', scope=__name__)
def base_relation_class(qrn):
"""Returns the class corresponding to the QRN (qualified relation name).
"""
cls = MODEL.get_relation_class(qrn)
return cls