2022-03-15 11:58:59 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2022-08-19 02:22:20 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
This module contains wrappers for NeoFS verbs executed via neofs-cli.
|
2022-08-19 02:22:20 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
import allure
|
2022-03-15 11:58:59 +00:00
|
|
|
import json
|
|
|
|
import random
|
2022-06-09 13:08:11 +00:00
|
|
|
import re
|
2022-03-15 11:58:59 +00:00
|
|
|
import uuid
|
2022-08-19 02:22:20 +00:00
|
|
|
from typing import Optional
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
import json_transformers
|
2022-08-29 14:36:27 +00:00
|
|
|
from cli_utils import NeofsCli
|
2022-07-07 21:31:58 +00:00
|
|
|
from common import ASSETS_DIR, NEOFS_ENDPOINT, NEOFS_NETMAP, WALLET_CONFIG
|
|
|
|
from robot.api import logger
|
2022-09-20 15:03:52 +00:00
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
ROBOT_AUTO_KEYWORDS = False
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get object")
|
2022-09-05 09:35:46 +00:00
|
|
|
def get_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
bearer_token: Optional[str] = None,
|
|
|
|
write_object: str = "",
|
|
|
|
endpoint: str = "",
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
no_progress: bool = True,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
) -> str:
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
GET from NeoFS.
|
|
|
|
|
|
|
|
Args:
|
2022-06-06 13:47:13 +00:00
|
|
|
wallet (str): wallet on whose behalf GET is done
|
2022-03-15 11:58:59 +00:00
|
|
|
cid (str): ID of Container where we get the Object from
|
|
|
|
oid (str): Object ID
|
|
|
|
bearer_token (optional, str): path to Bearer Token file, appends to `--bearer` key
|
|
|
|
write_object (optional, str): path to downloaded file, appends to `--file` key
|
|
|
|
endpoint (optional, str): NeoFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-06-13 20:33:09 +00:00
|
|
|
wallet_config(optional, str): path to the wallet config
|
2022-08-19 02:22:20 +00:00
|
|
|
no_progress(optional, bool): do not show progress bar
|
2022-08-25 10:57:55 +00:00
|
|
|
xhdr (optional, dict): Request X-Headers in form of Key=Value
|
2022-09-05 09:35:46 +00:00
|
|
|
session (optional, dict): path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
(str): path to downloaded file
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
|
2022-08-25 10:57:55 +00:00
|
|
|
wallet_config = wallet_config or WALLET_CONFIG
|
2022-03-15 11:58:59 +00:00
|
|
|
if not write_object:
|
|
|
|
write_object = str(uuid.uuid4())
|
|
|
|
file_path = f"{ASSETS_DIR}/{write_object}"
|
|
|
|
|
|
|
|
if not endpoint:
|
|
|
|
endpoint = random.sample(NEOFS_NETMAP, 1)[0]
|
|
|
|
|
2022-08-19 02:22:20 +00:00
|
|
|
cli = NeofsCli(config=wallet_config)
|
2022-09-05 09:35:46 +00:00
|
|
|
cli.object.get(
|
|
|
|
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
file=file_path,
|
|
|
|
bearer=bearer_token,
|
|
|
|
no_progress=no_progress,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
)
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
return file_path
|
|
|
|
|
|
|
|
|
2022-06-06 13:47:13 +00:00
|
|
|
# TODO: make `bearer_token` optional
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get Range Hash")
|
2022-09-05 09:35:46 +00:00
|
|
|
def get_range_hash(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
bearer_token: str,
|
|
|
|
range_cut: str,
|
|
|
|
endpoint: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
):
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
GETRANGEHASH of given Object.
|
|
|
|
|
|
|
|
Args:
|
2022-06-06 13:47:13 +00:00
|
|
|
wallet (str): wallet on whose behalf GETRANGEHASH is done
|
2022-03-15 11:58:59 +00:00
|
|
|
cid (str): ID of Container where we get the Object from
|
|
|
|
oid (str): Object ID
|
2022-09-05 09:35:46 +00:00
|
|
|
bearer_token (optional, str): path to Bearer Token file, appends to `--bearer` key
|
2022-03-15 11:58:59 +00:00
|
|
|
range_cut (str): Range to take hash from in the form offset1:length1,...,
|
|
|
|
value to pass to the `--range` parameter
|
2022-09-05 09:35:46 +00:00
|
|
|
endpoint (optional, str): NeoFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-06-13 20:33:09 +00:00
|
|
|
wallet_config(optional, str): path to the wallet config
|
2022-08-25 10:57:55 +00:00
|
|
|
xhdr (optional, dict): Request X-Headers in form of Key=Value
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
None
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-08-25 10:57:55 +00:00
|
|
|
wallet_config = wallet_config or WALLET_CONFIG
|
2022-08-19 02:22:20 +00:00
|
|
|
cli = NeofsCli(config=wallet_config)
|
2022-09-05 09:35:46 +00:00
|
|
|
output = cli.object.hash(
|
|
|
|
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
range=range_cut,
|
|
|
|
bearer=bearer_token,
|
|
|
|
xhdr=xhdr,
|
|
|
|
)
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-06-06 13:47:13 +00:00
|
|
|
# cutting off output about range offset and length
|
2022-09-05 09:35:46 +00:00
|
|
|
return output.split(":")[1].strip()
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Put object")
|
2022-09-05 09:35:46 +00:00
|
|
|
def put_object(
|
|
|
|
wallet: str,
|
|
|
|
path: str,
|
|
|
|
cid: str,
|
|
|
|
bearer: str = "",
|
|
|
|
attributes: Optional[dict] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
endpoint: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
expire_at: Optional[int] = None,
|
|
|
|
no_progress: bool = True,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
):
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
PUT of given file.
|
|
|
|
|
|
|
|
Args:
|
2022-06-06 13:47:13 +00:00
|
|
|
wallet (str): wallet on whose behalf PUT is done
|
2022-03-15 11:58:59 +00:00
|
|
|
path (str): path to file to be PUT
|
|
|
|
cid (str): ID of Container where we get the Object from
|
|
|
|
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
2022-08-25 10:57:55 +00:00
|
|
|
attributes (optional, str): User attributes in form of Key1=Value1,Key2=Value2
|
2022-03-15 11:58:59 +00:00
|
|
|
endpoint(optional, str): NeoFS endpoint to send request to
|
2022-06-13 20:33:09 +00:00
|
|
|
wallet_config(optional, str): path to the wallet config
|
2022-08-19 02:22:20 +00:00
|
|
|
no_progress(optional, bool): do not show progress bar
|
|
|
|
expire_at (optional, int): Last epoch in the life of the object
|
2022-08-25 10:57:55 +00:00
|
|
|
xhdr (optional, dict): Request X-Headers in form of Key=Value
|
2022-09-05 09:35:46 +00:00
|
|
|
session (optional, dict): path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
(str): ID of uploaded Object
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-08-25 10:57:55 +00:00
|
|
|
wallet_config = wallet_config or WALLET_CONFIG
|
2022-03-15 11:58:59 +00:00
|
|
|
if not endpoint:
|
|
|
|
endpoint = random.sample(NEOFS_NETMAP, 1)[0]
|
2022-07-08 17:24:55 +00:00
|
|
|
if not endpoint:
|
2022-09-05 09:35:46 +00:00
|
|
|
logger.info(f"---DEB:\n{NEOFS_NETMAP}")
|
2022-08-19 02:22:20 +00:00
|
|
|
|
|
|
|
cli = NeofsCli(config=wallet_config)
|
2022-09-05 09:35:46 +00:00
|
|
|
output = cli.object.put(
|
|
|
|
rpc_endpoint=endpoint,
|
|
|
|
wallet=wallet,
|
|
|
|
file=path,
|
|
|
|
cid=cid,
|
|
|
|
attributes=attributes,
|
|
|
|
bearer=bearer,
|
|
|
|
expire_at=expire_at,
|
|
|
|
no_progress=no_progress,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
)
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
# splitting CLI output to lines and taking the penultimate line
|
2022-09-05 09:35:46 +00:00
|
|
|
id_str = output.strip().split("\n")[-2]
|
|
|
|
oid = id_str.split(":")[1]
|
2022-03-15 11:58:59 +00:00
|
|
|
return oid.strip()
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Delete object")
|
2022-09-05 09:35:46 +00:00
|
|
|
def delete_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
endpoint: Optional[str] = None,
|
|
|
|
bearer: str = "",
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
):
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
DELETE an Object.
|
|
|
|
|
|
|
|
Args:
|
2022-06-06 13:47:13 +00:00
|
|
|
wallet (str): wallet on whose behalf DELETE is done
|
2022-03-15 11:58:59 +00:00
|
|
|
cid (str): ID of Container where we get the Object from
|
|
|
|
oid (str): ID of Object we are going to delete
|
|
|
|
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
2022-09-05 09:35:46 +00:00
|
|
|
endpoint (optional, str): NeoFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-06-13 20:33:09 +00:00
|
|
|
wallet_config(optional, str): path to the wallet config
|
2022-08-25 10:57:55 +00:00
|
|
|
xhdr (optional, dict): Request X-Headers in form of Key=Value
|
2022-09-05 09:35:46 +00:00
|
|
|
session (optional, dict): path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
(str): Tombstone ID
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-08-25 10:57:55 +00:00
|
|
|
wallet_config = wallet_config or WALLET_CONFIG
|
2022-08-19 02:22:20 +00:00
|
|
|
cli = NeofsCli(config=wallet_config)
|
2022-09-05 09:35:46 +00:00
|
|
|
output = cli.object.delete(
|
|
|
|
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
)
|
|
|
|
|
|
|
|
id_str = output.split("\n")[1]
|
|
|
|
tombstone = id_str.split(":")[1]
|
2022-03-15 11:58:59 +00:00
|
|
|
return tombstone.strip()
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get Range")
|
2022-09-05 09:35:46 +00:00
|
|
|
def get_range(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
range_cut: str,
|
|
|
|
endpoint: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
bearer: str = "",
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
):
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
GETRANGE an Object.
|
|
|
|
|
|
|
|
Args:
|
2022-06-06 13:47:13 +00:00
|
|
|
wallet (str): wallet on whose behalf GETRANGE is done
|
2022-03-15 11:58:59 +00:00
|
|
|
cid (str): ID of Container where we get the Object from
|
|
|
|
oid (str): ID of Object we are going to request
|
|
|
|
range_cut (str): range to take data from in the form offset:length
|
2022-09-05 09:35:46 +00:00
|
|
|
endpoint (optional, str): NeoFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-06-06 13:47:13 +00:00
|
|
|
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
2022-06-13 20:33:09 +00:00
|
|
|
wallet_config(optional, str): path to the wallet config
|
2022-08-25 10:57:55 +00:00
|
|
|
xhdr (optional, dict): Request X-Headers in form of Key=Value
|
2022-09-05 09:35:46 +00:00
|
|
|
session (optional, dict): path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
2022-08-03 15:50:01 +00:00
|
|
|
(str, bytes) - path to the file with range content and content of this file as bytes
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-08-25 10:57:55 +00:00
|
|
|
wallet_config = wallet_config or WALLET_CONFIG
|
2022-06-06 13:47:13 +00:00
|
|
|
range_file = f"{ASSETS_DIR}/{uuid.uuid4()}"
|
2022-08-19 02:22:20 +00:00
|
|
|
|
|
|
|
cli = NeofsCli(config=wallet_config)
|
2022-09-05 09:35:46 +00:00
|
|
|
cli.object.range(
|
|
|
|
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
range=range_cut,
|
|
|
|
file=range_file,
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
)
|
|
|
|
|
|
|
|
with open(range_file, "rb") as fout:
|
2022-06-06 13:47:13 +00:00
|
|
|
content = fout.read()
|
|
|
|
return range_file, content
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Search object")
|
2022-09-05 09:35:46 +00:00
|
|
|
def search_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
bearer: str = "",
|
|
|
|
endpoint: Optional[str] = None,
|
|
|
|
filters: Optional[dict] = None,
|
|
|
|
expected_objects_list: Optional[list] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
) -> list:
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-06-06 13:47:13 +00:00
|
|
|
SEARCH an Object.
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
Args:
|
2022-06-06 13:47:13 +00:00
|
|
|
wallet (str): wallet on whose behalf SEARCH is done
|
2022-03-15 11:58:59 +00:00
|
|
|
cid (str): ID of Container where we get the Object from
|
|
|
|
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
2022-09-05 09:35:46 +00:00
|
|
|
endpoint (optional, str): NeoFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-03-15 11:58:59 +00:00
|
|
|
filters (optional, dict): key=value pairs to filter Objects
|
|
|
|
expected_objects_list (optional, list): a list of ObjectIDs to compare found Objects with
|
2022-06-13 20:33:09 +00:00
|
|
|
wallet_config(optional, str): path to the wallet config
|
2022-08-25 10:57:55 +00:00
|
|
|
xhdr (optional, dict): Request X-Headers in form of Key=Value
|
2022-09-05 09:35:46 +00:00
|
|
|
session (optional, dict): path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
(list): list of found ObjectIDs
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-08-25 10:57:55 +00:00
|
|
|
wallet_config = wallet_config or WALLET_CONFIG
|
2022-08-19 02:22:20 +00:00
|
|
|
cli = NeofsCli(config=wallet_config)
|
|
|
|
output = cli.object.search(
|
2022-09-05 09:35:46 +00:00
|
|
|
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
|
|
|
filters=[
|
|
|
|
f"{filter_key} EQ {filter_val}"
|
|
|
|
for filter_key, filter_val in filters.items()
|
|
|
|
]
|
|
|
|
if filters
|
|
|
|
else None,
|
|
|
|
session=session,
|
|
|
|
)
|
|
|
|
|
|
|
|
found_objects = re.findall(r"(\w{43,44})", output)
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
if expected_objects_list:
|
|
|
|
if sorted(found_objects) == sorted(expected_objects_list):
|
2022-09-05 09:35:46 +00:00
|
|
|
logger.info(
|
|
|
|
f"Found objects list '{found_objects}' ",
|
|
|
|
f"is equal for expected list '{expected_objects_list}'",
|
|
|
|
)
|
2022-03-15 11:58:59 +00:00
|
|
|
else:
|
2022-09-05 09:35:46 +00:00
|
|
|
logger.warn(
|
|
|
|
f"Found object list {found_objects} ",
|
|
|
|
f"is not equal to expected list '{expected_objects_list}'",
|
|
|
|
)
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
return found_objects
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Head object")
|
2022-09-05 09:35:46 +00:00
|
|
|
def head_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
bearer_token: str = "",
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
endpoint: Optional[str] = None,
|
|
|
|
json_output: bool = True,
|
|
|
|
is_raw: bool = False,
|
|
|
|
is_direct: bool = False,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
):
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
HEAD an Object.
|
|
|
|
|
|
|
|
Args:
|
2022-06-06 13:47:13 +00:00
|
|
|
wallet (str): wallet on whose behalf HEAD is done
|
2022-03-15 11:58:59 +00:00
|
|
|
cid (str): ID of Container where we get the Object from
|
|
|
|
oid (str): ObjectID to HEAD
|
|
|
|
bearer_token (optional, str): path to Bearer Token file, appends to `--bearer` key
|
|
|
|
endpoint(optional, str): NeoFS endpoint to send request to
|
|
|
|
json_output(optional, bool): return reponse in JSON format or not; this flag
|
|
|
|
turns into `--json` key
|
|
|
|
is_raw(optional, bool): send "raw" request or not; this flag
|
|
|
|
turns into `--raw` key
|
2022-04-07 18:48:03 +00:00
|
|
|
is_direct(optional, bool): send request directly to the node or not; this flag
|
|
|
|
turns into `--ttl 1` key
|
2022-06-13 20:33:09 +00:00
|
|
|
wallet_config(optional, str): path to the wallet config
|
2022-08-25 10:57:55 +00:00
|
|
|
xhdr (optional, dict): Request X-Headers in form of Key=Value
|
2022-09-05 09:35:46 +00:00
|
|
|
session (optional, dict): path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
depending on the `json_output` parameter value, the function returns
|
|
|
|
(dict): HEAD response in JSON format
|
|
|
|
or
|
|
|
|
(str): HEAD response as a plain text
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-08-25 10:57:55 +00:00
|
|
|
wallet_config = wallet_config or WALLET_CONFIG
|
2022-08-19 02:22:20 +00:00
|
|
|
cli = NeofsCli(config=wallet_config)
|
2022-09-05 09:35:46 +00:00
|
|
|
output = cli.object.head(
|
|
|
|
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
bearer=bearer_token,
|
|
|
|
json_mode=json_output,
|
|
|
|
raw=is_raw,
|
|
|
|
ttl=1 if is_direct else None,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
)
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
if not json_output:
|
|
|
|
return output
|
|
|
|
|
|
|
|
try:
|
|
|
|
decoded = json.loads(output)
|
|
|
|
except Exception as exc:
|
|
|
|
# If we failed to parse output as JSON, the cause might be
|
|
|
|
# the plain text string in the beginning of the output.
|
|
|
|
# Here we cut off first string and try to parse again.
|
|
|
|
logger.info(f"failed to parse output: {exc}")
|
|
|
|
logger.info("parsing output in another way")
|
2022-09-05 09:35:46 +00:00
|
|
|
fst_line_idx = output.find("\n")
|
2022-03-15 11:58:59 +00:00
|
|
|
decoded = json.loads(output[fst_line_idx:])
|
|
|
|
|
|
|
|
# If response is Complex Object header, it has `splitId` key
|
2022-09-05 09:35:46 +00:00
|
|
|
if "splitId" in decoded.keys():
|
2022-03-15 11:58:59 +00:00
|
|
|
logger.info("decoding split header")
|
|
|
|
return json_transformers.decode_split_header(decoded)
|
|
|
|
|
|
|
|
# If response is Last or Linking Object header,
|
|
|
|
# it has `header` dictionary and non-null `split` dictionary
|
2022-09-05 09:35:46 +00:00
|
|
|
if "split" in decoded["header"].keys():
|
|
|
|
if decoded["header"]["split"]:
|
2022-03-15 11:58:59 +00:00
|
|
|
logger.info("decoding linking object")
|
|
|
|
return json_transformers.decode_linking_object(decoded)
|
|
|
|
|
2022-09-05 09:35:46 +00:00
|
|
|
if decoded["header"]["objectType"] == "STORAGE_GROUP":
|
2022-03-15 11:58:59 +00:00
|
|
|
logger.info("decoding storage group")
|
|
|
|
return json_transformers.decode_storage_group(decoded)
|
|
|
|
|
2022-09-05 09:35:46 +00:00
|
|
|
if decoded["header"]["objectType"] == "TOMBSTONE":
|
2022-06-06 13:47:13 +00:00
|
|
|
logger.info("decoding tombstone")
|
|
|
|
return json_transformers.decode_tombstone(decoded)
|
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
logger.info("decoding simple header")
|
|
|
|
return json_transformers.decode_simple_header(decoded)
|