Skip to content

Commit e233cd4

Browse files
committed
http: api: blueprints: implement get
1 parent 42be5bc commit e233cd4

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/enapter/cli/http/api/blueprint_command.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from enapter import cli
44

55
from .blueprint_download_command import BlueprintDownloadCommand
6+
from .blueprint_get_command import BlueprintGetCommand
67
from .blueprint_upload_command import BlueprintUploadCommand
78
from .blueprint_validate_command import BlueprintValidateCommand
89

@@ -17,6 +18,7 @@ def register(parent: cli.Subparsers) -> None:
1718
subparsers = parser.add_subparsers(dest="blueprint_command", required=True)
1819
for command in [
1920
BlueprintDownloadCommand,
21+
BlueprintGetCommand,
2022
BlueprintUploadCommand,
2123
BlueprintValidateCommand,
2224
]:
@@ -27,6 +29,8 @@ async def run(args: argparse.Namespace) -> None:
2729
match args.blueprint_command:
2830
case "download":
2931
await BlueprintDownloadCommand.run(args)
32+
case "get":
33+
await BlueprintGetCommand.run(args)
3034
case "upload":
3135
await BlueprintUploadCommand.run(args)
3236
case "validate":
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import argparse
2+
import json
3+
import logging
4+
5+
from enapter import cli, http
6+
7+
LOGGER = logging.getLogger(__name__)
8+
9+
10+
class BlueprintGetCommand(cli.Command):
11+
12+
@staticmethod
13+
def register(parent: cli.Subparsers) -> None:
14+
parser = parent.add_parser(
15+
"get", formatter_class=argparse.ArgumentDefaultsHelpFormatter
16+
)
17+
parser.add_argument("id", help="ID of the blueprint to get")
18+
19+
@staticmethod
20+
async def run(args: argparse.Namespace) -> None:
21+
async with http.api.Client(http.api.Config.from_env()) as client:
22+
blueprint = await client.blueprints.get(blueprint_id=args.id)
23+
print(json.dumps(blueprint.to_dto()))

src/enapter/http/api/blueprints/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ class Client:
1414
def __init__(self, client: httpx.AsyncClient) -> None:
1515
self._client = client
1616

17+
async def get(self, blueprint_id: str) -> Blueprint:
18+
url = f"v3/blueprints/{blueprint_id}"
19+
response = await self._client.get(url)
20+
api.check_error(response)
21+
return Blueprint.from_dto(response.json()["blueprint"])
22+
1723
async def upload_file(self, path: pathlib.Path) -> Blueprint:
1824
with path.open("rb") as file:
1925
data = file.read()

0 commit comments

Comments
 (0)