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 16dcebd..0000000 Binary files a/halfapi/lib/__pycache__/query.cpython-38.pyc and /dev/null differ diff --git a/halfapi/lib/__pycache__/responses.cpython-38.pyc b/halfapi/lib/__pycache__/responses.cpython-38.pyc deleted file mode 100644 index 4a87cbc..0000000 Binary files a/halfapi/lib/__pycache__/responses.cpython-38.pyc and /dev/null differ 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