[#424] neofs-cli: WIF replaced with wallets

Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
This commit is contained in:
Elizaveta Chichindaeva 2022-02-01 16:42:41 +03:00
parent b3b0e20628
commit 89a4c6daa7
55 changed files with 1299 additions and 1307 deletions

View file

@ -9,7 +9,7 @@ import uuid
import base64
import base58
from cli_helpers import _cmd_run
from common import ASSETS_DIR, NEOFS_ENDPOINT
from common import ASSETS_DIR, NEOFS_ENDPOINT, WALLET_PASS
from robot.api.deco import keyword
from robot.api import logger
@ -36,10 +36,10 @@ class Role(AutoName):
@keyword('Get eACL')
def get_eacl(wif: str, cid: str):
def get_eacl(wallet: str, cid: str):
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wif} '
f'container get-eacl --cid {cid}'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'container get-eacl --cid {cid} --config {WALLET_PASS}'
)
try:
output = _cmd_run(cmd)
@ -53,10 +53,10 @@ def get_eacl(wif: str, cid: str):
@keyword('Set eACL')
def set_eacl(wif: str, cid: str, eacl_table_path: str):
def set_eacl(wallet: str, cid: str, eacl_table_path: str):
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wif} '
f'container set-eacl --cid {cid} --table {eacl_table_path} --await'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'container set-eacl --cid {cid} --table {eacl_table_path} --config {WALLET_PASS} --await'
)
_cmd_run(cmd)
@ -159,9 +159,9 @@ def form_bearertoken_file(wif: str, cid: str, eacl_records: list) -> str:
return file_path
def sign_bearer_token(wif: str, eacl_rules_file: str):
def sign_bearer_token(wallet: str, eacl_rules_file: str):
cmd = (
f'{NEOFS_CLI_EXEC} util sign bearer-token --from {eacl_rules_file} '
f'--to {eacl_rules_file} --wallet {wif} --json'
f'--to {eacl_rules_file} --wallet {wallet} --config {WALLET_PASS} --json'
)
_cmd_run(cmd)

View file

@ -60,13 +60,13 @@ def start_nodes(*nodes_list):
@keyword('Get nodes with object')
def get_nodes_with_object(private_key: str, cid: str, oid: str):
def get_nodes_with_object(wallet: str, cid: str, oid: str):
copies = 0
nodes_list = []
for node in NEOFS_NETMAP:
search_res = _search_object(node, private_key, cid, oid)
search_res = _search_object(node, wallet, cid, oid)
if search_res:
if oid in search_res:
nodes_list.append(node)
@ -76,13 +76,13 @@ def get_nodes_with_object(private_key: str, cid: str, oid: str):
@keyword('Get nodes without object')
def get_nodes_without_object(private_key: str, cid: str, oid: str):
def get_nodes_without_object(wallet: str, cid: str, oid: str):
copies = 0
nodes_list = []
for node in NEOFS_NETMAP:
search_res = _search_object(node, private_key, cid, oid)
search_res = _search_object(node, wallet, cid, oid)
if search_res:
if not re.search(fr'({oid})', search_res):
nodes_list.append(node)
@ -94,7 +94,7 @@ def get_nodes_without_object(private_key: str, cid: str, oid: str):
@keyword('Validate storage policy for object')
def validate_storage_policy_for_object(private_key: str, expected_copies: int, cid, oid,
def validate_storage_policy_for_object(wallet: str, expected_copies: int, cid, oid,
expected_node_list=[], storage_nodes=[]):
storage_nodes = storage_nodes if len(storage_nodes) != 0 else NEOFS_NETMAP
copies = 0
@ -102,7 +102,7 @@ def validate_storage_policy_for_object(private_key: str, expected_copies: int, c
oid = oid.strip()
for node in storage_nodes:
search_res = _search_object(node, private_key, cid, oid)
search_res = _search_object(node, wallet, cid, oid)
if search_res:
if oid in search_res:
copies += 1
@ -123,9 +123,8 @@ def validate_storage_policy_for_object(private_key: str, expected_copies: int, c
raise Exception(f"Found node list '{found_nodes}' is not equal to expected list '{expected_node_list}'")
@keyword('Create container')
def create_container(private_key: str, basic_acl:str, rule:str, user_headers: str='', session: str=''):
def create_container(wallet: str, basic_acl:str, rule:str, user_headers: str='', session: str=''):
if rule == "":
logger.error("Cannot create container with empty placement rule")
@ -137,8 +136,8 @@ def create_container(private_key: str, basic_acl:str, rule:str, user_headers: st
session = f"--session {session}"
createContainerCmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {private_key} '
f'container create --policy "{rule}" {basic_acl} {user_headers} {session} --await'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'container create --policy "{rule}" {basic_acl} {user_headers} {session} --config {WALLET_PASS} --await'
)
output = _cmd_run(createContainerCmd)
cid = _parse_cid(output)
@ -147,10 +146,10 @@ def create_container(private_key: str, basic_acl:str, rule:str, user_headers: st
return cid
@keyword('Container List')
def container_list(private_key: str):
def container_list(wallet: str):
Cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {private_key} '
f'container list'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'container list --config {WALLET_PASS}'
)
output = _cmd_run(Cmd)
@ -160,10 +159,10 @@ def container_list(private_key: str):
@keyword('Container Existing')
def container_existing(private_key: str, cid: str):
def container_existing(wallet: str, cid: str):
Cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {private_key} '
f'container list'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'container list --config {WALLET_PASS}'
)
output = _cmd_run(Cmd)
@ -172,11 +171,11 @@ def container_existing(private_key: str, cid: str):
@keyword('Verify Head Tombstone')
def verify_head_tombstone(private_key: str, cid: str, oid_ts: str, oid: str, addr: str):
def verify_head_tombstone(wallet: str, cid: str, oid_ts: str, oid: str, addr: str):
# TODO: replace with HEAD from neofs_verbs.py
object_cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {private_key} '
f'object head --cid {cid} --oid {oid_ts} --json'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'--config {WALLET_PASS} object head --cid {cid} --oid {oid_ts} --json'
)
output = _cmd_run(object_cmd)
full_headers = json.loads(output)
@ -221,13 +220,13 @@ def verify_head_tombstone(private_key: str, cid: str, oid_ts: str, oid: str, add
@keyword('Get container attributes')
def get_container_attributes(private_key: str, cid: str, endpoint: str="", json_output: bool = False):
def get_container_attributes(wallet: str, cid: str, endpoint: str="", json_output: bool = False):
if endpoint == "":
endpoint = NEOFS_ENDPOINT
container_cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {endpoint} --wallet {private_key} '
f'{NEOFS_CLI_EXEC} --rpc-endpoint {endpoint} --wallet {wallet} --config {WALLET_PASS} '
f'--cid {cid} container get {"--json" if json_output else ""}'
)
output = _cmd_run(container_cmd)
@ -253,14 +252,13 @@ def decode_container_attributes_json(header):
return result_header
@keyword('Delete Container')
# TODO: make the error message about a non-found container more user-friendly https://github.com/nspcc-dev/neofs-contract/issues/121
def delete_container(cid: str, private_key: str):
def delete_container(cid: str, wallet: str):
deleteContainerCmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {private_key} '
f'container delete --cid {cid}'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'container delete --cid {cid} --config {WALLET_PASS}'
)
_cmd_run(deleteContainerCmd)
@ -358,7 +356,7 @@ def find_in_nodes_Log(line: str, nodes_logs_time: dict):
@keyword('Put Storagegroup')
def put_storagegroup(private_key: str, cid: str, bearer_token: str="", *oid_list):
def put_storagegroup(wallet: str, cid: str, bearer_token: str="", *oid_list):
cmd_oid_line = ",".join(oid_list)
@ -366,8 +364,8 @@ def put_storagegroup(private_key: str, cid: str, bearer_token: str="", *oid_list
bearer_token = f"--bearer {bearer_token}"
object_cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {private_key} storagegroup '
f'put --cid {cid} --members {cmd_oid_line} {bearer_token}'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} --config {WALLET_PASS} '
f'storagegroup put --cid {cid} --members {cmd_oid_line} {bearer_token}'
)
output = _cmd_run(object_cmd)
oid = _parse_oid(output)
@ -376,14 +374,14 @@ def put_storagegroup(private_key: str, cid: str, bearer_token: str="", *oid_list
@keyword('List Storagegroup')
def list_storagegroup(private_key: str, cid: str, bearer_token: str="", *expected_list):
def list_storagegroup(wallet: str, cid: str, bearer_token: str="", *expected_list):
if bearer_token:
bearer_token = f"--bearer {bearer_token}"
object_cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {private_key} '
f'storagegroup list --cid {cid} {bearer_token}'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'--config {WALLET_PASS} storagegroup list --cid {cid} {bearer_token}'
)
output = _cmd_run(object_cmd)
found_objects = re.findall(r'(\w{43,44})', output)
@ -398,7 +396,7 @@ def list_storagegroup(private_key: str, cid: str, bearer_token: str="", *expecte
@keyword('Get Storagegroup')
def get_storagegroup(private_key: str, cid: str, oid: str, bearer_token: str, expected_size, *expected_objects_list):
def get_storagegroup(wallet: str, cid: str, oid: str, bearer_token: str, expected_size, *expected_objects_list):
if bearer_token:
bearer_token = f"--bearer {bearer_token}"
@ -422,14 +420,14 @@ def get_storagegroup(private_key: str, cid: str, oid: str, bearer_token: str, ex
@keyword('Delete Storagegroup')
def delete_storagegroup(private_key: str, cid: str, oid: str, bearer_token: str=""):
def delete_storagegroup(wallet: str, cid: str, oid: str, bearer_token: str=""):
if bearer_token:
bearer_token = f"--bearer {bearer_token}"
object_cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {private_key} storagegroup '
f'delete --cid {cid} --id {oid} {bearer_token}'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} storagegroup '
f'delete --cid {cid} --config {WALLET_PASS} --id {oid} {bearer_token}'
)
output = _cmd_run(object_cmd)
@ -484,10 +482,10 @@ def sign_session_token(session_token: str, wallet: str, to_file: str=''):
to_file = f'--to {to_file}'
cmd = (
f'{NEOFS_CLI_EXEC} util sign session-token --from {session_token} '
f'-w {wallet} {to_file}'
f'-w {wallet} {to_file} --config {WALLET_PASS}'
)
logger.info(f"cmd: {cmd}")
_run_with_passwd(cmd)
_cmd_run(cmd)
def _get_file_hash(filename):
@ -556,10 +554,10 @@ def _parse_cid(input_str: str):
return splitted[1]
def _search_object(node:str, private_key: str, cid:str, oid: str):
def _search_object(node:str, wallet: str, cid:str, oid: str):
Cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {node} --wallet {private_key} --ttl 1 '
f'object search --root --cid {cid} --oid {oid}'
f'{NEOFS_CLI_EXEC} --rpc-endpoint {node} --wallet {wallet} --ttl 1 '
f'object search --root --cid {cid} --oid {oid} --config {WALLET_PASS}'
)
output = _cmd_run(Cmd)
return output

View file

@ -11,7 +11,7 @@ import random
import uuid
from functools import reduce
from common import NEOFS_ENDPOINT, ASSETS_DIR, NEOFS_NETMAP
from common import NEOFS_ENDPOINT, ASSETS_DIR, NEOFS_NETMAP, WALLET_PASS
from cli_helpers import _cmd_run
import json_transformers
@ -25,7 +25,7 @@ NEOFS_CLI_EXEC = os.getenv('NEOFS_CLI_EXEC', 'neofs-cli')
@keyword('Get object')
def get_object(wif: str, cid: str, oid: str, bearer_token: str="",
def get_object(wallet: str, cid: str, oid: str, bearer_token: str="",
write_object: str="", endpoint: str="", options: str="" ):
'''
GET from NeoFS.
@ -50,8 +50,8 @@ def get_object(wif: str, cid: str, oid: str, bearer_token: str="",
endpoint = random.sample(NEOFS_NETMAP, 1)[0]
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {endpoint} --wallet {wif} '
f'object get --cid {cid} --oid {oid} --file {file_path} '
f'{NEOFS_CLI_EXEC} --rpc-endpoint {endpoint} --wallet {wallet} '
f'object get --cid {cid} --oid {oid} --file {file_path} --config {WALLET_PASS} '
f'{"--bearer " + bearer_token if bearer_token else ""} '
f'{options}'
)
@ -60,7 +60,7 @@ def get_object(wif: str, cid: str, oid: str, bearer_token: str="",
@keyword('Get Range Hash')
def get_range_hash(wif: str, cid: str, oid: str, bearer_token: str,
def get_range_hash(wallet: str, cid: str, oid: str, bearer_token: str,
range_cut: str, options: str=""):
'''
GETRANGEHASH of given Object.
@ -77,8 +77,8 @@ def get_range_hash(wif: str, cid: str, oid: str, bearer_token: str,
None
'''
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wif} '
f'object hash --cid {cid} --oid {oid} --range {range_cut} '
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'object hash --cid {cid} --oid {oid} --range {range_cut} --config {WALLET_PASS} '
f'{"--bearer " + bearer_token if bearer_token else ""} '
f'{options}'
)
@ -86,7 +86,7 @@ def get_range_hash(wif: str, cid: str, oid: str, bearer_token: str,
@keyword('Put object')
def put_object(wif: str, path: str, cid: str, bearer: str="", user_headers: dict={},
def put_object(wallet: str, path: str, cid: str, bearer: str="", user_headers: dict={},
endpoint: str="", options: str="" ):
'''
PUT of given file.
@ -105,8 +105,8 @@ def put_object(wif: str, path: str, cid: str, bearer: str="", user_headers: dict
if not endpoint:
endpoint = random.sample(NEOFS_NETMAP, 1)[0]
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {endpoint} --wallet {wif} '
f'object put --file {path} --cid {cid} {options} '
f'{NEOFS_CLI_EXEC} --rpc-endpoint {endpoint} --wallet {wallet} '
f'object put --file {path} --cid {cid} {options} --config {WALLET_PASS} '
f'{"--bearer " + bearer if bearer else ""} '
f'{"--attributes " + _dict_to_attrs(user_headers) if user_headers else ""}'
)
@ -118,7 +118,7 @@ def put_object(wif: str, path: str, cid: str, bearer: str="", user_headers: dict
@keyword('Delete object')
def delete_object(wif: str, cid: str, oid: str, bearer: str="", options: str=""):
def delete_object(wallet: str, cid: str, oid: str, bearer: str="", options: str=""):
'''
DELETE an Object.
@ -132,8 +132,8 @@ def delete_object(wif: str, cid: str, oid: str, bearer: str="", options: str="")
(str): Tombstone ID
'''
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wif} '
f'object delete --cid {cid} --oid {oid} {options} '
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'object delete --cid {cid} --oid {oid} {options} --config {WALLET_PASS} '
f'{"--bearer " + bearer if bearer else ""}'
)
output = _cmd_run(cmd)
@ -143,7 +143,7 @@ def delete_object(wif: str, cid: str, oid: str, bearer: str="", options: str="")
@keyword('Get Range')
def get_range(wif: str, cid: str, oid: str, range_file: str, bearer: str,
def get_range(wallet: str, cid: str, oid: str, range_file: str, bearer: str,
range_cut: str, options:str=""):
'''
GETRANGE an Object.
@ -160,8 +160,8 @@ def get_range(wif: str, cid: str, oid: str, range_file: str, bearer: str,
None
'''
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wif} '
f'object range --cid {cid} --oid {oid} --range {range_cut} '
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'object range --cid {cid} --oid {oid} --range {range_cut} --config {WALLET_PASS} '
f'--file {ASSETS_DIR}/{range_file} {options} '
f'{"--bearer " + bearer if bearer else ""} '
)
@ -169,7 +169,7 @@ def get_range(wif: str, cid: str, oid: str, range_file: str, bearer: str,
@keyword('Search object')
def search_object(wif: str, cid: str, keys: str="", bearer: str="", filters: dict={},
def search_object(wallet: str, cid: str, keys: str="", bearer: str="", filters: dict={},
expected_objects_list=[], options:str=""):
'''
GETRANGE an Object.
@ -193,8 +193,8 @@ def search_object(wif: str, cid: str, keys: str="", bearer: str="", filters: dic
filters_result += ','.join(map(lambda i: f"'{i} EQ {filters[i]}'", filters))
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wif} '
f'object search {keys} --cid {cid} {filters_result} {options} '
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'object search {keys} --cid {cid} {filters_result} {options} --config {WALLET_PASS} '
f'{"--bearer " + bearer if bearer else ""}'
)
output = _cmd_run(cmd)
@ -213,7 +213,7 @@ def search_object(wif: str, cid: str, keys: str="", bearer: str="", filters: dic
@keyword('Head object')
def head_object(wif: str, cid: str, oid: str, bearer_token: str="",
def head_object(wallet: str, cid: str, oid: str, bearer_token: str="",
options:str="", endpoint: str="", json_output: bool = True,
is_raw: bool = False, is_direct: bool = False):
'''
@ -240,7 +240,7 @@ def head_object(wif: str, cid: str, oid: str, bearer_token: str="",
'''
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {endpoint if endpoint else NEOFS_ENDPOINT} '
f'--wallet {wif} '
f'--wallet {wallet} --config {WALLET_PASS} '
f'object head --cid {cid} --oid {oid} {options} '
f'{"--bearer " + bearer_token if bearer_token else ""} '
f'{"--json" if json_output else ""} '

View file

@ -45,14 +45,6 @@ def get_container_logs(testcase_name: str) -> None:
os.remove(file_name)
tar.close()
@keyword('WIF to Binary')
def wif_to_binary(wif: str) -> str:
priv_key = wallet.Account.private_key_from_wif(wif)
path = f"{os.getcwd()}/{ASSETS_DIR}/{str(uuid.uuid4())}"
with open(path, "wb") as out:
out.write(priv_key)
return path
@keyword('Make Up')
def make_up(services: list=[], config_dict: dict={}):
test_path = os.getcwd()