fly: refactor team verification
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.
@@ -128,24 +128,21 @@ func (command *LoginCommand) Execute(args []string) error {
fmt.Println("")
- err = command.saveTarget(
+ verifyTarget, err := rc.NewAuthenticatedTarget("verify",
client.URL(),
+ command.TeamName,
+ command.Insecure,
&rc.TargetToken{
Type: tokenType,
Value: tokenValue,
},
target.CACert(),
- )
- if err != nil {
- return err
- }
-
- authenticatedTarget, err := rc.LoadTarget(Fly.Target, Fly.Verbose)
+ false)
if err != nil {
return err
}
- userInfo, err := authenticatedTarget.Client().UserInfo()
+ userInfo, err := verifyTarget.Client().UserInfo()
if err != nil {
return err
}
@@ -160,7 +157,14 @@ func (command *LoginCommand) Execute(args []string) error {
return errors.New("unable to verify role on team")
}
- return err
+ return command.saveTarget(
+ client.URL(),
+ &rc.TargetToken{
+ Type: tokenType,
+ Value: tokenValue,
+ },
+ target.CACert(),
+ )
}
func (command *LoginCommand) passwordGrant(client concourse.Client, username, password string) (string, string, error) {
