-
Notifications
You must be signed in to change notification settings - Fork 516
/
indy_tails_server.py
79 lines (62 loc) · 2.64 KB
/
indy_tails_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Indy tails server interface class."""
import logging
from typing import Tuple
from ..config.injection_context import InjectionContext
from ..ledger.base import BaseLedger
from ..ledger.multiple_ledger.base_manager import BaseMultipleLedgerManager
from ..utils.http import put_file, PutError
from .base import BaseTailsServer
from .error import TailsServerNotConfiguredError
LOGGER = logging.getLogger(__name__)
class IndyTailsServer(BaseTailsServer):
"""Indy tails server interface."""
async def upload_tails_file(
self,
context: InjectionContext,
rev_reg_id: str,
tails_file_path: str,
interval: float = 1.0,
backoff: float = 0.25,
max_attempts: int = 5,
) -> Tuple[bool, str]:
"""Upload tails file to tails server.
Args:
context: context with configuration settings
rev_reg_id: revocation registry identifier
tails_file_path: path to the tails file to upload
interval: initial interval between attempts
backoff: exponential backoff in retry interval
max_attempts: maximum number of attempts to make
"""
tails_server_upload_url = context.settings.get("tails_server_upload_url")
genesis_transactions = context.settings.get("ledger.genesis_transactions")
if not genesis_transactions:
ledger_manager = context.injector.inject(BaseMultipleLedgerManager)
write_ledger = context.injector.inject(BaseLedger)
available_write_ledgers = await ledger_manager.get_write_ledgers()
LOGGER.debug(f"available write_ledgers = {available_write_ledgers}")
LOGGER.debug(f"write_ledger = {write_ledger}")
pool = write_ledger[1].pool
LOGGER.debug(f"write_ledger pool = {pool}")
genesis_transactions = pool.genesis_txns
if not genesis_transactions:
raise TailsServerNotConfiguredError(
"no genesis_transactions for writable ledger"
)
if not tails_server_upload_url:
raise TailsServerNotConfiguredError(
"tails_server_upload_url setting is not set"
)
upload_url = tails_server_upload_url.rstrip("/") + f"/{rev_reg_id}"
try:
await put_file(
upload_url,
{"tails": tails_file_path},
{"genesis": genesis_transactions},
interval=interval,
backoff=backoff,
max_attempts=max_attempts,
)
except PutError as x_put:
return (False, x_put.message)
return True, upload_url