Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for Management of database entities #564

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions lifecycle/lifecycle/auth/authorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from lifecycle.auth.subject import get_description_from_auth_subject
from lifecycle.database.condition_builder import QueryCondition
from lifecycle.database.schema import tables
from lifecycle.database.table_model import table_metadata
from lifecycle.server.cache import LifecycleCache
from racetrack_commons.auth.auth import AuthSubjectType, UnauthorizedError
from racetrack_commons.auth.scope import AuthScope
Expand Down Expand Up @@ -107,9 +108,9 @@ def has_endpoint_permission(
) -> bool:
mapper = LifecycleCache.record_mapper()
placeholder: str = mapper.placeholder
table_permission = tables.AuthResourcePermission.table_name()
table_family = tables.JobFamily.table_name()
table_job = tables.Job.table_name()
table_permission = table_metadata(tables.AuthResourcePermission).table_name
table_family = table_metadata(tables.JobFamily).table_name
table_job = table_metadata(tables.Job).table_name
join_expression = f'left join {table_family} on {table_family}.id = {table_permission}.job_family_id'
join_expression += f' left join {table_job} on {table_job}.id = {table_permission}.job_id'

Expand Down Expand Up @@ -153,9 +154,9 @@ def has_resource_permission(
) -> bool:
mapper = LifecycleCache.record_mapper()
placeholder: str = mapper.placeholder
table_permission = tables.AuthResourcePermission.table_name()
table_family = tables.JobFamily.table_name()
table_job = tables.Job.table_name()
table_permission = table_metadata(tables.AuthResourcePermission).table_name
table_family = table_metadata(tables.JobFamily).table_name
table_job = table_metadata(tables.Job).table_name
join_expression = f'left join {table_family} on {table_family}.id = {table_permission}.job_family_id'
join_expression += f' left join {table_job} on {table_job}.id = {table_permission}.job_id'

Expand Down Expand Up @@ -192,7 +193,7 @@ def has_scope_permission(
) -> bool:
mapper = LifecycleCache.record_mapper()
placeholder: str = mapper.placeholder
table_permission = tables.AuthResourcePermission.table_name()
table_permission = table_metadata(tables.AuthResourcePermission).table_name

subject_filter = QueryCondition(f'{table_permission}.auth_subject_id = {placeholder}', auth_subject.id)
scope_filter = QueryCondition.operator_or(
Expand Down Expand Up @@ -359,9 +360,9 @@ def permission_exists(
) -> bool:
mapper = LifecycleCache.record_mapper()
placeholder: str = mapper.placeholder
table_permission = tables.AuthResourcePermission.table_name()
table_family = tables.JobFamily.table_name()
table_job = tables.Job.table_name()
table_permission = table_metadata(tables.AuthResourcePermission).table_name
table_family = table_metadata(tables.JobFamily).table_name
table_job = table_metadata(tables.Job).table_name
join_expression = f'left join {table_family} on {table_family}.id = {table_permission}.job_family_id'
join_expression += f' left join {table_job} on {table_job}.id = {table_permission}.job_id'

Expand Down
13 changes: 6 additions & 7 deletions lifecycle/lifecycle/database/base_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ class DatabaseStatus:
connections_errors: int = 0 # Number of failed connection attempts


"""
Base class for Database Engines
- PostgreSQL implementation: file://./postgres/engine.py
- SQLite implementation: file://./sqlite/engine.py
"""
class DbEngine(ABC):
def __init__(self) -> None:
self.query_builder: BaseQueryBuilder
"""
Base class for Database Engines
- PostgreSQL implementation: file://./postgres/engine.py
- SQLite implementation: file://./sqlite/engine.py
"""
query_builder: BaseQueryBuilder

def check_connection(self) -> None:
pass
Expand Down
3 changes: 3 additions & 0 deletions lifecycle/lifecycle/database/query_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@


class QueryWrapper:
"""
A wrapper around DbEngine to provide a simple interface for common database operations and executing SQL queries.
"""
def __init__(self, engine: DbEngine):
self.engine: DbEngine = engine
self.query_builder: BaseQueryBuilder = engine.query_builder
Expand Down
Loading
Loading