3 services are updated
This commit is contained in:
31
api_services/api_builds/restriction_service/Dockerfile
Normal file
31
api_services/api_builds/restriction_service/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
WORKDIR /
|
||||
|
||||
# Install system dependencies and Poetry
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends gcc && rm -rf /var/lib/apt/lists/* && pip install --no-cache-dir poetry
|
||||
|
||||
# Copy Poetry configuration
|
||||
COPY /pyproject.toml ./pyproject.toml
|
||||
|
||||
# Configure Poetry and install dependencies with optimizations
|
||||
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi --no-root --only main && pip cache purge && rm -rf ~/.cache/pypoetry
|
||||
|
||||
# Copy application code
|
||||
COPY /api_services/api_initializer /api_initializer
|
||||
COPY /api_services/api_controllers /api_controllers
|
||||
COPY /api_services/api_validations /api_validations
|
||||
COPY /api_services/api_modules /api_modules
|
||||
COPY /api_services/schemas /schemas
|
||||
|
||||
COPY /api_services/api_middlewares /api_middlewares
|
||||
COPY /api_services/api_builds/restriction-service/endpoints /api_initializer/endpoints
|
||||
COPY /api_services/api_builds/restriction-service/events /api_initializer/events
|
||||
COPY /api_services/api_builds/restriction-service/validations /api_initializer/validations
|
||||
COPY /api_services/api_builds/restriction-service/index.py /api_initializer/index.py
|
||||
|
||||
# Set Python path to include app directory
|
||||
ENV PYTHONPATH=/ PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
|
||||
|
||||
# Run the application using the configured uvicorn server
|
||||
CMD ["poetry", "run", "python", "/api_initializer/app.py"]
|
||||
@@ -0,0 +1,39 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from events.pages.events import PageHandlers
|
||||
from index import endpoints_index
|
||||
|
||||
from validations.request.restrictions.validations import RequestApplication
|
||||
from api_validations.defaults.validations import CommonHeaders
|
||||
|
||||
|
||||
pages_route = APIRouter(prefix="/restrictions", tags=["Restrictions Cluster"])
|
||||
|
||||
|
||||
application_retrieve_page = "ApplicationRetrievePage"
|
||||
@pages_route.post(
|
||||
path="/page/valid",
|
||||
summary="Verify if page is valid returns application available",
|
||||
description="Verify if page is valid returns application available",
|
||||
operation_id=endpoints_index[application_retrieve_page]
|
||||
)
|
||||
def authentication_page_valid(data: RequestApplication, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
|
||||
"""
|
||||
Verify if page is valid returns application that can user reach
|
||||
page: { url = /building/create} | result: { "application": "4c11f5ef-0bbd-41ac-925e-f79d9aac2b0e" }
|
||||
"""
|
||||
return PageHandlers.retrieve_valid_page_via_token(access_token=headers.token, page_url=data.page)
|
||||
|
||||
|
||||
application_retrieve_all_sites = "ApplicationRetrieveAllSites"
|
||||
@pages_route.get(
|
||||
path="/sites/list",
|
||||
summary="Lists all sites that are available for user",
|
||||
description="Lists all sites that are available for user",
|
||||
operation_id=endpoints_index[application_retrieve_all_sites]
|
||||
)
|
||||
def authentication_get_all_sites_list(headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
|
||||
"""
|
||||
Verify if page is valid returns application that can user reach result: { "sites": ['/dashboard', '/building/create'] }
|
||||
"""
|
||||
return PageHandlers.retrieve_valid_sites_via_token(access_token=headers.token)
|
||||
@@ -0,0 +1,15 @@
|
||||
from fastapi import APIRouter
|
||||
from .pages.router import pages_route
|
||||
|
||||
def get_routes() -> list[APIRouter]:
|
||||
return [pages_route]
|
||||
|
||||
|
||||
def get_safe_endpoint_urls() -> list[tuple[str, str]]:
|
||||
return [
|
||||
("/", "GET"),
|
||||
("/docs", "GET"),
|
||||
("/redoc", "GET"),
|
||||
("/openapi.json", "GET"),
|
||||
("/metrics", "GET"),
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
__all__ = []
|
||||
@@ -0,0 +1,34 @@
|
||||
from api_modules.redis.redis_handlers import RedisHandlers
|
||||
|
||||
|
||||
class PageHandlers:
|
||||
|
||||
@classmethod
|
||||
def retrieve_valid_page_via_token(cls, access_token: str, page_url: str) -> str:
|
||||
"""
|
||||
Retrieve valid page via token. {access_token: "string", page_url: "string"} | Results: str(application)
|
||||
"""
|
||||
if result := RedisHandlers.get_object_from_redis(access_token=access_token):
|
||||
if result.is_employee:
|
||||
if result.selected_company and result.selected_company.reachable_app_codes:
|
||||
if application := result.selected_company.reachable_app_codes.get(page_url, None):
|
||||
return application
|
||||
elif result.is_occupant:
|
||||
if result.selected_occupant and result.selected_occupant.reachable_app_codes:
|
||||
if application := result.selected_occupant.reachable_app_codes.get(page_url, None):
|
||||
return application
|
||||
raise ValueError("EYS_0013")
|
||||
|
||||
@classmethod
|
||||
def retrieve_valid_sites_via_token(cls, access_token: str) -> list:
|
||||
"""
|
||||
Retrieve valid pages via token. {"access_token": "string"} | Results: list(sites)
|
||||
"""
|
||||
if result := RedisHandlers.get_object_from_redis(access_token=access_token):
|
||||
if result.is_employee:
|
||||
if result.selected_company and result.selected_company.reachable_app_codes:
|
||||
return result.selected_company.reachable_app_codes.keys()
|
||||
elif result.is_occupant:
|
||||
if result.selected_occupant and result.selected_occupant.reachable_app_codes:
|
||||
return result.selected_occupant.reachable_app_codes.keys()
|
||||
raise ValueError("EYS_0013")
|
||||
5
api_services/api_builds/restriction_service/index.py
Normal file
5
api_services/api_builds/restriction_service/index.py
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
endpoints_index: dict = {
|
||||
"ApplicationRetrievePage": "e17a9475-0a8a-4a64-82a4-3357ac4a89d0",
|
||||
"ApplicationRetrieveAllSites": "e02b83fc-c579-460b-8a8a-04b46ff83318",
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class RequestApplication(BaseModel):
|
||||
page_url: str # /building/create
|
||||
Reference in New Issue
Block a user