mirror of
https://github.com/gravitl/netmaker.git
synced 2024-09-20 15:26:04 +08:00
add external client config fetch subcommand
This commit is contained in:
parent
9061c2f26c
commit
db014c93bd
22
cli/cmd/ext_client/config.go
Normal file
22
cli/cmd/ext_client/config.go
Normal file
|
@ -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)
|
||||
}
|
|
@ -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()})
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
},
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue