-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add token validation * Switch token to security and testing it * Intro httpx for testing * Support query and brief in server * Fix testing * Intro fast release for mutex * Testing query
- Loading branch information
Showing
26 changed files
with
414 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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,2 @@ | ||
[run] | ||
omit = duetector/cli/* |
This file contains 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 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 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 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 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 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 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 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,13 +1,34 @@ | ||
from fastapi import FastAPI | ||
from fastapi import Depends, FastAPI, HTTPException | ||
from fastapi.security import APIKeyQuery | ||
from starlette.status import HTTP_403_FORBIDDEN | ||
|
||
from duetector.__init__ import __version__ | ||
from duetector.service.config import Config, get_server_config | ||
from duetector.service.control.routes import r as cr | ||
from duetector.service.query.routes import r as qr | ||
|
||
|
||
async def verify_token( | ||
server_config: Config = Depends(get_server_config), | ||
token: str = Depends(APIKeyQuery(name="token", auto_error=False)), | ||
): | ||
if server_config.token and token != server_config.token: | ||
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Not authenticated") | ||
|
||
|
||
app = FastAPI( | ||
title="Duetector", | ||
description="Data Usage Extensible Detector for data usage observability", | ||
version=__version__, | ||
dependencies=[Depends(verify_token)], | ||
) | ||
app.include_router(qr) | ||
app.include_router(cr) | ||
|
||
|
||
@app.get("/") | ||
async def root(): | ||
""" | ||
Just a simple health check, returns a message. | ||
""" | ||
return {"message": "Hello World"} |
This file contains 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,22 @@ | ||
from typing import Any, Dict, Optional | ||
|
||
from fastapi import Depends | ||
|
||
from duetector.config import Configuable | ||
from duetector.service.config import get_config | ||
|
||
|
||
class Controller(Configuable): | ||
config_scope = None | ||
|
||
default_config = {} | ||
|
||
def __init__(self, config: Optional[Dict[str, Any]] = None, *args, **kwargs): | ||
super().__init__(config, *args, **kwargs) | ||
|
||
|
||
def get_controller(controller_type: type): | ||
def _(config: dict = Depends(get_config)) -> Controller: | ||
return controller_type(config) | ||
|
||
return _ |
This file contains 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 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,5 @@ | ||
from duetector.service.base import Controller | ||
|
||
|
||
class DaemonControler(Controller): | ||
pass |
Empty file.
This file contains 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 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,9 @@ | ||
from fastapi import HTTPException | ||
from starlette.status import HTTP_404_NOT_FOUND | ||
|
||
|
||
class NotFoundError(HTTPException): | ||
def __init__(self, what: str = ""): | ||
if what: | ||
what = f"{what} " | ||
super().__init__(status_code=HTTP_404_NOT_FOUND, detail=f"{what}Not found") |
Oops, something went wrong.