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

Adds line to template for custom role annotation #31

Merged
merged 2 commits into from
Feb 15, 2023

Conversation

sarahsimpers
Copy link
Collaborator

@sarahsimpers sarahsimpers commented Feb 8, 2023

Proposed changes

We have info on the roles required for all commands in the OpenAPI spec. When I started the MCLI backfill, I planned to explore ways we might programmatically pull this info in rather than adding it manually.

After some research, it seems that we do need to add the roles manually, but I think that the best way to do this is by standardizing the language at the cobra2snooty template level, adding a new custom annotation for requiredRole to each command, and having the info display for all commands with the annotation after the Long description. This also aligns with a new ask we have this quarter to make sure that all pages for the UI include info on required roles to perform actions.

If we choose to merge this PR, I can add all of the requiredRoles annotations for Atlas commands.

I tested this locally and results display as expected for commands with a requiredRole annotation and don't display for commands without it. See the highlighted line on the attached screenshot for how it displays on an autogenerated docs page.
Screen Shot 2023-02-08 at 6 48 21 AM
Screen Shot 2023-02-08 at 6 52 07 AM

Jira ticket:

N/A

Checklist

  • I have signed the MongoDB CLA
  • [] I have added tests that prove my fix is effective or that my feature works
  • I have added any necessary documentation (if appropriate)
  • [] I have run make fmt and formatted my code

@sarahsimpers
Copy link
Collaborator Author

Hi @melissamahoney-mongodb, I've been thinking about creating a PR to do something like this for a while now, can you please take a look and provide input on whether you think this is a good addition to the template?

@sarahsimpers sarahsimpers marked this pull request as draft February 8, 2023 11:46
@sarahsimpers
Copy link
Collaborator Author

Marked as a draft until I figure out how I can lessen the cyclomatic complexity, since it was already at the max before adding this line.

@sarahsimpers sarahsimpers marked this pull request as ready for review February 8, 2023 13:02
Copy link
Collaborator

@melissamahoney-mongodb melissamahoney-mongodb left a comment

Choose a reason for hiding this comment

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

This is a super cool idea and I'm definitely in favor. One small question, and then I turn it over to tech review for actual thoughts on the Go :)


func requiredRole(buf *bytes.Buffer, cmd *cobra.Command) {
if cmd.Annotations["requiredRole"] != "" {
buf.WriteString("\nTo use this command, the requesting user or API key must have the " + cmd.Annotations["requiredRole"] + " role.\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reading the rest of the long description, everything is framed in the second person. Should we do that here as well?

Suggested change
buf.WriteString("\nTo use this command, the requesting user or API key must have the " + cmd.Annotations["requiredRole"] + " role.\n")
buf.WriteString("\nTo use this command, you must have the " + cmd.Annotations["requiredRole"] + " role.\n")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@melissamahoney-mongodb My concern with this change is that they can be authenticating either using their own user login (via atlas auth login) or with their API key. So there could conceivably be a scenario where their personal user login doesn't have the right permissions, but the API key does (or vice versa), and saying "you" doesn't capture that and might confuse people. What do you think of the following instead?

Suggested change
buf.WriteString("\nTo use this command, the requesting user or API key must have the " + cmd.Annotations["requiredRole"] + " role.\n")
buf.WriteString("\nTo use this command, you must authenticate with a user account or an API key that has the " + cmd.Annotations["requiredRole"] + " role.\n")

It's a little wordy, but I think it clears that up while using the second person.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I like it!

)

func requiredRole(buf *bytes.Buffer, cmd *cobra.Command) {
if cmd.Annotations["requiredRole"] != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

no strong opinion if this is a good idea or not, if this works for docs good for me just a reminder that any metadata added to annotations doesn't reflect in the command help (atlas--help)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oooh good point... I wonder if we could display this inside the long description? Or concatenate them somehow? so that it does show up in the command help. No problem with this merged as-is, but could be a follow-on if we can make it work

@sarahsimpers
Copy link
Collaborator Author

@gssbzn @melissamahoney-mongodb Looks like I don't have merge capabilities on this repo, but since this LGTM for both of you then please merge when you have a chance @gssbzn

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.

3 participants