44
55import typer
66from aleph .sdk .account import _load_account
7- from aleph .sdk .client import AlephClient , AuthenticatedAlephClient
7+ from aleph .sdk .client import AlephHttpClient , AuthenticatedAlephHttpClient
88from aleph .sdk .conf import settings as sdk_settings
9- from aleph .sdk .domain import DomainValidator , Hostname , TargetType , hostname_from_url
9+ from aleph .sdk .domain import (
10+ DomainValidator ,
11+ Hostname ,
12+ TargetType ,
13+ get_target_type ,
14+ hostname_from_url ,
15+ )
1016from aleph .sdk .exceptions import DomainConfigurationError
17+ from aleph .sdk .query .filters import MessageFilter
1118from aleph .sdk .types import AccountFromPrivateKey
1219from aleph_client .commands import help_strings
1320from aleph_client .commands .utils import coro
2027
2128
2229async def get_aggregate_domain_info (account , fqdn ):
23- async with AlephClient (api_server = sdk_settings .API_HOST ) as client :
30+ async with AlephHttpClient (api_server = sdk_settings .API_HOST ) as client :
2431 aggregates = await client .get_messages (
25- addresses = [str (account .get_address ())],
26- message_type = MessageType .aggregate ,
32+ message_filter = MessageFilter (
33+ message_types = [MessageType .aggregate ],
34+ addresses = [str (account .get_address ())],
35+ ),
2736 page = 1 ,
28- pagination = 1000
37+ page_size = 1000
2938 )
3039
3140 for message in aggregates .messages :
@@ -59,20 +68,18 @@ async def detach_resource(account: AccountFromPrivateKey, fqdn: Hostname):
5968 table .add_column ("New resource" , justify = "right" , style = "green" , no_wrap = True )
6069 table .add_column ("Resource type" , style = "magenta" )
6170
62- domain_validator = DomainValidator ()
63-
6471 if domain_info is not None and domain_info .get ("info" ):
6572 current_resource = domain_info ["info" ]["message_id" ]
6673
67- resource_type = await domain_validator . get_target_type (fqdn )
74+ resource_type = await get_target_type (fqdn )
6875 table .add_row (f"{ current_resource [:16 ]} ...{ current_resource [- 16 :]} " , "" , resource_type )
6976
7077 console .print (table )
7178
7279 if Confirm .ask ("Continue" ):
7380 """Update aggregate message"""
7481
75- async with AuthenticatedAlephClient (
82+ async with AuthenticatedAlephHttpClient (
7683 account = account , api_server = sdk_settings .API_HOST
7784 ) as client :
7885 aggregate_content = {
@@ -102,12 +109,11 @@ async def attach_resource(account: AccountFromPrivateKey, fqdn: Hostname, item_h
102109 table .add_column ("Resource type" , style = "magenta" )
103110
104111 current_resource = "null"
105- domain_validator = DomainValidator ()
106112
107113 """
108114 Detect target type on the fly to be able to switch to another type
109115 """
110- resource_type = await domain_validator . get_target_type (fqdn )
116+ resource_type = await get_target_type (fqdn )
111117
112118 if domain_info is not None and domain_info .get ("info" ):
113119 current_resource = domain_info ["info" ]["message_id" ]
@@ -119,7 +125,7 @@ async def attach_resource(account: AccountFromPrivateKey, fqdn: Hostname, item_h
119125 if Confirm .ask ("Continue" ):
120126 """Create aggregate message"""
121127
122- async with AuthenticatedAlephClient (
128+ async with AuthenticatedAlephHttpClient (
123129 account = account , api_server = sdk_settings .API_HOST
124130 ) as client :
125131 aggregate_content = {
@@ -177,7 +183,7 @@ async def add(
177183 owner = account .get_address ()
178184 dns_rules = domain_validator .get_required_dns_rules (fqdn , target , owner )
179185 for rule_id , rule in enumerate (dns_rules ):
180- table .add_row (str (rule_id ), rule [ " dns" ][ " type"] , rule [ " dns" ][ " name"] , rule [ " dns" ][ " value"] )
186+ table .add_row (str (rule_id ), rule . dns . get ( " type") , rule . dns . get ( " name") , rule . dns . get ( " value") )
181187
182188 console .print (table )
183189
@@ -191,7 +197,7 @@ async def add(
191197 checks = await check_domain_records (fqdn , target , owner )
192198 completed_rules = []
193199 for index , rule in enumerate (dns_rules ):
194- if checks [rule [ "rule_name" ] ] is True :
200+ if checks [rule . name ] is True :
195201 """Pass configured rules"""
196202 completed_rules .append (rule )
197203 console .log (f"record: { index } [bold green] OK" )
@@ -202,8 +208,8 @@ async def add(
202208
203209 if dns_rules :
204210 rule = dns_rules [0 ]
205- console .log (f"[green]{ rule [ ' info' ] } " )
206- status .update (f"{ msg_status } [bold red]{ rule [ ' on_error' ] } " )
211+ console .log (f"[green]{ rule . info } " )
212+ status .update (f"{ msg_status } [bold red]{ rule . on_error } " )
207213
208214 max_retries -= 1
209215 sleep (10 )
0 commit comments