From d8729b1d498ca3f0e6f78e0540c1b59ab2a91cc0 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Thu, 2 Jul 2020 11:30:53 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20des=20mod=C3=A8les=20dans=20le=20d?= =?UTF-8?q?=C3=A9pot=20halfAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- halfapi/app.py | 10 +-- halfapi/lib/__pycache__/query.cpython-38.pyc | Bin 2931 -> 0 bytes .../lib/__pycache__/responses.cpython-38.pyc | Bin 1864 -> 0 bytes models/__init__.py | 11 +++ models/api.sql | 73 ++++++++++++++++++ models/api/__init__.py | 15 ++++ models/api/acl.py | 52 +++++++++++++ models/api/acl_function.py | 50 ++++++++++++ models/api/domain.py | 50 ++++++++++++ models/api/route.py | 49 ++++++++++++ models/api/version.py | 47 +++++++++++ models/api/view/__init__.py | 11 +++ models/api/view/acl.py | 49 ++++++++++++ models/api/view/route.py | 48 ++++++++++++ models/db_connector.py | 17 ++++ 15 files changed, 477 insertions(+), 5 deletions(-) delete mode 100644 halfapi/lib/__pycache__/query.cpython-38.pyc delete mode 100644 halfapi/lib/__pycache__/responses.cpython-38.pyc create mode 100644 models/__init__.py create mode 100644 models/api.sql create mode 100644 models/api/__init__.py create mode 100644 models/api/acl.py create mode 100644 models/api/acl_function.py create mode 100644 models/api/domain.py create mode 100644 models/api/route.py create mode 100644 models/api/version.py create mode 100644 models/api/view/__init__.py create mode 100644 models/api/view/acl.py create mode 100644 models/api/view/route.py create mode 100644 models/db_connector.py diff --git a/halfapi/app.py b/halfapi/app.py index 1d6920a..920bb9e 100644 --- a/halfapi/app.py +++ b/halfapi/app.py @@ -18,11 +18,11 @@ from typing import Any, Awaitable, Callable, MutableMapping RequestResponseEndpoint = Callable[ [Request], Awaitable[Response] ] # hop-generated classes -from apidb.api.acl_function import AclFunction -from apidb.api.domain import Domain -from apidb.api.route import Route -from apidb.api.view.acl import Acl as AclView -from apidb.api.view.route import Route as RouteView +from .models.api.acl_function import AclFunction +from .models.api.domain import Domain +from .models.api.route import Route +from .models.api.view.acl import Acl as AclView +from .models.api.view.route import Route as RouteView # module libraries from .lib.responses import ForbiddenResponse, NotFoundResponse diff --git a/halfapi/lib/__pycache__/query.cpython-38.pyc b/halfapi/lib/__pycache__/query.cpython-38.pyc deleted file mode 100644 index 16dcebd77b041b5dd4e712170679cd16b49d1526..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2931 zcmcguPj4JG6t`z)H=9jTP#dZgie%-|Y?aO~5<+MdR#YK^B8Z}9+d`@kO=i5wWIZz* z+Z&Q-(*ub_dn(BDDiU~p z`}MEyejg{~5BwQ^9QgSZnwp0$AORI5qHC0rzzS?(MfREv<8kf;xu0o}55`V%Yq_AX zN=n67u!59mI`u`pzOuCM^Og>i_!Z5l6N{^lA9B@7V#QNrqq{y%^&T4r1!(wHhtP%O z1<|BKj%h%fj@&t92;qbrQBAegp&jyz9XO}-*gB>!$P*IZc8GSGMfnva`08AcJElL- zZ%J%@LjdYOuKkfTXfPHOP6|g>#{yHvy&HK#iVU8IT(@PcnBL~B5o#UATR_XqV9DkV z_cil;Kal~>=!EUIxjbMkPkIs8Tq?I{A0@jf&b;~e>w9ZGIirI3ShBo-P5Pro@i`;=*iJ%_{rg-rAc*-{~3-R^GV+HR!gh z&;#alvWR?8xhj3#FkhX*o`IdK(cDw_zxvZC`Q(xh>(cZ2rsp@=T$Cuh(0sTx&2`6w zr*!G^$%VZ?a%>vF=CwkX_cE4pM-o_-eORd!v(q9mV~wOOBw)%~g{CmILRx~Xc}iEw znYDaQt7kOLsg?*e4CwwDkyF5Q{&9IbiFlbuA)NHGl73l)GK$J*N*OP)`zsI37m&f! zX4za)ZtEZ|EC?^!47}PR$oUf*Ieh=M=e@^wPCMaCfcbA>%Q28Cp*A3L0z1T;b=Pq8 z7IdHE;BDwG$;<)q1~l~&x_~|>&Ahy;$#WRr!c1;KCcg_Vq669~g@VF1oOMIB`mb>O8ZIFs+nDa zC03qT2oqHaP*K62>KS$R`%byFm&PQXC6NWMqjr!FB+RfYErm?H$uIv+3?l z?A7{YOF2a-5;ursAM-w3xXsN5Kx_Y{*tG=pvFgI5xFls;l z_U%=hkY7=l9k53}f~h$WPB@h$#Fa^!v5-;ZEoo(TXlG97RI)AI%nLnAJ|*1Y?g`

-J)~`|>bcfU|&HV;0KTg_ygo^gkagYz4gT;Oi6_V_y&gq z6JJvySOS9x{{HJDX6QZ}K@|a#*^xD}PAzV6`-F_>9db<15Z#WkPn|RJBUJoz>&P}P zVBZ_DQ~#{0{E-cs+H;H7e`37Bn@=rDz9b)z&&ekFYFrz08=)f(06T3OdOVG#NX%af z3|&RoY{ArvK=#OpeA7IlBYH~C$TRj3-d6>&O-uJtEC)hE4`H3_r6r`92`{Fntgpya zo21D4t8e3tc(qFy8NNFcpJ|3VE3!ypsaJuSd^ViFFO)9wTu2>#w!V4y?()#?B>K_t zih;h>1@2~$^kSujx%FUsZTZ9D<=B`w>184}H-p_&3M`~sORwlsn+=<{i`;-_dHb+0 zh6@wvP71wFrzS1(m%o6MkU}pRpDeweh&ec+d{opFKBBb1aOpl)sSzryjo0F_Rv5t2 zF$Iqg6&B&RYW+Q7s$jJph0UR~ik zbE(T1t^Z+L?Dyf~ML`9NSRe|Msoq3_HKXvZnQXo89@jvDHmZv9sY1EkP)o3sKK?RH znu+l@i-z2&~23z#)!_eAu5D>)qWI~RCU>m)oC4<{>r%ftyXn`mG09fZCOp$ Ha$D}7`dz5) diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..8aaa822 --- /dev/null +++ b/models/__init__.py @@ -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' +] diff --git a/models/api.sql b/models/api.sql new file mode 100644 index 0000000..5b89aaa --- /dev/null +++ b/models/api.sql @@ -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 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; diff --git a/models/api/__init__.py b/models/api/__init__.py new file mode 100644 index 0000000..3fe4bd2 --- /dev/null +++ b/models/api/__init__.py @@ -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' +] diff --git a/models/api/acl.py b/models/api/acl.py new file mode 100644 index 0000000..e065fc4 --- /dev/null +++ b/models/api/acl.py @@ -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: + 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! diff --git a/models/api/acl_function.py b/models/api/acl_function.py new file mode 100644 index 0000000..2aecf9d --- /dev/null +++ b/models/api/acl_function.py @@ -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: + 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! diff --git a/models/api/domain.py b/models/api/domain.py new file mode 100644 index 0000000..5896fc5 --- /dev/null +++ b/models/api/domain.py @@ -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: + 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! diff --git a/models/api/route.py b/models/api/route.py new file mode 100644 index 0000000..596f8f7 --- /dev/null +++ b/models/api/route.py @@ -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: + 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! diff --git a/models/api/version.py b/models/api/version.py new file mode 100644 index 0000000..b1a6077 --- /dev/null +++ b/models/api/version.py @@ -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: + 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! diff --git a/models/api/view/__init__.py b/models/api/view/__init__.py new file mode 100644 index 0000000..8a38f03 --- /dev/null +++ b/models/api/view/__init__.py @@ -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' +] diff --git a/models/api/view/acl.py b/models/api/view/acl.py new file mode 100644 index 0000000..6fced55 --- /dev/null +++ b/models/api/view/acl.py @@ -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: + 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! diff --git a/models/api/view/route.py b/models/api/view/route.py new file mode 100644 index 0000000..f8d9eab --- /dev/null +++ b/models/api/view/route.py @@ -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: + 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! diff --git a/models/db_connector.py b/models/db_connector.py new file mode 100644 index 0000000..b0d2673 --- /dev/null +++ b/models/db_connector.py @@ -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