Skip to content

Commit

Permalink
Support for karton_id and karton_arguments in upload parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed Feb 22, 2022
1 parent e13c8db commit 54e878a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions mwdblib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ def _upload_params(
metakeys: Optional[Dict[str, Union[str, List[str]]]],
attributes: Optional[Dict[str, Union[Any, List[Any]]]],
tags: Optional[List[str]],
karton_id: Optional[str],
karton_arguments: Optional[Dict[str, str]],
share_with: Optional[str],
private: bool,
public: bool,
Expand All @@ -729,6 +731,12 @@ def _upload_params(

_tags_param = {"tags": [{"tag": tag} for tag in tags]} if tags else {}

_karton_id_param = {"karton_id": karton_id} if karton_id else {}

_karton_arguments_param = (
{"karton_arguments": karton_arguments} if karton_arguments else {}
)

if len([arg for arg in (share_with, private, public) if arg]) > 1:
raise ValidationError(
"'share_with', 'private' and 'public' arguments are exclusive"
Expand All @@ -747,6 +755,8 @@ def _upload_params(
**_tags_param,
**_metakeys_param,
**_attributes_param,
**_karton_id_param,
**_karton_arguments_param,
}

def upload_file(
Expand All @@ -756,6 +766,8 @@ def upload_file(
parent: Optional[Union[MWDBObject, str]] = None,
metakeys: Optional[Dict[str, Union[str, List[str]]]] = None,
attributes: Optional[Dict[str, Union[Any, List[Any]]]] = None,
karton_id: Optional[str] = None,
karton_arguments: Optional[Dict[str, str]] = None,
tags: Optional[List[str]] = None,
share_with: Optional[str] = None,
private: bool = False,
Expand All @@ -777,6 +789,11 @@ def upload_file(
If you want to set many values with the same key: use list as value.
Attributes support object values that are JSON-serializable.
:type attributes: dict, optional
:param karton_id: Karton analysis identifier to be attached
to the uploaded file
:type karton_id: str, optional
:param karton_arguments: Karton analysis arguments. Reserved for future.
:type karton_arguments: dict, optional
:param tags: Dictionary with tags to be set after upload.
:type tags: list, optional
:param share_with: Group name you want to share object with
Expand All @@ -792,6 +809,11 @@ def upload_file(
They are supported by MWDB Core >= 2.6.0, use ``metakeys``
if your MWDB Core version is older.
.. versionadded:: 4.1.0
Added ``karton_id`` and ``karton_arguments`` parameters.
Use ``karton_id`` instead of ``metakeys={"karton": "<id>"}`` if
you use MWDB Core >= 2.3.0
Usage example:
.. code-block:: python
Expand All @@ -813,6 +835,8 @@ def upload_file(
parent=parent,
metakeys=metakeys,
attributes=attributes,
karton_id=karton_id,
karton_arguments=karton_arguments,
tags=tags,
share_with=share_with,
private=private,
Expand All @@ -832,6 +856,8 @@ def upload_config(
parent: Optional[Union[MWDBObject, str]] = None,
metakeys: Optional[Dict[str, Union[str, List[str]]]] = None,
attributes: Optional[Dict[str, Union[Any, List[Any]]]] = None,
karton_id: Optional[str] = None,
karton_arguments: Optional[Dict[str, str]] = None,
tags: Optional[List[str]] = None,
share_with: Optional[str] = None,
private: bool = False,
Expand All @@ -856,6 +882,11 @@ def upload_config(
If you want to set many values with the same key: use list as value.
Attributes support object values that are JSON-serializable.
:type attributes: dict, optional
:param karton_id: Karton analysis identifier to be attached
to the uploaded file
:type karton_id: str, optional
:param karton_arguments: Karton analysis arguments. Reserved for future.
:type karton_arguments: dict, optional
:param tags: Dictionary with tags to be set after upload.
:type tags: list, optional
:param share_with: Group name you want to share object with
Expand All @@ -871,6 +902,11 @@ def upload_config(
They are supported by MWDB Core >= 2.6.0, use ``metakeys``
if your MWDB Core version is older.
.. versionadded:: 4.1.0
Added ``karton_id`` and ``karton_arguments`` parameters.
Use ``karton_id`` instead of ``metakeys={"karton": "<id>"}`` if
you use MWDB Core >= 2.3.0
.. code-block:: python
mwdb.upload_config(
Expand All @@ -892,6 +928,8 @@ def upload_config(
parent=parent,
metakeys=metakeys,
attributes=attributes,
karton_id=karton_id,
karton_arguments=karton_arguments,
tags=tags,
share_with=share_with,
private=private,
Expand All @@ -909,6 +947,8 @@ def upload_blob(
parent: Optional[Union[MWDBObject, str]] = None,
metakeys: Optional[Dict[str, Union[str, List[str]]]] = None,
attributes: Optional[Dict[str, Union[Any, List[Any]]]] = None,
karton_id: Optional[str] = None,
karton_arguments: Optional[Dict[str, str]] = None,
tags: Optional[List[str]] = None,
share_with: Optional[str] = None,
private: bool = False,
Expand All @@ -932,6 +972,11 @@ def upload_blob(
If you want to set many values with the same key: use list as value.
Attributes support object values that are JSON-serializable.
:type attributes: dict, optional
:param karton_id: Karton analysis identifier to be attached
to the uploaded file
:type karton_id: str, optional
:param karton_arguments: Karton analysis arguments. Reserved for future.
:type karton_arguments: dict, optional
:param tags: Dictionary with tags to be set after upload.
:type tags: list, optional
:param share_with: Group name you want to share object with
Expand All @@ -946,13 +991,20 @@ def upload_blob(
Added ``attributes`` and ``tags`` arguments.
They are supported by MWDB Core >= 2.6.0, use ``metakeys``
if your MWDB Core version is older.
.. versionadded:: 4.1.0
Added ``karton_id`` and ``karton_arguments`` parameters.
Use ``karton_id`` instead of ``metakeys={"karton": "<id>"}`` if
you use MWDB Core >= 2.3.0
"""
params = {"blob_name": name, "blob_type": type, "content": content}
params.update(
self._upload_params(
parent=parent,
metakeys=metakeys,
attributes=attributes,
karton_id=karton_id,
karton_arguments=karton_arguments,
tags=tags,
share_with=share_with,
private=private,
Expand Down

0 comments on commit 54e878a

Please sign in to comment.