-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/public api refactor #43
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
Open
RusticPotatoes
wants to merge
11
commits into
Bot-detector:develop
Choose a base branch
from
RusticPotatoes:feature/public-api-refactor
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9b17799
refactor public api for endpoints, added tests
RusticPotatoes e4e1364
adding tests
RusticPotatoes 55f6fc0
moved api back under bot_detector in bases
RusticPotatoes c21ffcf
user player struct
RusticPotatoes c3572d3
config parsing issue
RusticPotatoes 37cd75a
remove bases
RusticPotatoes 9e8234d
repo to services rename, moved to components and set structure
RusticPotatoes 6ff9443
update readme
RusticPotatoes 30973b9
working refactor
RusticPotatoes c21ff88
rename
b5916a3
rename
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../src/core/fastapi/dependencies/session.py → ...blic/core/fastapi/dependencies/session.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
158 changes: 79 additions & 79 deletions
158
...ot_detector/api_public/src/core/server.py → bases/bot_detector/api_public/core/server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,79 +1,79 @@ | ||
| import logging | ||
| from contextlib import asynccontextmanager | ||
| from bot_detector.api_public.src import api | ||
| from bot_detector.api_public.src.core.fastapi.dependencies.kafka import kafka_manager | ||
| from bot_detector.api_public.src.core.fastapi.middleware import ( | ||
| LoggingMiddleware, | ||
| PrometheusMiddleware, | ||
| ) | ||
| from bot_detector.kafka import Settings as KafkaSettings | ||
| from bot_detector.kafka.repositories import RepoReportsToInsertProducer | ||
| from fastapi import FastAPI | ||
| from fastapi.middleware import Middleware | ||
| from fastapi.middleware.cors import CORSMiddleware | ||
| from prometheus_client import start_http_server | ||
| logger = logging.getLogger(__name__) | ||
| def init_routers(_app: FastAPI) -> None: | ||
| _app.include_router(api.router) | ||
| def make_middleware() -> list[Middleware]: | ||
| middleware = [ | ||
| Middleware( | ||
| CORSMiddleware, | ||
| allow_origins=[ | ||
| "http://osrsbotdetector.com/", | ||
| "https://osrsbotdetector.com/", | ||
| "http://localhost", | ||
| "http://localhost:8080", | ||
| ], | ||
| allow_credentials=True, | ||
| allow_methods=["*"], | ||
| allow_headers=["*"], | ||
| ), | ||
| Middleware(LoggingMiddleware), | ||
| Middleware(PrometheusMiddleware), | ||
| ] | ||
| return middleware | ||
| @asynccontextmanager | ||
| async def lifespan(app: FastAPI): | ||
| logger.info("startup initiated") | ||
| kafka_manager.set_producer( | ||
| key="reports_to_insert", | ||
| producer=RepoReportsToInsertProducer( | ||
| bootstrap_servers=KafkaSettings().KAFKA_BOOTSTRAP_SERVERS | ||
| ), | ||
| ) | ||
| producer = kafka_manager.get_producer(key="reports_to_insert") | ||
| await producer.start() | ||
| yield | ||
| await producer.stop() | ||
| logger.info("shutdown completed") | ||
| def create_app() -> FastAPI: | ||
| _app = FastAPI( | ||
| title="Bot-Detector-API", | ||
| description="Bot-Detector-API", | ||
| middleware=make_middleware(), | ||
| lifespan=lifespan, | ||
| ) | ||
| init_routers(_app=_app) | ||
| return _app | ||
| app = create_app() | ||
| start_http_server(8000) | ||
| @app.get("/") | ||
| async def root(): | ||
| return {"message": "Hello World"} | ||
| import logging | ||
| from contextlib import asynccontextmanager | ||
|
|
||
| from bases.bot_detector.api_public import routes as routes_pkg | ||
| from bases.bot_detector.api_public.core.fastapi.dependencies.kafka import kafka_manager | ||
| from bases.bot_detector.api_public.core.fastapi.middleware import ( | ||
| LoggingMiddleware, | ||
| PrometheusMiddleware, | ||
| ) | ||
| from bot_detector.kafka import Settings as KafkaSettings | ||
| from bot_detector.kafka.repositories import RepoReportsToInsertProducer | ||
| from fastapi import FastAPI | ||
| from fastapi.middleware import Middleware | ||
| from fastapi.middleware.cors import CORSMiddleware | ||
| from prometheus_client import start_http_server | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def init_routers(_app: FastAPI) -> None: | ||
| _app.include_router(routes_pkg.router) | ||
|
|
||
|
|
||
| def make_middleware() -> list[Middleware]: | ||
| middleware = [ | ||
| Middleware( | ||
| CORSMiddleware, | ||
| allow_origins=[ | ||
| "http://osrsbotdetector.com/", | ||
| "https://osrsbotdetector.com/", | ||
| "http://localhost", | ||
| "http://localhost:8080", | ||
| ], | ||
| allow_credentials=True, | ||
| allow_methods=["*"], | ||
| allow_headers=["*"], | ||
| ), | ||
| Middleware(LoggingMiddleware), | ||
| Middleware(PrometheusMiddleware), | ||
| ] | ||
| return middleware | ||
|
|
||
|
|
||
| @asynccontextmanager | ||
| async def lifespan(app: FastAPI): | ||
| logger.info("startup initiated") | ||
| kafka_manager.set_producer( | ||
| key="reports_to_insert", | ||
| producer=RepoReportsToInsertProducer( | ||
| bootstrap_servers=KafkaSettings().KAFKA_BOOTSTRAP_SERVERS | ||
| ), | ||
| ) | ||
| producer = kafka_manager.get_producer(key="reports_to_insert") | ||
| await producer.start() | ||
| yield | ||
| await producer.stop() | ||
| logger.info("shutdown completed") | ||
|
|
||
|
|
||
| def create_app() -> FastAPI: | ||
| _app = FastAPI( | ||
| title="Bot-Detector-API", | ||
| description="Bot-Detector-API", | ||
| middleware=make_middleware(), | ||
| lifespan=lifespan, | ||
| ) | ||
| init_routers(_app=_app) | ||
| return _app | ||
|
|
||
|
|
||
| app = create_app() | ||
|
|
||
|
|
||
| start_http_server(8000) | ||
|
|
||
|
|
||
| @app.get("/") | ||
| async def root(): | ||
| return {"message": "Hello World"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from bases.bot_detector.api_public.feedback.routes import router | ||
|
|
||
| __all__ = ["router"] |
2 changes: 1 addition & 1 deletion
2
...i_public/src/app/repositories/feedback.py → ...etector/api_public/feedback/repository.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...etector/api_public/src/api/v2/feedback.py → ...ot_detector/api_public/feedback/routes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from bases.bot_detector.api_public.labels.routes import router | ||
|
|
||
| __all__ = ["router"] |
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
..._detector/api_public/src/api/v2/labels.py → .../bot_detector/api_public/labels/routes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from bases.bot_detector.api_public.player.routes import router | ||
|
|
||
| __all__ = ["router"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.