forked from TrueCloudLab/frostfs-testlib
[#191] Credentials work overhaul
Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
This commit is contained in:
parent
09a7f66d1e
commit
25925c637b
31 changed files with 370 additions and 485 deletions
|
@ -1,13 +1,15 @@
|
|||
import json
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
from frostfs_testlib.resources.common import DEFAULT_WALLET_CONFIG, DEFAULT_WALLET_PASS
|
||||
import yaml
|
||||
|
||||
from frostfs_testlib import reporter
|
||||
from frostfs_testlib.resources.common import ASSETS_DIR, DEFAULT_WALLET_CONFIG, DEFAULT_WALLET_PASS
|
||||
from frostfs_testlib.shell import Shell
|
||||
from frostfs_testlib.storage.cluster import Cluster, NodeBase
|
||||
from frostfs_testlib.storage.cluster import NodeBase
|
||||
from frostfs_testlib.utils.wallet_utils import get_last_address_from_wallet, init_wallet
|
||||
|
||||
logger = logging.getLogger("frostfs.testlib.utils")
|
||||
|
@ -21,9 +23,13 @@ class WalletInfo:
|
|||
|
||||
@staticmethod
|
||||
def from_node(node: NodeBase):
|
||||
return WalletInfo(
|
||||
node.get_wallet_path(), node.get_wallet_password(), node.get_wallet_config_path()
|
||||
)
|
||||
wallet_path = node.get_wallet_path()
|
||||
wallet_password = node.get_wallet_password()
|
||||
wallet_config_file = os.path.join(ASSETS_DIR, os.path.basename(node.get_wallet_config_path()))
|
||||
with open(wallet_config_file, "w") as file:
|
||||
file.write(yaml.dump({"wallet": wallet_path, "password": wallet_password}))
|
||||
|
||||
return WalletInfo(wallet_path, wallet_password, wallet_config_file)
|
||||
|
||||
def get_address(self) -> str:
|
||||
"""
|
||||
|
@ -47,22 +53,17 @@ class WalletInfo:
|
|||
"""
|
||||
with open(self.path, "r") as wallet:
|
||||
wallet_json = json.load(wallet)
|
||||
assert abs(account_id) + 1 <= len(
|
||||
wallet_json["accounts"]
|
||||
), f"There is no index '{account_id}' in wallet: {wallet_json}"
|
||||
assert abs(account_id) + 1 <= len(wallet_json["accounts"]), f"There is no index '{account_id}' in wallet: {wallet_json}"
|
||||
|
||||
return wallet_json["accounts"][account_id]["address"]
|
||||
|
||||
|
||||
class WalletFactory:
|
||||
def __init__(self, wallets_dir: str, shell: Shell, cluster: Cluster) -> None:
|
||||
def __init__(self, wallets_dir: str, shell: Shell) -> None:
|
||||
self.shell = shell
|
||||
self.wallets_dir = wallets_dir
|
||||
self.cluster = cluster
|
||||
|
||||
def create_wallet(
|
||||
self, file_name: Optional[str] = None, password: Optional[str] = None
|
||||
) -> WalletInfo:
|
||||
def create_wallet(self, file_name: str, password: Optional[str] = None) -> WalletInfo:
|
||||
"""
|
||||
Creates new default wallet.
|
||||
|
||||
|
@ -74,8 +75,6 @@ class WalletFactory:
|
|||
WalletInfo object of new wallet.
|
||||
"""
|
||||
|
||||
if file_name is None:
|
||||
file_name = str(uuid.uuid4())
|
||||
if password is None:
|
||||
password = ""
|
||||
|
||||
|
@ -85,6 +84,8 @@ class WalletFactory:
|
|||
init_wallet(wallet_path, password)
|
||||
|
||||
with open(wallet_config_path, "w") as config_file:
|
||||
config_file.write(f'password: "{password}"')
|
||||
config_file.write(f'wallet: {wallet_path}\npassword: "{password}"')
|
||||
|
||||
reporter.attach(wallet_path, os.path.basename(wallet_path))
|
||||
|
||||
return WalletInfo(wallet_path, password, wallet_config_path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue