endpoint retriever updated
This commit is contained in:
parent
efb528bd46
commit
88f94c37c2
|
|
@ -32,6 +32,9 @@ class Config:
|
|||
"/authentication/valid",
|
||||
"/api/Contact/Us/current_date",
|
||||
]
|
||||
NOT_SECURE_PATHS = [
|
||||
"/access/endpoints/available"
|
||||
]
|
||||
|
||||
APP_NAME = "evyos-web-api-gateway"
|
||||
TITLE = "WAG API Web Api Gateway"
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
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
|
||||
endpoint_active = EndpointRestriction.filter_one(
|
||||
EndpointRestriction.endpoint_name.ilike(f"%{endpoint_name}%"),
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ services:
|
|||
|
||||
commercial_mongo_service:
|
||||
container_name: commercial_mongo_service
|
||||
# image: "bitnami/mongodb:latest"
|
||||
image: "bitnami/mongodb:4.4.1-debian-10-r3"
|
||||
image: "bitnami/mongodb:latest"
|
||||
# image: "bitnami/mongodb:4.4.1-debian-10-r3"
|
||||
networks:
|
||||
- network_store_services
|
||||
environment:
|
||||
|
|
@ -61,100 +61,100 @@ services:
|
|||
- "41575:41575"
|
||||
networks:
|
||||
- network_store_services
|
||||
depends_on:
|
||||
- wag_management_init_service
|
||||
- grafana
|
||||
# depends_on:
|
||||
# - wag_management_init_service
|
||||
# - 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:
|
||||
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_init_service:
|
||||
container_name: wag_management_init_service
|
||||
build:
|
||||
context: .
|
||||
dockerfile: service_app_init/Dockerfile
|
||||
networks:
|
||||
- network_store_services
|
||||
depends_on:
|
||||
- postgres_commercial
|
||||
|
||||
wag_bank_services:
|
||||
container_name: wag_bank_services
|
||||
restart: on-failure
|
||||
build:
|
||||
context: .
|
||||
dockerfile: service_app_banks/mailService.Dockerfile
|
||||
networks:
|
||||
- network_store_services
|
||||
depends_on:
|
||||
- postgres_commercial
|
||||
environment:
|
||||
- DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
|
||||
- PYTHONPATH=/service_app_banks
|
||||
|
||||
wag_account_services:
|
||||
container_name: wag_account_services
|
||||
restart: on-failure
|
||||
build:
|
||||
context: .
|
||||
dockerfile: service_account_records/account.Dockerfile
|
||||
networks:
|
||||
- network_store_services
|
||||
depends_on:
|
||||
- postgres_commercial
|
||||
environment:
|
||||
- DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
|
||||
- PYTHONPATH=/
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus
|
||||
container_name: prometheus
|
||||
ports:
|
||||
- "9090:9090"
|
||||
volumes:
|
||||
- ./prometheus_data/prometheus.yml:/etc/prometheus/prometheus.yml
|
||||
command:
|
||||
- '--config.file=/etc/prometheus/prometheus.yml'
|
||||
networks:
|
||||
- network_store_services
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana
|
||||
container_name: grafana
|
||||
ports:
|
||||
- "3030:3000"
|
||||
depends_on:
|
||||
- prometheus
|
||||
networks:
|
||||
- network_store_services
|
||||
environment:
|
||||
- GF_SECURITY_ADMIN_USER=admin
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
- 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
|
||||
# wag_management_init_service:
|
||||
# container_name: wag_management_init_service
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: service_app_init/Dockerfile
|
||||
# networks:
|
||||
# - network_store_services
|
||||
# depends_on:
|
||||
# - postgres_commercial
|
||||
#
|
||||
# wag_bank_services:
|
||||
# container_name: wag_bank_services
|
||||
# restart: on-failure
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: service_app_banks/mailService.Dockerfile
|
||||
# networks:
|
||||
# - network_store_services
|
||||
# depends_on:
|
||||
# - postgres_commercial
|
||||
# environment:
|
||||
# - DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
|
||||
# - PYTHONPATH=/service_app_banks
|
||||
#
|
||||
# wag_account_services:
|
||||
# container_name: wag_account_services
|
||||
# restart: on-failure
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: service_account_records/account.Dockerfile
|
||||
# networks:
|
||||
# - network_store_services
|
||||
# depends_on:
|
||||
# - postgres_commercial
|
||||
# environment:
|
||||
# - DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
|
||||
# - PYTHONPATH=/
|
||||
#
|
||||
# prometheus:
|
||||
# image: prom/prometheus
|
||||
# container_name: prometheus
|
||||
# ports:
|
||||
# - "9090:9090"
|
||||
# volumes:
|
||||
# - ./prometheus_data/prometheus.yml:/etc/prometheus/prometheus.yml
|
||||
# command:
|
||||
# - '--config.file=/etc/prometheus/prometheus.yml'
|
||||
# networks:
|
||||
# - network_store_services
|
||||
#
|
||||
# grafana:
|
||||
# image: grafana/grafana
|
||||
# container_name: grafana
|
||||
# ports:
|
||||
# - "3030:3000"
|
||||
# depends_on:
|
||||
# - prometheus
|
||||
# networks:
|
||||
# - network_store_services
|
||||
# environment:
|
||||
# - GF_SECURITY_ADMIN_USER=admin
|
||||
# - GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
# - 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:
|
||||
# container_name: nginx-proxy-wag
|
||||
|
|
|
|||
|
|
@ -1,13 +1,19 @@
|
|||
from fastapi.routing import APIRouter
|
||||
from fastapi.requests import Request
|
||||
|
||||
from api_objects import OccupantTokenObject, EmployeeTokenObject
|
||||
from api_validations.validations_request import (
|
||||
UpdateEndpointAccessList,
|
||||
InsertEndpointAccess,
|
||||
)
|
||||
|
||||
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.include_router(
|
||||
|
|
@ -25,7 +31,7 @@ def endpoint_restriction_create(request: Request, data: InsertEndpointAccess):
|
|||
|
||||
|
||||
@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):
|
||||
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(
|
||||
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):
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
return
|
||||
token_dict, records = parse_token_object_to_dict(request=request), []
|
||||
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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue