Skip to content

Commit 8d32690

Browse files
committed
Refactor: renaming class / change folder struct
1 parent 0844f9a commit 8d32690

File tree

13 files changed

+62
-103
lines changed

13 files changed

+62
-103
lines changed

src/aleph/sdk/chains/remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def from_crypto_host(
5252
session = aiohttp.ClientSession(connector=connector)
5353

5454
async with session.get(f"{host}/properties") as response:
55-
await response.raise_for_status()
55+
response.raise_for_status()
5656
data = await response.json()
5757
properties = AccountProperties(**data)
5858

@@ -75,7 +75,7 @@ def private_key(self):
7575
async def sign_message(self, message: Dict) -> Dict:
7676
"""Sign a message inplace."""
7777
async with self._session.post(f"{self._host}/sign", json=message) as response:
78-
await response.raise_for_status()
78+
response.raise_for_status()
7979
return await response.json()
8080

8181
async def sign_raw(self, buffer: bytes) -> bytes:

src/aleph/sdk/client/authenticated_http.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,6 @@
5151

5252
class AuthenticatedAlephHttpClient(AlephHttpClient, AuthenticatedAlephClient):
5353
account: Account
54-
_registered_authenticated_services: Dict[str, Tuple[Type, Dict[str, Any]]] = {}
55-
56-
@classmethod
57-
def register_authenticated_service(
58-
cls, name: str, service_class: Type, **kwargs
59-
) -> None:
60-
"""
61-
Register an authenticated service to be instantiated when the authenticated client is entered.
62-
This is used for services that require an account.
63-
64-
:param name: The attribute name to use for the service
65-
:param service_class: The class to instantiate
66-
:param kwargs: Additional kwargs to pass to the service constructor
67-
"""
68-
cls._registered_authenticated_services[name] = (service_class, kwargs)
6954

7055
BROADCAST_MESSAGE_FIELDS = {
7156
"sender",
@@ -102,13 +87,6 @@ async def __aenter__(self):
10287
# Override services with authenticated versions
10388
self.port_forwarder = AuthenticatedPortForwarder(self)
10489

105-
# Initialize registered authenticated services
106-
for name, (
107-
service_class,
108-
kwargs,
109-
) in self.__class__._registered_authenticated_services.items():
110-
setattr(self, name, service_class(self, **kwargs))
111-
11290
return self
11391

11492
async def ipfs_push(self, content: Mapping) -> str:

src/aleph/sdk/client/http.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
from aleph_message.status import MessageStatus
3434
from pydantic import ValidationError
3535

36+
from aleph.sdk.client.services.crn import Crn
37+
from aleph.sdk.client.services.dns import DNS
38+
from aleph.sdk.client.services.instance import Instance
39+
from aleph.sdk.client.services.port_forwarder import PortForwarder
40+
from aleph.sdk.client.services.scheduler import Scheduler
41+
3642
from ..conf import settings
3743
from ..exceptions import (
3844
FileTooLarge,
@@ -55,30 +61,13 @@
5561
safe_getattr,
5662
)
5763
from .abstract import AlephClient
58-
from .service.crn.http_crn import CrnService
59-
from .service.dns.http_dns import DNSService
60-
from .service.port_forwarder.http_port_forwarder import PortForwarder
61-
from .service.scheduler.http_scheduler import SchedulerService
62-
from .service.utils.http_utils import UtilsService
6364

6465
logger = logging.getLogger(__name__)
6566

6667

6768
class AlephHttpClient(AlephClient):
6869
api_server: str
6970
_http_session: Optional[aiohttp.ClientSession]
70-
_registered_services: Dict[str, Tuple[Type, Dict[str, Any]]] = {}
71-
72-
@classmethod
73-
def register_service(cls, name: str, service_class: Type, **kwargs) -> None:
74-
"""
75-
Register a service to be instantiated when the client is entered.
76-
77-
:param name: The attribute name to use for the service
78-
:param service_class: The class to instantiate
79-
:param kwargs: Additional kwargs to pass to the service constructor
80-
"""
81-
cls._registered_services[name] = (service_class, kwargs)
8271

8372
def __init__(
8473
self,
@@ -141,18 +130,11 @@ async def __aenter__(self):
141130
)
142131

143132
# Initialize default services
144-
self.dns = DNSService(self)
133+
self.dns = DNS(self)
145134
self.port_forwarder = PortForwarder(self)
146-
self.crn = CrnService(self)
147-
self.scheduler = SchedulerService(self)
148-
self.utils = UtilsService(self)
149-
150-
# Initialize registered services
151-
for name, (
152-
service_class,
153-
kwargs,
154-
) in self.__class__._registered_services.items():
155-
setattr(self, name, service_class(self, **kwargs))
135+
self.crn = Crn(self)
136+
self.scheduler = Scheduler(self)
137+
self.instance = Instance(self)
156138

157139
return self
158140

src/aleph/sdk/client/service/port_forwarder/authenticated_port_forwarder.py renamed to src/aleph/sdk/client/services/authenticated_port_forwarder.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
from aleph_message.models import AggregateMessage, ItemHash
44
from aleph_message.status import MessageStatus
55

6-
from aleph.sdk.client.service.base import AggregateConfig
6+
from aleph.sdk.client.services.base import AggregateConfig
7+
from aleph.sdk.client.services.port_forwarder import PortForwarder
78
from aleph.sdk.exceptions import MessageNotProcessed, NotAuthorize
89
from aleph.sdk.types import AllForwarders, Ports
910
from aleph.sdk.utils import safe_getattr
1011

11-
from .http_port_forwarder import PortForwarder
12-
1312
if TYPE_CHECKING:
1413
from aleph.sdk.client.abstract import AuthenticatedAlephClient
1514

1615

1716
class AuthenticatedPortForwarder(PortForwarder):
1817
"""
19-
Authenticated Port Forwarder service with create and update capabilities
18+
Authenticated Port Forwarder services with create and update capabilities
2019
"""
2120

2221
def __init__(self, client: "AuthenticatedAlephClient"):
@@ -80,7 +79,7 @@ async def get_ports(
8079
return await super().get_ports(address=address)
8180

8281
async def get_port(
83-
self, address: Optional[str] = None, item_hash: ItemHash = None
82+
self, item_hash: ItemHash = None, address: Optional[str] = None
8483
) -> Optional[Ports]:
8584
"""
8685
Get port forwarding configuration for a specific item hash
@@ -120,7 +119,7 @@ async def create_port(
120119
raise ValueError("An account is required for this operation")
121120

122121
# Pre Check
123-
_, _ = await self._verify_status_processed_and_ownership(item_hash=item_hash)
122+
# _, _ = await self._verify_status_processed_and_ownership(item_hash=item_hash)
124123

125124
content = {str(item_hash): ports.model_dump()}
126125

@@ -146,7 +145,7 @@ async def update_port(
146145
raise ValueError("An account is required for this operation")
147146

148147
# Pre Check
149-
_, _ = await self._verify_status_processed_and_ownership(item_hash=item_hash)
148+
# _, _ = await self._verify_status_processed_and_ownership(item_hash=item_hash)
150149

151150
content = {}
152151

@@ -174,7 +173,7 @@ async def delete_ports(
174173
raise ValueError("An account is required for this operation")
175174

176175
# Pre Check
177-
_, _ = await self._verify_status_processed_and_ownership(item_hash=item_hash)
176+
# _, _ = await self._verify_status_processed_and_ownership(item_hash=item_hash)
178177

179178
# Get the Port Config of the item_hash
180179
port: Optional[Ports] = await self.get_port(item_hash=item_hash)

src/aleph/sdk/client/service/crn/http_crn.py renamed to src/aleph/sdk/client/services/crn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
from aleph.sdk.client.http import AlephHttpClient
1414

1515

16-
class CrnService:
16+
class Crn:
1717
"""
18-
This service allow interact with CRNS API
18+
This services allow interact with CRNS API
1919
TODO: ADD
2020
/about/executions/details
2121
/about/executions/records

src/aleph/sdk/client/service/dns/http_dns.py renamed to src/aleph/sdk/client/services/dns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from aleph.sdk.client.http import AlephHttpClient
1212

1313

14-
class DNSService:
14+
class DNS:
1515
"""
1616
This Service mostly made to get active dns for instance:
1717
`https://api.dns.public.aleph.sh/instances/list`

src/aleph/sdk/client/service/utils/http_utils.py renamed to src/aleph/sdk/client/services/instance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from aleph.sdk.utils import safe_getattr, sanitize_url
2222

2323

24-
class UtilsService:
24+
class Instance:
2525
"""
2626
This is utils functions that used multiple Service
2727
exemple getting info about Allocations / exeuction of any instances (hold or not)

src/aleph/sdk/client/service/port_forwarder/http_port_forwarder.py renamed to src/aleph/sdk/client/services/port_forwarder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from aleph_message.models import ItemHash
44

5-
from aleph.sdk.client.service.base import AggregateConfig, BaseService
5+
from aleph.sdk.client.services.base import AggregateConfig, BaseService
66
from aleph.sdk.types import AllForwarders, Ports
77

88
if TYPE_CHECKING:
@@ -24,7 +24,7 @@ async def get_ports(self, address: str) -> AggregateConfig[AllForwarders]:
2424
result = await self.get_config(address=address)
2525
return result
2626

27-
async def get_port(self, address: str, item_hash: ItemHash) -> Optional[Ports]:
27+
async def get_port(self, item_hash: ItemHash, address: str) -> Optional[Ports]:
2828
"""
2929
Get Ports Forwarder of Instance / Program / IPFS website from aggregate
3030
"""

src/aleph/sdk/client/service/scheduler/http_scheduler.py renamed to src/aleph/sdk/client/services/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from aleph.sdk.client.http import AlephHttpClient
1212

1313

14-
class SchedulerService:
14+
class Scheduler:
1515
"""
1616
This Service is made to interact with scheduler API:
1717
`https://scheduler.api.aleph.cloud/`

tests/unit/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ async def __aenter__(self):
166166

167167
async def __aexit__(self, exc_type, exc_val, exc_tb): ...
168168

169-
async def raise_for_status(self): ...
169+
def raise_for_status(self): ...
170170

171171
@property
172172
def status(self):

0 commit comments

Comments
 (0)