netmaker/cli/cmd/ext_client/update.go
Matthew R Kasun 78640f1342
Extclient NET-63x (#2286)
* model changes

* additional fields for extclient create

* add DNS to extclient config

* extclient name checks

* update extclient

* nmctl extclient

* final tweaks

* review comments

* add extclientdns to node on ingress creation

* fix to add ingress dns to api (#2296)

---------

Co-authored-by: Aceix <aceixsmartX@gmail.com>
2023-05-17 10:58:03 -04:00

52 lines
1.6 KiB
Go

package ext_client
import (
"encoding/json"
"log"
"os"
"github.com/gravitl/netmaker/cli/functions"
"github.com/gravitl/netmaker/models"
"github.com/spf13/cobra"
)
var (
extClientUpdateFile string
)
var extClientUpdateCmd = &cobra.Command{
Use: "update [NETWORK NAME] [EXTERNAL CLIENT ID]",
Args: cobra.ExactArgs(2),
Short: "Update an External Client",
Long: `Update an External Client`,
Run: func(cmd *cobra.Command, args []string) {
var (
network = args[0]
clientID = args[1]
extClient = &models.CustomExtClient{}
)
if extClientUpdateFile != "" {
content, err := os.ReadFile(extClientUpdateFile)
if err != nil {
log.Fatal("Error when opening file: ", err)
}
if err := json.Unmarshal(content, extClient); err != nil {
log.Fatal(err)
}
} else {
extClient.ClientID = extClientID
extClient.PublicKey = publicKey
extClient.DNS = dns
}
functions.PrettyPrint(functions.UpdateExtClient(network, clientID, extClient))
},
}
func init() {
extClientUpdateCmd.Flags().StringVar(&extClientID, "id", "", "updated ID of the external client")
extClientUpdateCmd.Flags().StringVar(&extClientUpdateFile, "file", "", "Filepath of updated external client definition in JSON")
extClientUpdateCmd.Flags().StringVar(&publicKey, "public_key", "", "updated public key of the external client")
extClientUpdateCmd.Flags().StringVar(&dns, "dns", "", "updated DNS of the external client")
extClientUpdateCmd.Flags().StringSliceVar(&allowedips, "allowedips", []string{}, "updated extra allowed IPs of the external client")
rootCmd.AddCommand(extClientUpdateCmd)
}