Skip to content

Commit

Permalink
feat: add database and host name to whoami endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Aug 22, 2023
1 parent abf194a commit e940439
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion auth/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package auth
import (
"fmt"
"net/http"
"net/url"
"os"
"strings"

"github.com/flanksource/incident-commander/api"
Expand Down Expand Up @@ -124,8 +126,18 @@ func WhoAmI(c echo.Context) error {
Message: "Error fetching user",
})
}

hostname, _ := os.Hostname()
var dbName string
if dbURL, err := url.Parse(db.ConnectionString); err == nil {
dbName = strings.TrimPrefix(dbURL.Path, "/")
}
return c.JSON(http.StatusOK, api.HTTPSuccess{
Message: "success",
Payload: user,
Payload: map[string]any{
"user": user,
"hostname": hostname,
"database": dbName,
},
})
}

0 comments on commit e940439

Please sign in to comment.