Browse Source

add delete and push dns subcommands

Anish Mukherjee 2 years ago
parent
commit
2e0b4726c9
3 changed files with 50 additions and 0 deletions
  1. 20 0
      cli/cmd/dns/delete.go
  2. 22 0
      cli/cmd/dns/push.go
  3. 8 0
      cli/functions/dns.go

+ 20 - 0
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)
+}

+ 22 - 0
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)
+}

+ 8 - 0
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)
+}