mirror of
https://github.com/openziti/zrok.git
synced 2025-06-25 04:02:15 +02:00
better default environment description
This commit is contained in:
parent
7f6b54dbc2
commit
23288d38cd
@ -9,10 +9,11 @@ import (
|
|||||||
"github.com/shirou/gopsutil/v3/host"
|
"github.com/shirou/gopsutil/v3/host"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
user2 "os/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
enableCmd.Flags().StringVarP(&enableDescription, "description", "d", "", "Description of this environment")
|
enableCmd.Flags().StringVarP(&enableDescription, "description", "d", "<user>@<hostname>", "Description of this environment")
|
||||||
rootCmd.AddCommand(enableCmd)
|
rootCmd.AddCommand(enableCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,17 +28,25 @@ var enableDescription string
|
|||||||
func enable(_ *cobra.Command, args []string) {
|
func enable(_ *cobra.Command, args []string) {
|
||||||
token := args[0]
|
token := args[0]
|
||||||
|
|
||||||
thisHost, err := getHost()
|
hostName, hostDetail, err := getHost()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
user, err := user2.Current()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
hostDetail = fmt.Sprintf("%v; %v", user.Username, hostDetail)
|
||||||
|
if enableDescription == "<user>@<hostname>" {
|
||||||
|
enableDescription = fmt.Sprintf("%v@%v", user.Username, hostName)
|
||||||
|
}
|
||||||
|
|
||||||
zrok := newZrokClient()
|
zrok := newZrokClient()
|
||||||
auth := httptransport.APIKeyAuth("X-TOKEN", "header", token)
|
auth := httptransport.APIKeyAuth("X-TOKEN", "header", token)
|
||||||
req := identity.NewEnableParams()
|
req := identity.NewEnableParams()
|
||||||
req.Body = &rest_model_zrok.EnableRequest{
|
req.Body = &rest_model_zrok.EnableRequest{
|
||||||
Description: enableDescription,
|
Description: enableDescription,
|
||||||
Host: thisHost,
|
Host: hostDetail,
|
||||||
}
|
}
|
||||||
resp, err := zrok.Identity.Enable(req, auth)
|
resp, err := zrok.Identity.Enable(req, auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -55,12 +64,12 @@ func enable(_ *cobra.Command, args []string) {
|
|||||||
logrus.Infof("enabled, identity = '%v'", resp.Payload.Identity)
|
logrus.Infof("enabled, identity = '%v'", resp.Payload.Identity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHost() (string, error) {
|
func getHost() (string, string, error) {
|
||||||
info, err := host.Info()
|
info, err := host.Info()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
thisHost := fmt.Sprintf("%v; %v; %v; %v; %v; %v; %v",
|
thisHost := fmt.Sprintf("%v; %v; %v; %v; %v; %v; %v",
|
||||||
info.Hostname, info.OS, info.Platform, info.PlatformFamily, info.PlatformVersion, info.KernelVersion, info.KernelArch)
|
info.Hostname, info.OS, info.Platform, info.PlatformFamily, info.PlatformVersion, info.KernelVersion, info.KernelArch)
|
||||||
return thisHost, nil
|
return info.Hostname, thisHost, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user