Skip to content

Commit

Permalink
ADCM-6156: Implement missing methods for BundleNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Starovoitov committed Nov 29, 2024
1 parent 2d268b1 commit 34cfc74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions adcm_aio_client/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from typing import Self

from adcm_aio_client.core.objects.cm import ADCM, BundlesNode, ClustersNode, HostProvidersNode, HostsAccessor
from adcm_aio_client.core.requesters import DefaultRequester
from adcm_aio_client.core.requesters import Requester
from adcm_aio_client.core.requesters import DefaultRequester, Requester
from adcm_aio_client.core.types import AuthToken, Cert, Credentials, Verify


Expand Down
10 changes: 5 additions & 5 deletions adcm_aio_client/core/objects/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def signature_status(self: Self) -> Literal["invalid", "valid", "absent"]:
def _type(self: Self) -> Literal["cluster", "provider"]:
return self._data["mainPrototype"]["type"]

@property
def license(self: Self) -> License:
return self._construct(what=License, from_data=self._data["mainPrototype"]["license"])

Expand All @@ -88,7 +89,7 @@ class BundlesNode(PaginatedAccessor[Bundle, None]):
async def _download_external_bundle(self: Self, url: str) -> bytes:
try:
urlopen(url) # noqa S310
async with httpx.AsyncClient() as client: # Create an async client
async with httpx.AsyncClient() as client:
response = await client.get(url)
return response.content
except ValueError as err:
Expand All @@ -97,15 +98,14 @@ async def _download_external_bundle(self: Self, url: str) -> bytes:
async def create(self: Self, bundle_loc: str, accept_license: bool | None = None) -> Bundle:
if not Path(bundle_loc).exists():
file_content = await self._download_external_bundle(bundle_loc)
files = {"file": file_content.decode("utf-8")}
files = {"file": file_content}
else:
files = {"file": Path(bundle_loc).read_text(encoding="utf-8")}
files = {"file": Path(bundle_loc).read_bytes()}

response = await self._requester.post("bundles", data=files)

if accept_license:
bundle_license = await (await self.get()).license
bundle_license.accept()
(await self.get()).license.accept()

return Bundle(requester=self._requester, data=response.as_dict())

Expand Down

0 comments on commit 34cfc74

Please sign in to comment.