-
Notifications
You must be signed in to change notification settings - Fork 175
/
whoami.go
51 lines (48 loc) · 1.32 KB
/
whoami.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package commands
import (
"encoding/json"
"fmt"
"github.com/kubeflow/arena/pkg/apis/arenaclient"
"github.com/kubeflow/arena/pkg/apis/config"
"github.com/kubeflow/arena/pkg/apis/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func NewWhoamiCommand() *cobra.Command {
var command = &cobra.Command{
Use: "whoami",
Short: "Display current user information.",
Long: "Display current user information.",
PreRun: func(cmd *cobra.Command, args []string) {
_ = viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
_, err := arenaclient.NewArenaClient(types.ArenaClientArgs{
Kubeconfig: viper.GetString("config"),
LogLevel: viper.GetString("loglevel"),
Namespace: viper.GetString("namespace"),
ArenaNamespace: viper.GetString("arena-namespace"),
IsDaemonMode: false,
})
if err != nil {
return fmt.Errorf("failed to create arena client: %v", err)
}
user := config.GetArenaConfiger().GetUser()
d, err := json.Marshal(struct {
Name string
Id string
IsAdminUser bool
}{
Name: user.GetName(),
Id: user.GetId(),
IsAdminUser: config.GetArenaConfiger().IsAdminUser(),
})
if err != nil {
return err
}
fmt.Println(string(d))
return nil
},
}
return command
}