From 2e0b4726c9f6637b5b687c4862230db4be81ddfa Mon Sep 17 00:00:00 2001 From: Anish Mukherjee Date: Tue, 22 Nov 2022 23:08:18 +0530 Subject: [PATCH] add delete and push dns subcommands --- cli/cmd/dns/delete.go | 20 ++++++++++++++++++++ cli/cmd/dns/push.go | 22 ++++++++++++++++++++++ cli/functions/dns.go | 8 ++++++++ 3 files changed, 50 insertions(+) create mode 100644 cli/cmd/dns/delete.go create mode 100644 cli/cmd/dns/push.go diff --git a/cli/cmd/dns/delete.go b/cli/cmd/dns/delete.go new file mode 100644 index 00000000..ef963ee0 --- /dev/null +++ b/cli/cmd/dns/delete.go @@ -0,0 +1,20 @@ +package dns + +import ( + "github.com/gravitl/netmaker/cli/functions" + "github.com/spf13/cobra" +) + +var dnsDeleteCmd = &cobra.Command{ + Use: "delete [NETWORK NAME] [DOMAIN NAME]", + Args: cobra.ExactArgs(2), + Short: "Delete a DNS entry", + Long: `Delete a DNS entry`, + Run: func(cmd *cobra.Command, args []string) { + functions.PrettyPrint(functions.DeleteDNS(args[0], args[1])) + }, +} + +func init() { + rootCmd.AddCommand(dnsDeleteCmd) +} diff --git a/cli/cmd/dns/push.go b/cli/cmd/dns/push.go new file mode 100644 index 00000000..2fbab191 --- /dev/null +++ b/cli/cmd/dns/push.go @@ -0,0 +1,22 @@ +package dns + +import ( + "fmt" + + "github.com/gravitl/netmaker/cli/functions" + "github.com/spf13/cobra" +) + +var dnsPushCmd = &cobra.Command{ + Use: "push", + Args: cobra.NoArgs, + Short: "Push latest DNS entries", + Long: `Push latest DNS entries`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(*functions.PushDNS()) + }, +} + +func init() { + rootCmd.AddCommand(dnsPushCmd) +} diff --git a/cli/functions/dns.go b/cli/functions/dns.go index 85070bda..fa297159 100644 --- a/cli/functions/dns.go +++ b/cli/functions/dns.go @@ -26,3 +26,11 @@ func GetNetworkDNS(networkName string) *[]models.DNSEntry { func CreateDNS(networkName string, payload *models.DNSEntry) *models.DNSEntry { return request[models.DNSEntry](http.MethodPost, "/api/dns/"+networkName, payload) } + +func PushDNS() *string { + return request[string](http.MethodPost, "/api/dns/adm/pushdns", nil) +} + +func DeleteDNS(networkName, domainName string) *string { + return request[string](http.MethodDelete, fmt.Sprintf("/api/dns/%s/%s", networkName, domainName), nil) +}