From e9404390ffa0e44ce4796de71f274c81ed9db474 Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Tue, 22 Aug 2023 10:09:44 +0530 Subject: [PATCH] feat: add database and host name to whoami endpoint --- auth/controllers.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/auth/controllers.go b/auth/controllers.go index 184571965..afba73849 100644 --- a/auth/controllers.go +++ b/auth/controllers.go @@ -3,6 +3,8 @@ package auth import ( "fmt" "net/http" + "net/url" + "os" "strings" "github.com/flanksource/incident-commander/api" @@ -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, + }, }) }