Skip to content

Commit

Permalink
Add a new feature to handle fileIO
Browse files Browse the repository at this point in the history
Restructure codebase
  • Loading branch information
dormant-user committed Oct 27, 2024
1 parent 89ff685 commit 9e14235
Show file tree
Hide file tree
Showing 19 changed files with 1,389 additions and 784 deletions.
46 changes: 41 additions & 5 deletions doc_gen/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,27 @@ Database

API Routes
----------
.. automodule:: pyninja.executors.routes
.. automodule:: pyninja.routes.fullaccess

====

.. automodule:: pyninja.routes.ipaddr

====

.. automodule:: pyninja.routes.metrics

====

.. automodule:: pyninja.routes.namespace

====

.. automodule:: pyninja.routes.orchestration

====

.. automodule:: pyninja.executors.routers

Squire
------
Expand Down Expand Up @@ -76,10 +96,6 @@ Exceptions

Models
------
.. autoclass:: pyninja.modules.models.Payload(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

====

.. autoclass:: pyninja.modules.models.ServiceStatus(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields
Expand Down Expand Up @@ -119,6 +135,26 @@ Models
.. automodule:: pyninja.modules.models
:exclude-members: Payload, ServiceStatus, DiskLib, ServiceLib, ProcessorLib, EnvConfig, Session, RateLimit, env, database

Payloads
--------
.. autoclass:: pyninja.modules.payloads.RunCommand(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

====

.. autoclass:: pyninja.modules.payloads.ListFiles(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

====

.. autoclass:: pyninja.modules.payloads.GetFile(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

====

.. autoclass:: pyninja.modules.payloads.PutFile(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

RateLimit
---------
.. automodule:: pyninja.modules.rate_limit
Expand Down
46 changes: 41 additions & 5 deletions docs/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,27 @@ Database

API Routes
----------
.. automodule:: pyninja.executors.routes
.. automodule:: pyninja.routes.fullaccess

====

.. automodule:: pyninja.routes.ipaddr

====

.. automodule:: pyninja.routes.metrics

====

.. automodule:: pyninja.routes.namespace

====

.. automodule:: pyninja.routes.orchestration

====

.. automodule:: pyninja.executors.routers

Squire
------
Expand Down Expand Up @@ -76,10 +96,6 @@ Exceptions

Models
------
.. autoclass:: pyninja.modules.models.Payload(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

====

.. autoclass:: pyninja.modules.models.ServiceStatus(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields
Expand Down Expand Up @@ -119,6 +135,26 @@ Models
.. automodule:: pyninja.modules.models
:exclude-members: Payload, ServiceStatus, DiskLib, ServiceLib, ProcessorLib, EnvConfig, Session, RateLimit, env, database

Payloads
--------
.. autoclass:: pyninja.modules.payloads.RunCommand(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

====

.. autoclass:: pyninja.modules.payloads.ListFiles(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

====

.. autoclass:: pyninja.modules.payloads.GetFile(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

====

.. autoclass:: pyninja.modules.payloads.PutFile(BaseModel)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

RateLimit
---------
.. automodule:: pyninja.modules.rate_limit
Expand Down
150 changes: 116 additions & 34 deletions docs/genindex.html

Large diffs are not rendered by default.

317 changes: 225 additions & 92 deletions docs/index.html

Large diffs are not rendered by default.

Binary file modified docs/objects.inv
Binary file not shown.
27 changes: 26 additions & 1 deletion docs/py-modindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h1>Python Module Index</h1>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="index.html#module-pyninja.executors.routes"><code class="xref">pyninja.executors.routes</code></a></td><td>
<a href="index.html#module-pyninja.executors.routers"><code class="xref">pyninja.executors.routers</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
Expand Down Expand Up @@ -158,6 +158,31 @@ <h1>Python Module Index</h1>
<td>&#160;&#160;&#160;
<a href="index.html#module-pyninja.monitor.routes"><code class="xref">pyninja.monitor.routes</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="index.html#module-pyninja.routes.fullaccess"><code class="xref">pyninja.routes.fullaccess</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="index.html#module-pyninja.routes.ipaddr"><code class="xref">pyninja.routes.ipaddr</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="index.html#module-pyninja.routes.metrics"><code class="xref">pyninja.routes.metrics</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="index.html#module-pyninja.routes.namespace"><code class="xref">pyninja.routes.namespace</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="index.html#module-pyninja.routes.orchestration"><code class="xref">pyninja.routes.orchestration</code></a></td><td>
<em></em></td></tr>
</table>


Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

144 changes: 144 additions & 0 deletions pyninja/executors/routers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import logging
from http import HTTPStatus
from typing import List

from fastapi import Depends
from fastapi.responses import RedirectResponse
from fastapi.routing import APIRoute
from fastapi.security import HTTPBasic, HTTPBearer

from pyninja.modules import exceptions
from pyninja.routes import ipaddr, metrics, namespace, orchestration

LOGGER = logging.getLogger("uvicorn.default")
BASIC_AUTH = HTTPBasic()
BEARER_AUTH = HTTPBearer()


async def docs() -> RedirectResponse:
"""Redirect to docs page.
Returns:
RedirectResponse:
Redirects the user to ``/docs`` page.
"""
return RedirectResponse("/docs")


async def health():
"""Health check for PyNinja.
Returns:
APIResponse:
Returns a health check response with status code 200.
"""
raise exceptions.APIResponse(status_code=HTTPStatus.OK, detail=HTTPStatus.OK.phrase)


def get_all_routes(dependencies: List[Depends]) -> List[APIRoute]:
"""Get all the routes to be added for the API server.
Args:
dependencies: List of dependencies to be added to the routes
Returns:
List[APIRoute]:
Returns the routes as a list of APIRoute objects.
"""
routes = [
APIRoute(path="/", endpoint=docs, methods=["GET"], include_in_schema=False),
APIRoute(
path="/health", endpoint=health, methods=["GET"], include_in_schema=False
),
APIRoute(
path="/get-ip",
endpoint=ipaddr.get_ip_address,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/get-cpu",
endpoint=metrics.get_cpu_utilization,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/get-cpu-load",
endpoint=metrics.get_cpu_load_avg,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/get-processor",
endpoint=namespace.get_processor_name,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/get-memory",
endpoint=metrics.get_memory_utilization,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/get-disk",
endpoint=metrics.get_disk_utilization,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/get-all-disks",
endpoint=metrics.get_all_disks,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/service-status",
endpoint=namespace.get_service_status,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/service-usage",
endpoint=namespace.get_service_usage,
methods=["POST"],
dependencies=dependencies,
),
APIRoute(
path="/process-status",
endpoint=namespace.get_process_status,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/process-usage",
endpoint=namespace.get_process_usage,
methods=["POST"],
dependencies=dependencies,
),
APIRoute(
path="/docker-container",
endpoint=orchestration.get_docker_containers,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/docker-image",
endpoint=orchestration.get_docker_images,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/docker-volume",
endpoint=orchestration.get_docker_volumes,
methods=["GET"],
dependencies=dependencies,
),
APIRoute(
path="/docker-stats",
endpoint=orchestration.get_docker_stats,
methods=["GET"],
dependencies=dependencies,
),
]
return routes
Loading

0 comments on commit 9e14235

Please sign in to comment.