Skip to content

Commit

Permalink
Merge pull request #99 from DNO-inc/bodya
Browse files Browse the repository at this point in the history
redis error handler & changes in nginx config
  • Loading branch information
m-o-d-e-r authored Jul 20, 2023
2 parents c051d34 + 2e68cb3 commit fe6a501
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 243 deletions.
361 changes: 182 additions & 179 deletions CHANGELOG.md

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions burrito/apps/about/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import uvicorn
from random import randint
from fastapi.routing import APIRoute

from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


Expand All @@ -12,14 +10,15 @@
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url="/about/docs", openapi_url="/about/openapi.json")
connect_app(app, "/about", about_router)
app = get_current_app(docs_url=f"/{_APP_NAME}/docs", openapi_url=f"/{_APP_NAME}/openapi.json")
connect_app(app, f"/{_APP_NAME}", about_router)


if __name__ == "__main__":
uvicorn.run(
"burrito.apps.about.__main__:app",
f"burrito.apps.{_APP_NAME}.__main__:app",
host="0.0.0.0",
port=int(get_config().BURRITO_PORT_ABOUT),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS)
Expand Down
11 changes: 5 additions & 6 deletions burrito/apps/admin/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import uvicorn
from random import randint
from fastapi.routing import APIRoute

from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


Expand All @@ -12,14 +10,15 @@
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url="/admin/docs", openapi_url="/admin/openapi.json")
connect_app(app, "/admin", admin_router)
app = get_current_app(docs_url=f"/{_APP_NAME}/docs", openapi_url=f"/{_APP_NAME}/openapi.json")
connect_app(app, f"/{_APP_NAME}", admin_router)


if __name__ == "__main__":
uvicorn.run(
"burrito.apps.admin.__main__:app",
f"burrito.apps.{_APP_NAME}.__main__:app",
host="0.0.0.0",
port=int(get_config().BURRITO_PORT_ADMIN),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS)
Expand Down
11 changes: 5 additions & 6 deletions burrito/apps/anon/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import uvicorn
from random import randint
from fastapi.routing import APIRoute

from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


Expand All @@ -12,14 +10,15 @@
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url="/anon/docs", openapi_url="/anon/openapi.json")
connect_app(app, "/anon", anon_router)
app = get_current_app(docs_url=f"/{_APP_NAME}/docs", openapi_url=f"/{_APP_NAME}/openapi.json")
connect_app(app, f"/{_APP_NAME}", anon_router)


if __name__ == "__main__":
uvicorn.run(
"burrito.apps.anon.__main__:app",
f"burrito.apps.{_APP_NAME}.__main__:app",
host="0.0.0.0",
port=int(get_config().BURRITO_PORT_ANON),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS)
Expand Down
11 changes: 5 additions & 6 deletions burrito/apps/auth/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import uvicorn
from random import randint
from fastapi.routing import APIRoute

from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


Expand All @@ -12,14 +10,15 @@
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url="/auth/docs", openapi_url="/auth/openapi.json")
connect_app(app, "/auth", auth_router)
app = get_current_app(docs_url=f"/{_APP_NAME}/docs", openapi_url=f"/{_APP_NAME}/openapi.json")
connect_app(app, f"/{_APP_NAME}", auth_router)


if __name__ == "__main__":
uvicorn.run(
"burrito.apps.auth.__main__:app",
f"burrito.apps.{_APP_NAME}.__main__:app",
host="0.0.0.0",
port=int(get_config().BURRITO_PORT_AUTH),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS)
Expand Down
11 changes: 5 additions & 6 deletions burrito/apps/comments/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import uvicorn
from random import randint
from fastapi.routing import APIRoute

from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


Expand All @@ -12,14 +10,15 @@
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url="/comments/docs", openapi_url="/comments/openapi.json")
connect_app(app, "/comments", comments_router)
app = get_current_app(docs_url=f"/{_APP_NAME}/docs", openapi_url=f"/{_APP_NAME}/openapi.json")
connect_app(app, f"/{_APP_NAME}", comments_router)


if __name__ == "__main__":
uvicorn.run(
"burrito.apps.comments.__main__:app",
f"burrito.apps.{_APP_NAME}.__main__:app",
host="0.0.0.0",
port=int(get_config().BURRITO_PORT_COMMENTS),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS)
Expand Down
11 changes: 5 additions & 6 deletions burrito/apps/iofiles/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import uvicorn
from random import randint
from fastapi.routing import APIRoute

from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


Expand All @@ -12,14 +10,15 @@
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url="/iofiles/docs", openapi_url="/iofiles/openapi.json")
connect_app(app, "/iofiles", iofiles_router)
app = get_current_app(docs_url=f"/{_APP_NAME}/docs", openapi_url=f"/{_APP_NAME}/openapi.json")
connect_app(app, f"/{_APP_NAME}", iofiles_router)


if __name__ == "__main__":
uvicorn.run(
"burrito.apps.iofiles.__main__:app",
f"burrito.apps.{_APP_NAME}.__main__:app",
host="0.0.0.0",
port=int(get_config().BURRITO_PORT_IOFILES),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS)
Expand Down
11 changes: 5 additions & 6 deletions burrito/apps/meta/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import uvicorn
from random import randint
from fastapi.routing import APIRoute

from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


Expand All @@ -12,14 +10,15 @@
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url="/meta/docs", openapi_url="/meta/openapi.json")
connect_app(app, "/meta", meta_router)
app = get_current_app(docs_url=f"/{_APP_NAME}/docs", openapi_url=f"/{_APP_NAME}/openapi.json")
connect_app(app, f"/{_APP_NAME}", meta_router)


if __name__ == "__main__":
uvicorn.run(
"burrito.apps.meta.__main__:app",
f"burrito.apps.{_APP_NAME}.__main__:app",
host="0.0.0.0",
port=int(get_config().BURRITO_PORT_META),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS)
Expand Down
11 changes: 5 additions & 6 deletions burrito/apps/profile/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import uvicorn
from random import randint
from fastapi.routing import APIRoute

from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


Expand All @@ -12,14 +10,15 @@
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url="/profile/docs", openapi_url="/profile/openapi.json")
connect_app(app, "/profile", profile_router)
app = get_current_app(docs_url=f"/{_APP_NAME}/docs", openapi_url=f"/{_APP_NAME}/openapi.json")
connect_app(app, f"/{_APP_NAME}", profile_router)


if __name__ == "__main__":
uvicorn.run(
"burrito.apps.profile.__main__:app",
f"burrito.apps.{_APP_NAME}.__main__:app",
host="0.0.0.0",
port=int(get_config().BURRITO_PORT_PROFILE),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS)
Expand Down
11 changes: 5 additions & 6 deletions burrito/apps/registration/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import uvicorn
from random import randint
from fastapi.routing import APIRoute

from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


Expand All @@ -12,14 +10,15 @@
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url="/registration/docs", openapi_url="/registration/openapi.json")
connect_app(app, "/registration", registration_router)
app = get_current_app(docs_url=f"/{_APP_NAME}/docs", openapi_url=f"/{_APP_NAME}/openapi.json")
connect_app(app, f"/{_APP_NAME}", registration_router)


if __name__ == "__main__":
uvicorn.run(
"burrito.apps.registration.__main__:app",
f"burrito.apps.{_APP_NAME}.__main__:app",
host="0.0.0.0",
port=int(get_config().BURRITO_PORT_REGISTRATION),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS)
Expand Down
11 changes: 5 additions & 6 deletions burrito/apps/tickets/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import uvicorn
from random import randint
from fastapi.routing import APIRoute

from burrito.utils.config_reader import get_config
from burrito.containers import prepare_app
from burrito.containers import prepare_app, get_current_app_name
from burrito.utils.app_util import get_current_app, connect_app


Expand All @@ -12,14 +10,15 @@
else:
print("App preparation failed")

_APP_NAME = get_current_app_name()

app = get_current_app(docs_url="/tickets/docs", openapi_url="/tickets/openapi.json")
connect_app(app, "/tickets", tickets_router)
app = get_current_app(docs_url=f"/{_APP_NAME}/docs", openapi_url=f"/{_APP_NAME}/openapi.json")
connect_app(app, f"/{_APP_NAME}", tickets_router)


if __name__ == "__main__":
uvicorn.run(
"burrito.apps.tickets.__main__:app",
f"burrito.apps.{_APP_NAME}.__main__:app",
host="0.0.0.0",
port=int(get_config().BURRITO_PORT_TICKETS),
proxy_headers=bool(get_config().BURRITO_PROXY_HEADERS)
Expand Down
7 changes: 6 additions & 1 deletion burrito/containers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uvicorn
from pathlib import Path
import inspect

from burrito.utils.config_reader import get_config

Expand All @@ -7,6 +8,10 @@
from burrito.init.tasks.preprocessor_task import PreProcessorTask


def get_current_app_name() -> str:
return Path(inspect.getouterframes(inspect.currentframe(), 2)[1][1]).parent.name


def prepare_app():
get_config() # read configs

Expand Down
4 changes: 2 additions & 2 deletions burrito/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def verify_access_token(self) -> AuthTokenPayload:
return token_payload

raise AuthTokenError(
detail="Authorization token is invalid or expired",
detail="Something went wrong",
status_code=status.HTTP_401_UNAUTHORIZED
)

Expand All @@ -113,7 +113,7 @@ async def verify_refresh_token(self) -> AuthTokenPayload:
return token_payload

raise AuthTokenError(
detail="Authorization token is invalid or expired",
detail="Something went wrong",
status_code=status.HTTP_401_UNAUTHORIZED
)

Expand Down
15 changes: 14 additions & 1 deletion burrito/utils/redis_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import redis
from fastapi import HTTPException

from burrito.utils.singleton_pattern import singleton
from burrito.utils.config_reader import get_config
from burrito.utils.logger import get_logger


@singleton
Expand All @@ -11,7 +13,18 @@ def __init__(self, *, host: str, port: int, password: str | None = None, **kwarg


def get_redis_connector() -> RedisConnector:
return RedisConnector(
_redis_object = RedisConnector(
host=get_config().BURRITO_REDIS_HOST,
port=int(get_config().BURRITO_REDIS_PORT)
)

try:
_redis_object.ping()
except (redis.exceptions.ConnectionError, ConnectionRefusedError) as exc:
get_logger().critical("Redis server is unavailable")
raise HTTPException(
status_code=500,
detail="Some of the services is unavailable, please try late"
) from exc

return _redis_object
9 changes: 9 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ http {

listen 8080;

# For SSU cabinet server
location / {
proxy_pass http://burrito_meta:10006/meta/;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /about/ {
proxy_pass http://burrito_about:10000/about/;

Expand Down

0 comments on commit fe6a501

Please sign in to comment.