-
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.
- Loading branch information
Showing
13 changed files
with
109 additions
and
5 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
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,26 @@ | ||
from fastapi import FastAPI | ||
from typing import Optional | ||
|
||
from fastapi import Depends, FastAPI, HTTPException, Query | ||
|
||
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: Optional[str] = Query(default=""), | ||
): | ||
if server_config.token and token != server_config.token: | ||
raise HTTPException(403, "Invalid token") | ||
|
||
|
||
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) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
|
||
@r.get("/") | ||
async def root(config: dict = Depends(get_config)): | ||
return config | ||
pass |
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,17 @@ | ||
from typing import Any, Dict, Optional | ||
|
||
from duetector.analyzer.base import Analyzer | ||
from duetector.analyzer.db import DBAnalyzer | ||
from duetector.service.base import Controller | ||
|
||
|
||
class AnalyzerController(Controller): | ||
def __init__(self, config: Optional[Dict[str, Any]] = None, *args, **kwargs): | ||
super().__init__(config, *args, **kwargs) | ||
|
||
# TODO: Make this configurable | ||
self.analyzer: Analyzer = self._init_analyzer(DBAnalyzer) | ||
|
||
def _init_analyzer(self, analyzer: type): | ||
analyzer_config = getattr(self.config, analyzer.config_scope)._config_dict | ||
return analyzer(analyzer_config) |
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
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