endpoint retriever updated

This commit is contained in:
berkay 2024-12-03 21:27:33 +03:00
parent efb528bd46
commit 88f94c37c2
4 changed files with 135 additions and 101 deletions

View File

@ -32,6 +32,9 @@ class Config:
"/authentication/valid", "/authentication/valid",
"/api/Contact/Us/current_date", "/api/Contact/Us/current_date",
] ]
NOT_SECURE_PATHS = [
"/access/endpoints/available"
]
APP_NAME = "evyos-web-api-gateway" APP_NAME = "evyos-web-api-gateway"
TITLE = "WAG API Web Api Gateway" TITLE = "WAG API Web Api Gateway"

View File

@ -10,7 +10,7 @@ def parse_token_object_to_dict(request): # from requests import Request
if valid_token := get_object_via_access_key(request=request): if valid_token := get_object_via_access_key(request=request):
endpoint_name = str(request.url).replace(str(request.base_url), "/") endpoint_name = str(request.url).replace(str(request.base_url), "/")
if str(endpoint_name) in Config.INSECURE_PATHS: if str(endpoint_name) in Config.INSECURE_PATHS or str(endpoint_name) in Config.NOT_SECURE_PATHS:
return valid_token return valid_token
endpoint_active = EndpointRestriction.filter_one( endpoint_active = EndpointRestriction.filter_one(
EndpointRestriction.endpoint_name.ilike(f"%{endpoint_name}%"), EndpointRestriction.endpoint_name.ilike(f"%{endpoint_name}%"),

View File

@ -2,8 +2,8 @@ services:
commercial_mongo_service: commercial_mongo_service:
container_name: commercial_mongo_service container_name: commercial_mongo_service
# image: "bitnami/mongodb:latest" image: "bitnami/mongodb:latest"
image: "bitnami/mongodb:4.4.1-debian-10-r3" # image: "bitnami/mongodb:4.4.1-debian-10-r3"
networks: networks:
- network_store_services - network_store_services
environment: environment:
@ -61,100 +61,100 @@ services:
- "41575:41575" - "41575:41575"
networks: networks:
- network_store_services - network_store_services
depends_on: # depends_on:
- wag_management_init_service # - wag_management_init_service
- grafana # - grafana
#
# wag_management_service_second:
# container_name: wag_management_service_second
# restart: on-failure
# build:
# context: .
# dockerfile: service_app/Dockerfile
# ports:
# - "41576:41575"
# networks:
# - network_store_services
# depends_on:
# - wag_management_init_service
# - grafana
wag_management_service_second: # wag_management_init_service:
container_name: wag_management_service_second # container_name: wag_management_init_service
restart: on-failure # build:
build: # context: .
context: . # dockerfile: service_app_init/Dockerfile
dockerfile: service_app/Dockerfile # networks:
ports: # - network_store_services
- "41576:41575" # depends_on:
networks: # - postgres_commercial
- network_store_services #
depends_on: # wag_bank_services:
- wag_management_init_service # container_name: wag_bank_services
- grafana # restart: on-failure
# build:
wag_management_init_service: # context: .
container_name: wag_management_init_service # dockerfile: service_app_banks/mailService.Dockerfile
build: # networks:
context: . # - network_store_services
dockerfile: service_app_init/Dockerfile # depends_on:
networks: # - postgres_commercial
- network_store_services # environment:
depends_on: # - DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
- postgres_commercial # - PYTHONPATH=/service_app_banks
#
wag_bank_services: # wag_account_services:
container_name: wag_bank_services # container_name: wag_account_services
restart: on-failure # restart: on-failure
build: # build:
context: . # context: .
dockerfile: service_app_banks/mailService.Dockerfile # dockerfile: service_account_records/account.Dockerfile
networks: # networks:
- network_store_services # - network_store_services
depends_on: # depends_on:
- postgres_commercial # - postgres_commercial
environment: # environment:
- DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database # - DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
- PYTHONPATH=/service_app_banks # - PYTHONPATH=/
#
wag_account_services: # prometheus:
container_name: wag_account_services # image: prom/prometheus
restart: on-failure # container_name: prometheus
build: # ports:
context: . # - "9090:9090"
dockerfile: service_account_records/account.Dockerfile # volumes:
networks: # - ./prometheus_data/prometheus.yml:/etc/prometheus/prometheus.yml
- network_store_services # command:
depends_on: # - '--config.file=/etc/prometheus/prometheus.yml'
- postgres_commercial # networks:
environment: # - network_store_services
- DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database #
- PYTHONPATH=/ # grafana:
# image: grafana/grafana
prometheus: # container_name: grafana
image: prom/prometheus # ports:
container_name: prometheus # - "3030:3000"
ports: # depends_on:
- "9090:9090" # - prometheus
volumes: # networks:
- ./prometheus_data/prometheus.yml:/etc/prometheus/prometheus.yml # - network_store_services
command: # environment:
- '--config.file=/etc/prometheus/prometheus.yml' # - GF_SECURITY_ADMIN_USER=admin
networks: # - GF_SECURITY_ADMIN_PASSWORD=admin
- network_store_services # - GF_USERS_ALLOW_SIGN_UP=false
# - GF_USERS_ALLOW_ORG_CREATE=false
grafana: # volumes:
image: grafana/grafana # - grafana_data:/var/lib/grafana
container_name: grafana #
ports: # wag_management_test_service:
- "3030:3000" # container_name: wag_management_test_service
depends_on: # build:
- prometheus # context: .
networks: # dockerfile: service_app_test/Dockerfile
- network_store_services # networks:
environment: # - network_store_services
- GF_SECURITY_ADMIN_USER=admin # depends_on:
- GF_SECURITY_ADMIN_PASSWORD=admin # - wag_management_init_service
- GF_USERS_ALLOW_SIGN_UP=false
- GF_USERS_ALLOW_ORG_CREATE=false
volumes:
- grafana_data:/var/lib/grafana
wag_management_test_service:
container_name: wag_management_test_service
build:
context: .
dockerfile: service_app_test/Dockerfile
networks:
- network_store_services
depends_on:
- wag_management_init_service
# nginx-proxy-wag: # nginx-proxy-wag:
# container_name: nginx-proxy-wag # container_name: nginx-proxy-wag

View File

@ -1,13 +1,19 @@
from fastapi.routing import APIRouter from fastapi.routing import APIRouter
from fastapi.requests import Request from fastapi.requests import Request
from api_objects import OccupantTokenObject, EmployeeTokenObject
from api_validations.validations_request import ( from api_validations.validations_request import (
UpdateEndpointAccessList, UpdateEndpointAccessList,
InsertEndpointAccess, InsertEndpointAccess,
) )
from api_services.redis.auth_actions.token import parse_token_object_to_dict from api_services.redis.auth_actions.token import parse_token_object_to_dict
from databases import (
EndpointRestriction,
Event2Occupant,
Event2Employee,
Events,
)
endpoint_restriction_route = APIRouter(prefix="/access", tags=["Endpoint Access"]) endpoint_restriction_route = APIRouter(prefix="/access", tags=["Endpoint Access"])
endpoint_restriction_route.include_router( endpoint_restriction_route.include_router(
@ -25,7 +31,7 @@ def endpoint_restriction_create(request: Request, data: InsertEndpointAccess):
@endpoint_restriction_route.post( @endpoint_restriction_route.post(
path="/endpoint/bind/update", summary="Update extra restriction to endpoints list" path="/endpoint/update", summary="Update extra restriction to endpoints list"
) )
def endpoint_restriction_update(request: Request, data: UpdateEndpointAccessList): def endpoint_restriction_update(request: Request, data: UpdateEndpointAccessList):
token_dict = parse_token_object_to_dict(request=request) token_dict = parse_token_object_to_dict(request=request)
@ -33,11 +39,36 @@ def endpoint_restriction_update(request: Request, data: UpdateEndpointAccessList
@endpoint_restriction_route.post( @endpoint_restriction_route.post(
path="/endpoint/bind/list", summary="List extra restriction to endpoints list" path="/endpoints/available", summary="List extra restriction to endpoints list"
) )
def endpoint_restriction_list(request: Request): def endpoint_restriction_list(request: Request):
token_dict = parse_token_object_to_dict(request=request) token_dict, records = parse_token_object_to_dict(request=request), []
return if isinstance(token_dict, OccupantTokenObject):
occupant_events = Event2Occupant.filter_all(
Event2Occupant.build_living_space_id
== token_dict.selected_occupant.living_space_id
).data
events_list = Events.filter_all(
Events.id.in_([event.event_id for event in occupant_events])
).data
records = EndpointRestriction.filter_all(
EndpointRestriction.id.in_([event.endpoint_id for event in events_list])
).data
elif isinstance(token_dict, EmployeeTokenObject):
employee_events = Event2Employee.filter_all(
Event2Employee.employee_id == token_dict.selected_company.employee_id
).data
events_list = Events.filter_all(
Events.id.in_([event.event_id for event in employee_events])
).data
records = EndpointRestriction.filter_all(
EndpointRestriction.id.in_([event.endpoint_id for event in events_list])
).data
return dict(
completed=True,
message="Available endpoints are listed successfully",
result=[str(record.endpoint_name) for record in records],
)
@endpoint_restriction_route.patch( @endpoint_restriction_route.patch(