diff --git a/cli/cmd/ext_client/config.go b/cli/cmd/ext_client/config.go new file mode 100644 index 00000000..ef8e9ea6 --- /dev/null +++ b/cli/cmd/ext_client/config.go @@ -0,0 +1,22 @@ +package ext_client + +import ( + "fmt" + + "github.com/gravitl/netmaker/cli/functions" + "github.com/spf13/cobra" +) + +var extClientConfigCmd = &cobra.Command{ + Use: "config [NETWORK NAME] [EXTERNAL CLIENT ID]", + Args: cobra.ExactArgs(2), + Short: "Get an External Client Configuration", + Long: `Get an External Client Configuration`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(functions.GetExtClientConfig(args[0], args[1])) + }, +} + +func init() { + rootCmd.AddCommand(extClientConfigCmd) +} diff --git a/cli/cmd/ext_client/list.go b/cli/cmd/ext_client/list.go index cd95bcef..e7eb434c 100644 --- a/cli/cmd/ext_client/list.go +++ b/cli/cmd/ext_client/list.go @@ -26,7 +26,7 @@ var extClientListCmd = &cobra.Command{ data = *functions.GetAllExtClients() } table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"ClientID", "Network", "IPv4 Address", "IPv6 Address", "Enabled", "Last Modified"}) + table.SetHeader([]string{"Client ID", "Network", "IPv4 Address", "IPv6 Address", "Enabled", "Last Modified"}) for _, d := range data { table.Append([]string{d.ClientID, d.Network, d.Address, d.Address6, strconv.FormatBool(d.Enabled), time.Unix(d.LastModified, 0).String()}) } diff --git a/cli/cmd/node/list.go b/cli/cmd/node/list.go index b793efd6..c4b66999 100644 --- a/cli/cmd/node/list.go +++ b/cli/cmd/node/list.go @@ -23,7 +23,7 @@ var nodeListCmd = &cobra.Command{ data = *functions.GetNodes() } table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"Node Name", "Addresses", "Version", "Network", "Egress Status", "Ingress Status", "Relay Status"}) + table.SetHeader([]string{"Name", "Addresses", "Version", "Network", "Egress", "Ingress", "Relay", "ID"}) for _, d := range data { addresses := "" if d.Address != "" { @@ -35,7 +35,7 @@ var nodeListCmd = &cobra.Command{ } addresses += d.Address6 } - table.Append([]string{d.Name, addresses, d.Version, d.Network, d.IsEgressGateway, d.IsIngressGateway, d.IsRelay}) + table.Append([]string{d.Name, addresses, d.Version, d.Network, d.IsEgressGateway, d.IsIngressGateway, d.IsRelay, d.ID}) } table.Render() }, diff --git a/cli/functions/ext_client.go b/cli/functions/ext_client.go index c7b30a4d..e9000861 100644 --- a/cli/functions/ext_client.go +++ b/cli/functions/ext_client.go @@ -2,8 +2,11 @@ package functions import ( "fmt" + "io" + "log" "net/http" + "github.com/gravitl/netmaker/cli/config" "github.com/gravitl/netmaker/models" ) @@ -19,8 +22,26 @@ func GetExtClient(networkName, clientID string) *models.ExtClient { return request[models.ExtClient](http.MethodGet, fmt.Sprintf("/api/extclients/%s/%s", networkName, clientID), nil) } -func GetExtClientConfig(networkName, clientID, configType string) *models.ExtClient { - return request[models.ExtClient](http.MethodGet, fmt.Sprintf("/api/extclients/%s/%s/%s", networkName, clientID, configType), nil) +func GetExtClientConfig(networkName, clientID string) string { + ctx := config.GetCurrentContext() + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/api/extclients/%s/%s/file", ctx.Endpoint, networkName, clientID), nil) + if err != nil { + log.Fatal(err) + } + if ctx.MasterKey != "" { + req.Header.Set("Authorization", "Bearer "+ctx.MasterKey) + } else { + req.Header.Set("Authorization", "Bearer "+getAuthToken(ctx)) + } + res, err := http.DefaultClient.Do(req) + if err != nil { + log.Fatal(err) + } + bodyBytes, err := io.ReadAll(res.Body) + if err != nil { + log.Fatal(err) + } + return string(bodyBytes) } func CreateExtClient(networkName, nodeID, extClientID string) {