Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: implement share-add command #683

Closed
wants to merge 1 commit into from

Conversation

DaanRosendal
Copy link
Member

Adds a new command to the CLI to share a workflow with a user.

Closes #680

@DaanRosendal DaanRosendal force-pushed the feature/share-add branch 3 times, most recently from 3f75e8c to 508acbd Compare November 8, 2023 10:34
Adds a new command to the CLI to share a workflow with a user.

Closes reanahub#680
help="Optional date when access to the workflow will expire for the given user(s) (format: YYYY-MM-DD).",
)
@click.pass_context
def share_workflow_add(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick:

Suggested change
def share_workflow_add(
def workflow_share_add(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

The changes were applied to the following superseding PR: #692

Comment on lines +1486 to +1490
@click.option(
"-v",
"--valid-until",
help="Optional date when access to the workflow will expire for the given user(s) (format: YYYY-MM-DD).",
)
Copy link
Member

@mdonadoni mdonadoni Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. Added.

The changes were applied to the following superseding PR: #692

Comment on lines +1502 to +1504
$ reana-client share-add -w myanalysis.42 --user [email protected]

$ reana-client share-add -w myanalysis.42 --user [email protected] --user [email protected] --message "Please review my analysis" --valid-until 2025-12-31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$ reana-client share-add -w myanalysis.42 --user bob@example.org
$ reana-client share-add -w myanalysis.42 --user bob@example.org --user cecile@example.org --message "Please review my analysis" --valid-until 2025-12-31
\t $ reana-client share-add -w myanalysis.42 --user bob@example.org
\t $ reana-client share-add -w myanalysis.42 --user bob@example.org --user cecile@example.org --message "Please review my analysis" --valid-until 2025-12-31

To show the example commands indented when calling reana-client share-add --help

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

The changes were applied to the following superseding PR: #692

share_errors = []
shared_users = []

if workflow:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do if workflow: ... else: display_message(...), as this is already handled by @add_workflow_option. I think there are still some commands that do this, but it's a leftover from the past (that we should probably clean up at some point 😅 )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely spotted. Changed

The changes were applied to the following superseding PR: #692

share_errors.append(
f"Failed to share {workflow} with {user}: {str(e)}"
)
logging.debug(traceback.format_exc())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: You can use logging.exception("... message ...") instead of calling logging.debug manually

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

The changes were applied to the following superseding PR: #692

Comment on lines +1529 to +1535
except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
display_message(
"An error occurred while sharing workflow:\n{}".format(str(e)),
msg_type="error",
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which cases can we end up here? All the exceptions are already caught by the other try ... except block, aren't they?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! Removed it

The changes were applied to the following superseding PR: #692

f"{workflow} is now read-only shared with {', '.join(shared_users)}",
msg_type="success",
)
if share_errors:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check if share_errors: ..., as if the array is empty then the for loop will not do anything

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely spotted. Changed

The changes were applied to the following superseding PR: #692

)
if share_errors:
for error in share_errors:
display_message(error, msg_type="error")
Copy link
Member

@mdonadoni mdonadoni Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are errors (here or before), then reana-client should exit with non-zero exit code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would cancel out any subsequent errors. E.g. imagine someone shares with 20 people at a time where some emails have typos; the current implementation would then show all errors after 1 command execution, while the implementation you suggest requires the user to run the command again after each error to find the next error.

We can still change this if you prefer the latter scenario for a reason that I'm not seeing.

Copy link
Member

@mdonadoni mdonadoni Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's good that the errors are all shown at the end! What I meant was to add something like

if share_errors:
    sys.exit(1)

at the end of the command, so that in case of errors reana-client returns an appropriate status code. No need to call sys.exit just after the error happens.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 👍

help="Optional message that is sent to the user(s) with the sharing invitation.",
)
@click.option(
"-v",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shorthand option -v is normally used for --verbose in other scripts, so I think we should either change it to another letter or even drop the shorthand version. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to allow for --valid-until only, removed the -v shorthand.

The changes were applied to the following superseding PR: #692

@mdonadoni
Copy link
Member

Late comment: JSON output is missing, but if you prefer we can tackle this later on

@DaanRosendal
Copy link
Member Author

@mdonadoni I can not reply directly to your last comment so I'll do it like this.

I created an issue for this so we don't forget about it: #712

@mdonadoni
Copy link
Member

Included in #692

@mdonadoni mdonadoni closed this Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli: implement new share-add command
2 participants