diff --git a/README.md b/README.md
index ca599b7..59aaf4f 100644
--- a/README.md
+++ b/README.md
@@ -62,9 +62,9 @@ pyninja start
- **RATE_LIMIT** - List of dictionaries with `max_requests` and `seconds` to apply as rate limit.
- **APIKEY** - API Key for authentication.
-⚠️ Enabling remote execution can be extremely risky and can be a major security threat. So use **caution** and set the **API_SECRET** to a strong value.
+⚠️ Enabling remote execution can be extremely risky and a major security threat.
+So use **caution** and set the **API_SECRET** to a strong value.
-> `PyNinja` supports [logging.ini] configuration for custom logging. Just place it in the current working directory.
> Refer [samples] directory for examples.
## Coding Standards
@@ -142,4 +142,3 @@ Licensed under the [MIT License][license]
[license]: https://github.com/thevickypedia/PyNinja/blob/master/LICENSE
[runbook]: https://thevickypedia.github.io/PyNinja/
[samples]: https://github.com/thevickypedia/PyNinja/tree/main/samples
-[logging.ini]: https://docs.python-guide.org/writing/logging/#example-configuration-via-an-ini-file
diff --git a/docs/README.html b/docs/README.html
index 24d5343..557c2aa 100644
--- a/docs/README.html
+++ b/docs/README.html
@@ -99,10 +99,10 @@
RATE_LIMIT - List of dictionaries with max_requests
and seconds
to apply as rate limit.
APIKEY - API Key for authentication.
⚠️ Enabling remote execution can be extremely risky and can be a major security threat. So use caution and set the API_SECRET to a strong value.
+⚠️ Enabling remote execution can be extremely risky and a major security threat. +So use caution and set the API_SECRET to a strong value.
-++
PyNinja
supports logging.ini configuration for custom logging. Just place it in the current working directory.
-Refer samples directory for examples.Refer samples directory for examples.
diff --git a/docs/README.md b/docs/README.md index ca599b7..59aaf4f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -62,9 +62,9 @@ pyninja start - **RATE_LIMIT** - List of dictionaries with `max_requests` and `seconds` to apply as rate limit. - **APIKEY** - API Key for authentication. -⚠️ Enabling remote execution can be extremely risky and can be a major security threat. So use **caution** and set the **API_SECRET** to a strong value. +⚠️ Enabling remote execution can be extremely risky and a major security threat. +So use **caution** and set the **API_SECRET** to a strong value. -> `PyNinja` supports [logging.ini] configuration for custom logging. Just place it in the current working directory.
> Refer [samples] directory for examples. ## Coding Standards @@ -142,4 +142,3 @@ Licensed under the [MIT License][license] [license]: https://github.com/thevickypedia/PyNinja/blob/master/LICENSE [runbook]: https://thevickypedia.github.io/PyNinja/ [samples]: https://github.com/thevickypedia/PyNinja/tree/main/samples -[logging.ini]: https://docs.python-guide.org/writing/logging/#example-configuration-via-an-ini-file diff --git a/docs/_sources/README.md.txt b/docs/_sources/README.md.txt index ca599b7..59aaf4f 100644 --- a/docs/_sources/README.md.txt +++ b/docs/_sources/README.md.txt @@ -62,9 +62,9 @@ pyninja start - **RATE_LIMIT** - List of dictionaries with `max_requests` and `seconds` to apply as rate limit. - **APIKEY** - API Key for authentication. -⚠️ Enabling remote execution can be extremely risky and can be a major security threat. So use **caution** and set the **API_SECRET** to a strong value. +⚠️ Enabling remote execution can be extremely risky and a major security threat. +So use **caution** and set the **API_SECRET** to a strong value. -> `PyNinja` supports [logging.ini] configuration for custom logging. Just place it in the current working directory.
> Refer [samples] directory for examples. ## Coding Standards @@ -142,4 +142,3 @@ Licensed under the [MIT License][license] [license]: https://github.com/thevickypedia/PyNinja/blob/master/LICENSE [runbook]: https://thevickypedia.github.io/PyNinja/ [samples]: https://github.com/thevickypedia/PyNinja/tree/main/samples -[logging.ini]: https://docs.python-guide.org/writing/logging/#example-configuration-via-an-ini-file diff --git a/docs/genindex.html b/docs/genindex.html index b95ef7c..468b4d7 100644 --- a/docs/genindex.html +++ b/docs/genindex.html @@ -209,6 +209,8 @@L
diff --git a/docs/index.html b/docs/index.html index 31ae267..6f46c3d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -72,6 +72,7 @@ Welcome to PyNinja’s documentation!Keyword Arguments:
@@ -652,6 +653,11 @@
- +
env_file – Env filepath to load the environment variables.
apikey – API Key for authentication.
ninja_host – Hostname for the API server.
ninja_port – Port number for the API server.
- @@ -79,7 +80,7 @@
workers – Number of workers for the uvicorn server.
Welcome to PyNinja’s documentation!max_requests and
seconds
to apply as rate limit. -- +
apikey – API Key for authentication.
log_config – Logging configuration as a dict or a FilePath. Supports .yaml/.yml, .json or .ini formats.
Models
>>> EnvConfig+
+- +apikey: str¶
+
- ninja_host: str¶
@@ -688,8 +694,8 @@Models
-
- -apikey: str¶
+- +log_config: Optional[Union[Dict[str, Any], Path]]¶
diff --git a/docs/objects.inv b/docs/objects.inv index af0b746..98d818c 100644 Binary files a/docs/objects.inv and b/docs/objects.inv differ diff --git a/docs/searchindex.js b/docs/searchindex.js index 38c0f88..150f10f 100644 --- a/docs/searchindex.js +++ b/docs/searchindex.js @@ -1 +1 @@ -Search.setIndex({"docnames": ["README", "index"], "filenames": ["README.md", "index.rst"], "titles": ["PyNinja", "Welcome to PyNinja\u2019s documentation!"], "terms": {"lightweight": 0, "o": [0, 1], "agnost": 0, "servic": 0, "monitor": 0, "api": [0, 1], "platform": 0, "support": 0, "deploy": 0, "recommend": 0, "instal": 0, "python": 0, "3": 0, "10": [0, 1], "11": 0, "us": [0, 1], "dedic": 0, "virtual": 0, "m": 0, "pip": 0, "initi": 0, "id": 0, "import": 0, "__name__": 0, "__main__": 0, "start": [0, 1], "cli": 0, "help": 0, "usag": [0, 1], "instruct": 0, "sourc": 0, "from": [0, 1], "an": [0, 1], "env": [0, 1], "file": [0, 1], "By": 0, "default": 0, "look": 0, "current": 0, "work": 0, "directori": 0, "ninja": 0, "_": 0, "host": [0, 1], "hostnam": [0, 1], "server": [0, 1], "port": [0, 1], "number": [0, 1], "worker": [0, 1], "uvicorn": [0, 1], "remot": [0, 1], "execut": [0, 1], "boolean": [0, 1], "flag": [0, 1], "enabl": [0, 1], "secret": [0, 1], "access": [0, 1], "kei": [0, 1], "run": [0, 1], "command": [0, 1], "databas": 0, "filepath": [0, 1], "store": [0, 1], "auth": [0, 1], "handl": [0, 1], "authent": 0, "error": [0, 1], "rate": [0, 1], "limit": [0, 1], "list": [0, 1], "dictionari": [0, 1], "max_request": [0, 1], "second": [0, 1], "appli": [0, 1], "apikei": [0, 1], "can": 0, "extrem": 0, "riski": 0, "major": 0, "secur": [0, 1], "threat": 0, "so": 0, "caution": 0, "set": [0, 1], "strong": [0, 1], "valu": [0, 1], "log": 0, "ini": 0, "configur": [0, 1], "custom": [0, 1], "just": 0, "place": 0, "refer": [0, 1], "sampl": 0, "exampl": 0, "docstr": 0, "format": 0, "googl": 0, "style": 0, "convent": 0, "pep": 0, "8": 0, "isort": 0, "requir": [0, 1], "gitvers": 0, "revers": 0, "f": 0, "release_not": 0, "rst": 0, "t": 0, "pre": 0, "commit": 0, "ensur": 0, "pytest": 0, "gener": [0, 1], "valid": [0, 1], "hyperlink": 0, "all": [0, 1], "markdown": 0, "includ": 0, "wiki": 0, "page": [0, 1], "sphinx": 0, "5": 0, "1": [0, 1], "recommonmark": 0, "http": 0, "org": 0, "project": 0, "thevickypedia": 0, "github": 0, "io": 0, "vignesh": 0, "rao": 0, "under": 0, "mit": 0, "kick": 1, "off": 1, "environ": 1, "variabl": 1, "code": 1, "standard": 1, "releas": 1, "note": 1, "lint": 1, "pypi": 1, "packag": 1, "runbook": 1, "licens": 1, "copyright": 1, "kwarg": 1, "none": 1, "starter": 1, "function": 1, "which": 1, "trigger": 1, "keyword": 1, "argument": 1, "env_fil": 1, "load": 1, "ninja_host": 1, "ninja_port": 1, "remote_execut": 1, "api_secret": 1, "rate_limit": 1, "epoch": 1, "async": 1, "forbidden": 1, "request": 1, "i": 1, "part": 1, "paramet": 1, "fastapi": 1, "object": 1, "rais": 1, "apirespons": 1, "403": 1, "If": 1, "address": 1, "level_1": 1, "httpauthorizationcredenti": 1, "httpbearer": 1, "take": 1, "author": 1, "header": 1, "token": 1, "basic": 1, "rout": 1, "401": 1, "invalid": 1, "level_2": 1, "str": 1, "addition": 1, "addit": 1, "critic": 1, "increment": 1, "attempt": 1, "int": 1, "block": 1, "time": 1, "base": 1, "fail": 1, "return": 1, "appropri": 1, "minut": 1, "type": 1, "handle_auth_error": 1, "filebrows": 1, "The": 1, "incom": 1, "run_command": 1, "payload": 1, "depend": 1, "option": 1, "machin": 1, "arg": 1, "receiv": 1, "bodi": 1, "httpstatu": 1, "statu": 1, "detail": 1, "respons": 1, "process_statu": 1, "process_nam": 1, "cpu_interv": 1, "union": 1, "float": 1, "name": 1, "check": 1, "interv": 1, "get": 1, "cpu": 1, "service_statu": 1, "service_nam": 1, "docker_contain": 1, "container_nam": 1, "get_al": 1, "bool": 1, "fals": 1, "get_run": 1, "contain": 1, "inform": 1, "docker_imag": 1, "imag": 1, "docker_volum": 1, "volum": 1, "doc": 1, "redirectrespons": 1, "redirect": 1, "user": 1, "get_all_rout": 1, "apirout": 1, "ad": 1, "get_container_statu": 1, "string": 1, "get_running_contain": 1, "dict": 1, "yield": 1, "correspond": 1, "metric": 1, "get_all_contain": 1, "stat": 1, "get_all_imag": 1, "get_all_volum": 1, "get_process_statu": 1, "perform": 1, "report": 1, "each": 1, "given": 1, "get_perform": 1, "util": 1, "thread": 1, "open": 1, "pair": 1, "get_service_statu": 1, "servicestatu": 1, "instanc": 1, "get_record": 1, "particular": 1, "until": 1, "when": 1, "should": 1, "put_record": 1, "block_until": 1, "insert": 1, "remove_record": 1, "delet": 1, "record": 1, "relat": 1, "class": 1, "rp": 1, "implement": 1, "init": 1, "call": 1, "exce": 1, "identifi": 1, "429": 1, "too": 1, "mani": 1, "status_cod": 1, "ani": 1, "httpexcept": 1, "wrap": 1, "unsupportedo": 1, "unsupport": 1, "basemodel": 1, "input": 1, "data": 1, "timeout": 1, "descript": 1, "session": 1, "auth_count": 1, "forbid": 1, "info": 1, "allowed_origin": 1, "envconfig": 1, "classmethod": 1, "parse_api_secret": 1, "pars": 1, "complex": 1, "from_env_fil": 1, "path": 1, "creat": 1, "config": 1, "extra": 1, "ignor": 1, "hide_input_in_error": 1, "true": 1, "complexity_check": 1, "verifi": 1, "strength": 1, "A": 1, "consid": 1, "least": 1, "ha": 1, "32": 1, "charact": 1, "digit": 1, "symbol": 1, "uppercas": 1, "letter": 1, "lowercas": 1, "assertionerror": 1, "abov": 1, "condit": 1, "match": 1, "datastor": 1, "connect": 1, "sqlite3": 1, "create_t": 1, "table_nam": 1, "column": 1, "tupl": 1, "process_command": 1, "result": 1, "stdout": 1, "stderr": 1, "env_load": 1, "filenam": 1, "pathlik": 1, "filetyp": 1, "where": 1, "var": 1, "have": 1, "index": 1, "modul": 1, "search": 1}, "objects": {"pyninja": [[1, 0, 0, "-", "auth"], [1, 0, 0, "-", "database"], [1, 0, 0, "-", "dockerized"], [1, 0, 0, "-", "exceptions"], [1, 0, 0, "-", "main"], [1, 0, 0, "-", "models"], [1, 0, 0, "-", "process"], [1, 0, 0, "-", "rate_limit"], [1, 0, 0, "-", "routers"], [1, 0, 0, "-", "service"], [1, 0, 0, "-", "squire"]], "pyninja.auth": [[1, 1, 1, "", "EPOCH"], [1, 1, 1, "", "forbidden"], [1, 1, 1, "", "handle_auth_error"], [1, 1, 1, "", "incrementer"], [1, 1, 1, "", "level_1"], [1, 1, 1, "", "level_2"]], "pyninja.database": [[1, 1, 1, "", "get_record"], [1, 1, 1, "", "put_record"], [1, 1, 1, "", "remove_record"]], "pyninja.dockerized": [[1, 1, 1, "", "get_all_containers"], [1, 1, 1, "", "get_all_images"], [1, 1, 1, "", "get_all_volumes"], [1, 1, 1, "", "get_container_status"], [1, 1, 1, "", "get_running_containers"]], "pyninja.exceptions": [[1, 2, 1, "", "APIResponse"], [1, 2, 1, "", "UnSupportedOS"]], "pyninja.main": [[1, 1, 1, "", "start"]], "pyninja.models": [[1, 3, 1, "", "Database"], [1, 3, 1, "", "EnvConfig"], [1, 3, 1, "", "Payload"], [1, 3, 1, "", "RateLimit"], [1, 3, 1, "", "ServiceStatus"], [1, 3, 1, "", "Session"], [1, 1, 1, "", "complexity_checker"]], "pyninja.models.Database": [[1, 4, 1, "", "create_table"]], "pyninja.models.EnvConfig": [[1, 3, 1, "", "Config"], [1, 5, 1, "", "api_secret"], [1, 5, 1, "", "apikey"], [1, 5, 1, "", "database"], [1, 4, 1, "", "from_env_file"], [1, 5, 1, "", "ninja_host"], [1, 5, 1, "", "ninja_port"], [1, 4, 1, "", "parse_api_secret"], [1, 5, 1, "", "rate_limit"], [1, 5, 1, "", "remote_execution"], [1, 5, 1, "", "workers"]], "pyninja.models.EnvConfig.Config": [[1, 5, 1, "", "extra"], [1, 5, 1, "", "hide_input_in_errors"]], "pyninja.models.Payload": [[1, 5, 1, "", "command"], [1, 5, 1, "", "timeout"]], "pyninja.models.RateLimit": [[1, 5, 1, "", "max_requests"], [1, 5, 1, "", "seconds"]], "pyninja.models.ServiceStatus": [[1, 5, 1, "", "description"], [1, 5, 1, "", "status_code"]], "pyninja.models.Session": [[1, 5, 1, "", "allowed_origins"], [1, 5, 1, "", "auth_counter"], [1, 5, 1, "", "forbid"], [1, 5, 1, "", "info"], [1, 5, 1, "", "rps"]], "pyninja.process": [[1, 1, 1, "", "get_performance"], [1, 1, 1, "", "get_process_status"]], "pyninja.rate_limit": [[1, 3, 1, "", "RateLimiter"]], "pyninja.rate_limit.RateLimiter": [[1, 4, 1, "", "init"]], "pyninja.routers": [[1, 1, 1, "", "docker_containers"], [1, 1, 1, "", "docker_images"], [1, 1, 1, "", "docker_volumes"], [1, 1, 1, "", "docs"], [1, 1, 1, "", "get_all_routes"], [1, 1, 1, "", "process_status"], [1, 1, 1, "", "run_command"], [1, 1, 1, "", "service_status"]], "pyninja.service": [[1, 1, 1, "", "get_service_status"]], "pyninja.squire": [[1, 1, 1, "", "env_loader"], [1, 1, 1, "", "process_command"]]}, "objtypes": {"0": "py:module", "1": "py:function", "2": "py:exception", "3": "py:class", "4": "py:method", "5": "py:attribute"}, "objnames": {"0": ["py", "module", "Python module"], "1": ["py", "function", "Python function"], "2": ["py", "exception", "Python exception"], "3": ["py", "class", "Python class"], "4": ["py", "method", "Python method"], "5": ["py", "attribute", "Python attribute"]}, "titleterms": {"pyninja": [0, 1], "kick": 0, "off": 0, "environ": 0, "variabl": 0, "code": 0, "standard": 0, "releas": 0, "note": 0, "lint": 0, "pypi": 0, "packag": 0, "runbook": 0, "licens": 0, "copyright": 0, "welcom": 1, "": 1, "document": 1, "content": 1, "main": 1, "authent": 1, "router": 1, "monitor": 1, "docker": 1, "process": 1, "servic": 1, "databas": 1, "ratelimit": 1, "except": 1, "model": 1, "squir": 1, "indic": 1, "tabl": 1}, "envversion": {"sphinx.domains.c": 2, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 6, "sphinx.domains.index": 1, "sphinx.domains.javascript": 2, "sphinx.domains.math": 2, "sphinx.domains.python": 3, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx": 56}}) \ No newline at end of file +Search.setIndex({"docnames": ["README", "index"], "filenames": ["README.md", "index.rst"], "titles": ["PyNinja", "Welcome to PyNinja\u2019s documentation!"], "terms": {"lightweight": 0, "o": [0, 1], "agnost": 0, "servic": 0, "monitor": 0, "api": [0, 1], "platform": 0, "support": [0, 1], "deploy": 0, "recommend": 0, "instal": 0, "python": 0, "3": 0, "10": [0, 1], "11": 0, "us": [0, 1], "dedic": 0, "virtual": 0, "m": 0, "pip": 0, "initi": 0, "id": 0, "import": 0, "__name__": 0, "__main__": 0, "start": [0, 1], "cli": 0, "help": 0, "usag": [0, 1], "instruct": 0, "sourc": 0, "from": [0, 1], "an": [0, 1], "env": [0, 1], "file": [0, 1], "By": 0, "default": 0, "look": 0, "current": 0, "work": 0, "directori": 0, "ninja": 0, "_": 0, "host": [0, 1], "hostnam": [0, 1], "server": [0, 1], "port": [0, 1], "number": [0, 1], "worker": [0, 1], "uvicorn": [0, 1], "remot": [0, 1], "execut": [0, 1], "boolean": [0, 1], "flag": [0, 1], "enabl": [0, 1], "secret": [0, 1], "access": [0, 1], "kei": [0, 1], "run": [0, 1], "command": [0, 1], "databas": 0, "filepath": [0, 1], "store": [0, 1], "auth": [0, 1], "handl": [0, 1], "authent": 0, "error": [0, 1], "rate": [0, 1], "limit": [0, 1], "list": [0, 1], "dictionari": [0, 1], "max_request": [0, 1], "second": [0, 1], "appli": [0, 1], "apikei": [0, 1], "can": 0, "extrem": 0, "riski": 0, "major": 0, "secur": [0, 1], "threat": 0, "so": 0, "caution": 0, "set": [0, 1], "strong": [0, 1], "valu": [0, 1], "refer": [0, 1], "sampl": 0, "exampl": 0, "docstr": 0, "format": [0, 1], "googl": 0, "style": 0, "convent": 0, "pep": 0, "8": 0, "isort": 0, "requir": [0, 1], "gitvers": 0, "revers": 0, "f": 0, "release_not": 0, "rst": 0, "t": 0, "pre": 0, "commit": 0, "ensur": 0, "pytest": 0, "gener": [0, 1], "valid": [0, 1], "hyperlink": 0, "all": [0, 1], "markdown": 0, "includ": 0, "wiki": 0, "page": [0, 1], "sphinx": 0, "5": 0, "1": [0, 1], "recommonmark": 0, "http": 0, "org": 0, "project": 0, "thevickypedia": 0, "github": 0, "io": 0, "vignesh": 0, "rao": 0, "under": 0, "mit": 0, "kick": 1, "off": 1, "environ": 1, "variabl": 1, "code": 1, "standard": 1, "releas": 1, "note": 1, "lint": 1, "pypi": 1, "packag": 1, "runbook": 1, "licens": 1, "copyright": 1, "kwarg": 1, "none": 1, "starter": 1, "function": 1, "which": 1, "trigger": 1, "keyword": 1, "argument": 1, "env_fil": 1, "load": 1, "ninja_host": 1, "ninja_port": 1, "remote_execut": 1, "api_secret": 1, "rate_limit": 1, "log_config": 1, "log": 1, "configur": 1, "dict": 1, "yaml": 1, "yml": 1, "json": 1, "ini": 1, "epoch": 1, "async": 1, "forbidden": 1, "request": 1, "i": 1, "part": 1, "paramet": 1, "fastapi": 1, "object": 1, "rais": 1, "apirespons": 1, "403": 1, "If": 1, "address": 1, "level_1": 1, "httpauthorizationcredenti": 1, "httpbearer": 1, "take": 1, "author": 1, "header": 1, "token": 1, "basic": 1, "rout": 1, "401": 1, "invalid": 1, "level_2": 1, "str": 1, "addition": 1, "addit": 1, "critic": 1, "increment": 1, "attempt": 1, "int": 1, "block": 1, "time": 1, "base": 1, "fail": 1, "return": 1, "appropri": 1, "minut": 1, "type": 1, "handle_auth_error": 1, "filebrows": 1, "The": 1, "incom": 1, "run_command": 1, "payload": 1, "depend": 1, "option": 1, "machin": 1, "arg": 1, "receiv": 1, "bodi": 1, "httpstatu": 1, "statu": 1, "detail": 1, "respons": 1, "process_statu": 1, "process_nam": 1, "cpu_interv": 1, "union": 1, "float": 1, "name": 1, "check": 1, "interv": 1, "get": 1, "cpu": 1, "service_statu": 1, "service_nam": 1, "docker_contain": 1, "container_nam": 1, "get_al": 1, "bool": 1, "fals": 1, "get_run": 1, "contain": 1, "inform": 1, "docker_imag": 1, "imag": 1, "docker_volum": 1, "volum": 1, "doc": 1, "redirectrespons": 1, "redirect": 1, "user": 1, "get_all_rout": 1, "apirout": 1, "ad": 1, "get_container_statu": 1, "string": 1, "get_running_contain": 1, "yield": 1, "correspond": 1, "metric": 1, "get_all_contain": 1, "stat": 1, "get_all_imag": 1, "get_all_volum": 1, "get_process_statu": 1, "perform": 1, "report": 1, "each": 1, "given": 1, "get_perform": 1, "util": 1, "thread": 1, "open": 1, "pair": 1, "get_service_statu": 1, "servicestatu": 1, "instanc": 1, "get_record": 1, "particular": 1, "until": 1, "when": 1, "should": 1, "put_record": 1, "block_until": 1, "insert": 1, "remove_record": 1, "delet": 1, "record": 1, "relat": 1, "class": 1, "rp": 1, "implement": 1, "init": 1, "call": 1, "exce": 1, "identifi": 1, "429": 1, "too": 1, "mani": 1, "status_cod": 1, "ani": 1, "custom": 1, "httpexcept": 1, "wrap": 1, "unsupportedo": 1, "unsupport": 1, "basemodel": 1, "input": 1, "data": 1, "timeout": 1, "descript": 1, "session": 1, "auth_count": 1, "forbid": 1, "info": 1, "allowed_origin": 1, "envconfig": 1, "path": 1, "classmethod": 1, "parse_api_secret": 1, "pars": 1, "complex": 1, "from_env_fil": 1, "creat": 1, "config": 1, "extra": 1, "ignor": 1, "hide_input_in_error": 1, "true": 1, "complexity_check": 1, "verifi": 1, "strength": 1, "A": 1, "consid": 1, "least": 1, "ha": 1, "32": 1, "charact": 1, "digit": 1, "symbol": 1, "uppercas": 1, "letter": 1, "lowercas": 1, "assertionerror": 1, "abov": 1, "condit": 1, "match": 1, "datastor": 1, "connect": 1, "sqlite3": 1, "create_t": 1, "table_nam": 1, "column": 1, "tupl": 1, "process_command": 1, "result": 1, "stdout": 1, "stderr": 1, "env_load": 1, "filenam": 1, "pathlik": 1, "filetyp": 1, "where": 1, "var": 1, "have": 1, "index": 1, "modul": 1, "search": 1}, "objects": {"pyninja": [[1, 0, 0, "-", "auth"], [1, 0, 0, "-", "database"], [1, 0, 0, "-", "dockerized"], [1, 0, 0, "-", "exceptions"], [1, 0, 0, "-", "main"], [1, 0, 0, "-", "models"], [1, 0, 0, "-", "process"], [1, 0, 0, "-", "rate_limit"], [1, 0, 0, "-", "routers"], [1, 0, 0, "-", "service"], [1, 0, 0, "-", "squire"]], "pyninja.auth": [[1, 1, 1, "", "EPOCH"], [1, 1, 1, "", "forbidden"], [1, 1, 1, "", "handle_auth_error"], [1, 1, 1, "", "incrementer"], [1, 1, 1, "", "level_1"], [1, 1, 1, "", "level_2"]], "pyninja.database": [[1, 1, 1, "", "get_record"], [1, 1, 1, "", "put_record"], [1, 1, 1, "", "remove_record"]], "pyninja.dockerized": [[1, 1, 1, "", "get_all_containers"], [1, 1, 1, "", "get_all_images"], [1, 1, 1, "", "get_all_volumes"], [1, 1, 1, "", "get_container_status"], [1, 1, 1, "", "get_running_containers"]], "pyninja.exceptions": [[1, 2, 1, "", "APIResponse"], [1, 2, 1, "", "UnSupportedOS"]], "pyninja.main": [[1, 1, 1, "", "start"]], "pyninja.models": [[1, 3, 1, "", "Database"], [1, 3, 1, "", "EnvConfig"], [1, 3, 1, "", "Payload"], [1, 3, 1, "", "RateLimit"], [1, 3, 1, "", "ServiceStatus"], [1, 3, 1, "", "Session"], [1, 1, 1, "", "complexity_checker"]], "pyninja.models.Database": [[1, 4, 1, "", "create_table"]], "pyninja.models.EnvConfig": [[1, 3, 1, "", "Config"], [1, 5, 1, "", "api_secret"], [1, 5, 1, "", "apikey"], [1, 5, 1, "", "database"], [1, 4, 1, "", "from_env_file"], [1, 5, 1, "", "log_config"], [1, 5, 1, "", "ninja_host"], [1, 5, 1, "", "ninja_port"], [1, 4, 1, "", "parse_api_secret"], [1, 5, 1, "", "rate_limit"], [1, 5, 1, "", "remote_execution"], [1, 5, 1, "", "workers"]], "pyninja.models.EnvConfig.Config": [[1, 5, 1, "", "extra"], [1, 5, 1, "", "hide_input_in_errors"]], "pyninja.models.Payload": [[1, 5, 1, "", "command"], [1, 5, 1, "", "timeout"]], "pyninja.models.RateLimit": [[1, 5, 1, "", "max_requests"], [1, 5, 1, "", "seconds"]], "pyninja.models.ServiceStatus": [[1, 5, 1, "", "description"], [1, 5, 1, "", "status_code"]], "pyninja.models.Session": [[1, 5, 1, "", "allowed_origins"], [1, 5, 1, "", "auth_counter"], [1, 5, 1, "", "forbid"], [1, 5, 1, "", "info"], [1, 5, 1, "", "rps"]], "pyninja.process": [[1, 1, 1, "", "get_performance"], [1, 1, 1, "", "get_process_status"]], "pyninja.rate_limit": [[1, 3, 1, "", "RateLimiter"]], "pyninja.rate_limit.RateLimiter": [[1, 4, 1, "", "init"]], "pyninja.routers": [[1, 1, 1, "", "docker_containers"], [1, 1, 1, "", "docker_images"], [1, 1, 1, "", "docker_volumes"], [1, 1, 1, "", "docs"], [1, 1, 1, "", "get_all_routes"], [1, 1, 1, "", "process_status"], [1, 1, 1, "", "run_command"], [1, 1, 1, "", "service_status"]], "pyninja.service": [[1, 1, 1, "", "get_service_status"]], "pyninja.squire": [[1, 1, 1, "", "env_loader"], [1, 1, 1, "", "process_command"]]}, "objtypes": {"0": "py:module", "1": "py:function", "2": "py:exception", "3": "py:class", "4": "py:method", "5": "py:attribute"}, "objnames": {"0": ["py", "module", "Python module"], "1": ["py", "function", "Python function"], "2": ["py", "exception", "Python exception"], "3": ["py", "class", "Python class"], "4": ["py", "method", "Python method"], "5": ["py", "attribute", "Python attribute"]}, "titleterms": {"pyninja": [0, 1], "kick": 0, "off": 0, "environ": 0, "variabl": 0, "code": 0, "standard": 0, "releas": 0, "note": 0, "lint": 0, "pypi": 0, "packag": 0, "runbook": 0, "licens": 0, "copyright": 0, "welcom": 1, "": 1, "document": 1, "content": 1, "main": 1, "authent": 1, "router": 1, "monitor": 1, "docker": 1, "process": 1, "servic": 1, "databas": 1, "ratelimit": 1, "except": 1, "model": 1, "squir": 1, "indic": 1, "tabl": 1}, "envversion": {"sphinx.domains.c": 2, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 6, "sphinx.domains.index": 1, "sphinx.domains.javascript": 2, "sphinx.domains.math": 2, "sphinx.domains.python": 3, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx": 56}}) \ No newline at end of file diff --git a/pyninja/main.py b/pyninja/main.py index 0aacf67..6df7095 100644 --- a/pyninja/main.py +++ b/pyninja/main.py @@ -15,6 +15,7 @@ def start(**kwargs) -> None: Keyword Args: env_file: Env filepath to load the environment variables. + apikey: API Key for authentication. ninja_host: Hostname for the API server. ninja_port: Port number for the API server. workers: Number of workers for the uvicorn server. @@ -22,7 +23,7 @@ def start(**kwargs) -> None: api_secret: Secret access key for running commands on server remotely. database: FilePath to store the auth database that handles the authentication errors. rate_limit: List of dictionaries with ``max_requests`` and ``seconds`` to apply as rate limit. - apikey: API Key for authentication. + log_config: Logging configuration as a dict or a FilePath. Supports .yaml/.yml, .json or .ini formats. """ if env_file := kwargs.get("env_file"): models.env = squire.env_loader(env_file) @@ -46,8 +47,7 @@ def start(**kwargs) -> None: host=models.env.ninja_host, port=models.env.ninja_port, workers=models.env.workers, + log_config=models.env.log_config, app=app, ) - if os.path.isfile("logging.ini"): - kwargs["log_config"] = os.path.join(os.getcwd(), "logging.ini") uvicorn.run(**kwargs) diff --git a/pyninja/models.py b/pyninja/models.py index be040dc..2ed2cea 100644 --- a/pyninja/models.py +++ b/pyninja/models.py @@ -2,7 +2,7 @@ import re import socket import sqlite3 -from typing import Dict, List, Set, Tuple +from typing import Any, Dict, List, Set, Tuple from pydantic import BaseModel, Field, FilePath, PositiveInt, field_validator from pydantic_settings import BaseSettings @@ -100,6 +100,7 @@ class EnvConfig(BaseSettings): """ + apikey: str ninja_host: str = socket.gethostbyname("localhost") or "0.0.0.0" ninja_port: PositiveInt = 8000 workers: PositiveInt = 1 @@ -107,7 +108,7 @@ class EnvConfig(BaseSettings): api_secret: str | None = None database: str = Field("auth.db", pattern=".*.db$") rate_limit: RateLimit | List[RateLimit] = [] - apikey: str + log_config: Dict[str, Any] | FilePath | None = None # noinspection PyMethodParameters @field_validator("api_secret", mode="after") diff --git a/samples/log_config.yml b/samples/log_config.yml new file mode 100644 index 0000000..a571ac4 --- /dev/null +++ b/samples/log_config.yml @@ -0,0 +1,45 @@ +#### This is a sample logging configuration for the API. #### +version: 1 +disable_existing_loggers: True +formatters: + default: + (): 'uvicorn.logging.DefaultFormatter' + fmt: '%(asctime)s %(levelprefix)-9s %(name)s -: %(message)s' + use_colors: False + access: + (): 'uvicorn.logging.AccessFormatter' + fmt: '%(asctime)s %(levelprefix)-9s %(name)s -: %(client_addr)s - "%(request_line)s" %(status_code)s' + use_colors: False + error: + (): 'uvicorn.logging.DefaultFormatter' + fmt: '%(asctime)s %(levelprefix)-9s %(name)s -: %(message)s' + use_colors: False +handlers: + default: + class: logging.FileHandler # Can be changed to StreamHandler for stdout logging + formatter: default + filename: default.log + access: + class: logging.FileHandler # Can be changed to StreamHandler for stdout logging + formatter: access + filename: access.log + error: + class: logging.FileHandler # Can be changed to StreamHandler for stdout logging + formatter: error + filename: default.log +loggers: + uvicorn: + propagate: True + level: INFO + handlers: + - default + uvicorn.error: + propagate: True + level: INFO + handlers: + - error + uvicorn.access: + propagate: True + level: INFO + handlers: + - access