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

fly: tell user when team is invalid #5670

Merged
merged 2 commits into from
May 28, 2020
Merged

fly: tell user when team is invalid #5670

merged 2 commits into from
May 28, 2020

Conversation

taylorsilva
Copy link
Member

What does this PR accomplish?

closes #5624

Before 6.1.0 fly would exit 1 and display an error if the user logged in
with an invalid team. This commit brings back this behaviour.

Contributor Checklist

Reviewer Checklist

  • Code reviewed
  • Tests reviewed
  • Documentation reviewed
  • Release notes reviewed
  • PR acceptance performed
  • New config flags added? Ensure that they are added to the
    BOSH and
    Helm packaging; otherwise, ignored for
    the integration
    tests

    (for example, if they are Garden configs that are not displayed in the
    --help text).

@taylorsilva taylorsilva requested review from a team May 26, 2020 20:58
Copy link
Contributor

@aoldershaw aoldershaw left a comment

Choose a reason for hiding this comment

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

Tested it and it seems to work, but the behaviour is a bit different than I would expect.

$ fly -t dev login -c https://127.0.0.1:8080 -u test -p test -n blah
logging in to team 'blah'


target saved
error: you are not a member of 'blah' or the team does not exist

It's weird to say target saved (and to save the target at all) if the team is invalid. What do you think about the following: instead of calling rc.SaveTarget(...) to perform the userInfo check, we instead use rc.NewTarget(...), and only after validating the user is a member of the team do we save the target.


EDIT

Perhaps a better way to do this would be to modify target.Validate() to also perform the user info check, and in fly login call:

target := rc.NewTarget(...)
err := target.Validate()
if err != nil {
  return err
}
err = command.saveTarget(...)
...

This way, we'd also perform the user info check for every command, so if a user is removed from a team, they'd also see an appropriate error message.

@taylorsilva
Copy link
Member Author

@aoldershaw Updated so the target is NOT saved if the user is not on the team/the team doesn't exist.


Perhaps a better way to do this would be to modify target.Validate() to also perform the user info check, and in fly login call:

I joked with @jomsie that this function should really be called ValidateVersion() 😅
I don't want to overload this function with more responsibility. Ideally I'd like to see the API tell us that "hey that team doesn't exist or you're not a member of that team" instead of figuring it out on the client-side with an extra API call. I know the API call to /user is cheap (not as cheap as /info though) but I'd like to avoid making more and more API calls per command.

aoldershaw
aoldershaw previously approved these changes May 28, 2020
Copy link
Contributor

@aoldershaw aoldershaw left a comment

Choose a reason for hiding this comment

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

Logging into an invalid team behaves as expected:

$ fly -t dev login -c https://127.0.0.1:8080 -u test -p test -n blah
logging in to team 'blah'


error: you are not a member of 'blah' or the team does not exist

...as does logging into a valid team:

$ fly -t dev login -c https://127.0.0.1:8080 -u test -p test -n main
logging in to team 'main'


target saved

Looks good!

taylorsilva and others added 2 commits May 28, 2020 09:44
#5624

Before 6.1.0 fly would exit 1 and display an error if the user logged in
with an invalid team. This commit brings back this behaviour.

Signed-off-by: Taylor Silva <[email protected]>
Co-authored-by: James Thomson <[email protected]>
Instead of saving the target and then verifying team membership we
create a NewAuthenticatedTarget() and use it to verify the users
membership on the team. If this check fails then we bail out early and
never save the target.

Signed-off-by: Taylor Silva <[email protected]>
@taylorsilva
Copy link
Member Author

Had to rebase on master to fix release notes conflict. Review again please :)

@jamieklassen
Copy link
Member

merge conflicts in release notes suck

Copy link
Contributor

@aoldershaw aoldershaw left a comment

Choose a reason for hiding this comment

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

Still looks good! (I'm not seeing any changes to the code...let me know if I missed anything)

@scottietremendous scottietremendous added this to the v6.3.0 milestone May 28, 2020
@taylorsilva taylorsilva merged commit 72c7cda into master May 28, 2020
@taylorsilva taylorsilva deleted the issue/5624 branch May 28, 2020 21:09
@taylorsilva taylorsilva added the release/documented Documentation and release notes have been updated. label Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release/documented Documentation and release notes have been updated.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"fly login" no longer validate team
4 participants