Updated message when user without ~/.tsh logs out (#4200)

* return only trace.NotFound

* supressed error message when user does not have ~/.tsh directory

* return only trace.NotFound

* handled permission issue and file path not found error

* formatting

* nit

* Make milv happy

* Revert "Make milv happy"

This reverts commit 5a24e9f725.

Co-authored-by: Ben Arent <ben@gravitational.com>
This commit is contained in:
quin quintero 2020-09-09 15:44:30 -07:00 committed by GitHub
parent 522443f374
commit dc267752fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View file

@ -510,7 +510,14 @@ func Status(profileDir string, proxyHost string) (*ProfileStatus, []*ProfileStat
profileDir = FullProfilePath(profileDir)
stat, err := os.Stat(profileDir)
if err != nil {
return nil, nil, trace.Wrap(err)
log.Debugf("Failed to stat file: %v.", err)
if os.IsNotExist(err) {
return nil, nil, trace.NotFound(err.Error())
} else if os.IsPermission(err) {
return nil, nil, trace.AccessDenied(err.Error())
} else {
return nil, nil, trace.Wrap(err)
}
}
if !stat.IsDir() {
return nil, nil, trace.BadParameter("profile path not a directory")

View file

@ -153,9 +153,7 @@ func UserMessageFromError(err error) string {
}
if err != nil {
// If the error is a trace error, check if it has a user message embedded in
// it. If a user message is embedded in it, print the user message and the
// original error. Otherwise return the original with a generic "A fatal
// error occurred" message.
// it, if it does, print it, otherwise escape and print the original error.
if er, ok := err.(*trace.TraceErr); ok {
if er.Message != "" {
return fmt.Sprintf("error: %v", EscapeControl(er.Message))

View file

@ -611,6 +611,13 @@ func onLogout(cf *CLIConf) {
// Extract all clusters the user is currently logged into.
active, available, err := client.Status("", "")
if err != nil {
if trace.IsNotFound(err) {
fmt.Printf("All users logged out.\n")
return
} else if trace.IsAccessDenied(err) {
fmt.Printf("%v: Logged in user does not have the correct permissions\n", err)
return
}
utils.FatalError(err)
return
}