Skip to content

Commit

Permalink
Merge pull request #54 from jle64/dont_crash_on_missing_user
Browse files Browse the repository at this point in the history
Show 'n/a' in case of missing information to avoid crashing.
  • Loading branch information
moul authored Mar 14, 2018
2 parents ec1e4d5 + 47a6fc9 commit 09ac2c3
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -1862,9 +1862,15 @@ GLOBAL OPTIONS:
table.SetBorder(false)
table.SetCaption(true, fmt.Sprintf("Total: %d userkeys.", len(userKeys)))
for _, userkey := range userKeys {
var email string
if userkey.User != nil {
email = userkey.User.Email
} else {
email = "n/a"
}
table.Append([]string{
fmt.Sprintf("%d", userkey.ID),
userkey.User.Email,
email,
// FIXME: add fingerprint
humanize.Time(userkey.UpdatedAt),
humanize.Time(userkey.CreatedAt),
Expand Down Expand Up @@ -1961,10 +1967,22 @@ GLOBAL OPTIONS:
duration = humanize.RelTime(session.CreatedAt, *session.StoppedAt, "", "")
}
duration = strings.Replace(duration, "now", "1 second", 1)
var hostname string
if session.Host != nil {
hostname = session.Host.Name
} else {
hostname = "n/a"
}
var username string
if session.User != nil {
username = session.User.Name
} else {
username = "n/a"
}
table.Append([]string{
fmt.Sprintf("%d", session.ID),
session.User.Name,
session.Host.Name,
username,
hostname,
session.Status,
humanize.Time(session.CreatedAt),
duration,
Expand Down

0 comments on commit 09ac2c3

Please sign in to comment.