Skip to content

Commit

Permalink
fix(cli): update workflow sharing commands after changes (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni authored and tiborsimko committed Sep 4, 2024
1 parent 5e4d12b commit 292827d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 65 deletions.
6 changes: 3 additions & 3 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,9 +1306,7 @@ def share_workflow(
"""
try:
share_params = {
"workflow_id_or_name": workflow,
"user_email_to_share_with": user_email_to_share_with,
"access_token": access_token,
}

if message:
Expand All @@ -1318,7 +1316,9 @@ def share_workflow(
share_params["valid_until"] = valid_until

(response, http_response) = current_rs_api_client.api.share_workflow(
**share_params
workflow_id_or_name=workflow,
share_details=share_params,
access_token=access_token,
).result()

if http_response.status_code == 200:
Expand Down
98 changes: 38 additions & 60 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ def workflow_sharing_group(ctx):
"--shared-by",
"shared_by",
default=None,
help="List workflows shared by the specified user(s).",
help="List workflows shared by the specified user.",
)
@click.option(
"--shared-with",
"shared_with",
default=None,
help="List workflows shared with the specified user(s).",
help="List workflows shared with the specified user.",
)
@add_access_token_options
@add_pagination_options
Expand Down Expand Up @@ -215,7 +215,7 @@ def workflows_list( # noqa: C901
\t - ``--shared-by anybody``: list workflows shared with you by anybody.\n
\t - ``--shared-with anybody``: list your shared workflows exclusively.\n
\t - ``--shared-with nobody``: list your unshared workflows exclusively.\n
\t - ``--shared-with [email protected],[email protected]``: list workflows shared with either bob@cern.ch or cecile@cern.ch
\t - ``--shared-with [email protected]``: list workflows shared with [email protected]
Examples:\n
\t $ reana-client list --all\n
Expand Down Expand Up @@ -332,7 +332,7 @@ def workflows_list( # noqa: C901
if header == "shared_by":
value = workflow.get("owner_email")
if header == "shared_with":
value = workflow.get("shared_with")
value = ", ".join(workflow.get("shared_with", []))
if not value:
value = workflow.get(header)
row.append(value)
Expand Down Expand Up @@ -1628,37 +1628,24 @@ def share_workflow_remove(ctx, workflow, access_token, users): # noqa D412
unshare_errors = []
unshared_users = []

if workflow:
for user in users:
try:
for user in users:
try:
logging.info(f"Unsharing workflow {workflow} with user {user}")
unshare_workflow(workflow, user, access_token)
unshared_users.append(user)
except Exception as e:
unshare_errors.append(
f"Failed to unshare {workflow} with {user}: {str(e)}"
)
logging.debug(traceback.format_exc())
logging.info(f"Unsharing workflow {workflow} with user {user}")
unshare_workflow(workflow, user, access_token)
unshared_users.append(user)
except Exception as e:
unshare_errors.append(f"Failed to unshare {workflow} with {user}: {str(e)}")
logging.debug(traceback.format_exc())
logging.debug(str(e))
display_message(
"An error occurred while unsharing workflow:\n{}".format(str(e)),
msg_type="error",
)

if unshared_users:
display_message(
f"{workflow} is no longer shared with {', '.join(unshared_users)}",
msg_type="success",
)
if unshare_errors:
for error in unshare_errors:
display_message(error, msg_type="error")

else:
display_message(f"Cannot find workflow {workflow}", msg_type="error")
if unshared_users:
display_message(
f"{workflow} is no longer shared with {', '.join(unshared_users)}",
msg_type="success",
)
if unshare_errors:
for error in unshare_errors:
display_message(error, msg_type="error")
sys.exit(1)


@workflow_sharing_group.command("share-status")
Expand All @@ -1667,7 +1654,7 @@ def share_workflow_remove(ctx, workflow, access_token, users): # noqa D412
@add_access_token_options
@click.option(
"--format",
"_format",
"format_",
multiple=True,
default=None,
help="Format output according to column titles or column "
Expand All @@ -1682,7 +1669,7 @@ def share_workflow_remove(ctx, workflow, access_token, users): # noqa D412
)
@click.pass_context
def share_workflow_status(
ctx, workflow, _format, output_format, access_token
ctx, workflow, format_, output_format, access_token
): # noqa D412
"""Show with whom a workflow is shared.
Expand All @@ -1697,33 +1684,6 @@ def share_workflow_status(

try:
sharing_status = get_workflow_sharing_status(workflow, access_token)

if sharing_status:
shared_with = sharing_status.get("shared_with", [])

if shared_with:
headers = ["user_email", "valid_until"]
data = [
[
entry["user_email"],
(
entry["valid_until"]
if entry["valid_until"] is not None
else "-"
),
]
for entry in shared_with
]

display_formatted_output(data, headers, _format, output_format)
else:
display_message(
f"Workflow {workflow} is not shared with anyone.", msg_type="info"
)
else:
display_message(
f"Workflow {workflow} is not shared with anyone.", msg_type="info"
)
except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
Expand All @@ -1733,3 +1693,21 @@ def share_workflow_status(
),
msg_type="error",
)
sys.exit(1)

shared_with = sharing_status.get("shared_with", [])
if shared_with:
headers = ["user_email", "valid_until"]
data = [
[
entry["user_email"],
(entry["valid_until"] if entry["valid_until"] is not None else "-"),
]
for entry in shared_with
]

display_formatted_output(data, headers, format_, output_format)
else:
display_message(
f"Workflow {workflow} is not shared with anyone.", msg_type="info"
)
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"sphinx-click>=1.0.4",
],
"tests": [
"pytest-reana>=0.95.0a2,<0.96.0",
"pytest-reana>=0.95.0a4,<0.96.0",
"reana-commons[kubernetes]>=0.95.0a3,<0.96.0",
"reana-commons[kubernetes] @ git+https://github.com/reanahub/reana-commons.git@master",
],
}

Expand All @@ -40,7 +42,8 @@
"click>=7",
"pathspec==0.9.0",
"jsonpointer>=2.0",
"reana-commons[yadage,snakemake,cwl]>=0.95.0a2,<0.96.0",
"reana-commons[yadage,snakemake,cwl]>=0.95.0a3,<0.96.0",
"reana-commons[yadage,snakemake,cwl] @ git+https://github.com/reanahub/reana-commons.git@master",
"tablib>=0.12.1,<0.13",
"werkzeug>=0.14.1 ; python_version<'3.10'",
"werkzeug>=0.15.0 ; python_version>='3.10'",
Expand Down

0 comments on commit 292827d

Please sign in to comment.