Skip to content

Commit

Permalink
fix(cli): update workflow sharing commands after changes (reanahub#692)
Browse files Browse the repository at this point in the history
Co-authored-by: Tibor Šimko <tibor.simko@cern.ch>
  • Loading branch information
mdonadoni and tiborsimko committed Sep 4, 2024
1 parent 5e4d12b commit 5d0aca7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 68 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ COPY . /code
RUN apt-get update -y && \
apt-get install --no-install-recommends -y \
gcc \
git \
libpython3.12 \
python3-pip \
python3.12 \
Expand Down
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
104 changes: 41 additions & 63 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022, 2023 CERN.
# Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down 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 bob@cern.ch,cecile@cern.ch``: list workflows shared with either bob@cern.ch or cecile@cern.ch
\t - ``--shared-with bob@cern.ch``: list workflows shared with bob@cern.ch
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 @@ -1621,44 +1621,31 @@ def share_workflow_remove(ctx, workflow, access_token, users): # noqa D412
Example:
$ reana-client share-remove -w myanalysis.42 --user bob@example.org
$ reana-client share-remove -w myanalysis.42 --user bob@example.org
"""
from reana_client.api.client import unshare_workflow

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 @@ -1691,39 +1678,12 @@ def share_workflow_status(
Example:
$ reana-client share-status -w myanalysis.42
$ reana-client share-status -w myanalysis.42
"""
from reana_client.api.client import get_workflow_sharing_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 5d0aca7

Please sign in to comment.