Merge pull request #54 from jle64/dont_crash_on_missing_user

Show 'n/a' in case of missing information to avoid crashing.
This commit is contained in:
Manfred Touron 2018-03-14 18:13:08 +01:00 committed by GitHub
commit 09ac2c35f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1862,9 +1862,15 @@ GLOBAL OPTIONS:
table.SetBorder(false) table.SetBorder(false)
table.SetCaption(true, fmt.Sprintf("Total: %d userkeys.", len(userKeys))) table.SetCaption(true, fmt.Sprintf("Total: %d userkeys.", len(userKeys)))
for _, userkey := range userKeys { for _, userkey := range userKeys {
var email string
if userkey.User != nil {
email = userkey.User.Email
} else {
email = "n/a"
}
table.Append([]string{ table.Append([]string{
fmt.Sprintf("%d", userkey.ID), fmt.Sprintf("%d", userkey.ID),
userkey.User.Email, email,
// FIXME: add fingerprint // FIXME: add fingerprint
humanize.Time(userkey.UpdatedAt), humanize.Time(userkey.UpdatedAt),
humanize.Time(userkey.CreatedAt), humanize.Time(userkey.CreatedAt),
@ -1961,10 +1967,22 @@ GLOBAL OPTIONS:
duration = humanize.RelTime(session.CreatedAt, *session.StoppedAt, "", "") duration = humanize.RelTime(session.CreatedAt, *session.StoppedAt, "", "")
} }
duration = strings.Replace(duration, "now", "1 second", 1) 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{ table.Append([]string{
fmt.Sprintf("%d", session.ID), fmt.Sprintf("%d", session.ID),
session.User.Name, username,
session.Host.Name, hostname,
session.Status, session.Status,
humanize.Time(session.CreatedAt), humanize.Time(session.CreatedAt),
duration, duration,