github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/logout_command.go (about) 1 package v7 2 3 import ( 4 "github.com/LukasHeimann/cloudfoundrycli/v8/actor/sharedaction" 5 "github.com/LukasHeimann/cloudfoundrycli/v8/actor/v7action" 6 "github.com/LukasHeimann/cloudfoundrycli/v8/command" 7 "github.com/LukasHeimann/cloudfoundrycli/v8/command/v7/shared" 8 "code.cloudfoundry.org/clock" 9 ) 10 11 type LogoutCommand struct { 12 BaseCommand 13 14 usage interface{} `usage:"CF_NAME logout"` 15 } 16 17 func (cmd *LogoutCommand) Setup(config command.Config, ui command.UI) error { 18 cmd.UI = ui 19 cmd.Config = config 20 sharedActor := sharedaction.NewActor(config) 21 cmd.SharedActor = sharedActor 22 23 ccClient, uaaClient, routingClient, _ := shared.GetNewClientsAndConnectToCF(config, ui, "") 24 cmd.cloudControllerClient = ccClient 25 cmd.uaaClient = uaaClient 26 cmd.Actor = v7action.NewActor(ccClient, config, sharedActor, uaaClient, routingClient, clock.NewClock()) 27 return nil 28 } 29 30 func (cmd LogoutCommand) Execute(args []string) error { 31 user, err := cmd.Actor.GetCurrentUser() 32 if err != nil { 33 return err 34 } 35 36 cmd.UI.DisplayTextWithFlavor("Logging out {{.Username}}...", 37 map[string]interface{}{ 38 "Username": user.Name, 39 }) 40 41 cmd.Actor.RevokeAccessAndRefreshTokens() 42 cmd.Config.UnsetUserInformation() 43 cmd.UI.DisplayOK() 44 45 return nil 46 }