-
Notifications
You must be signed in to change notification settings - Fork 20
/
dns_remove.go
67 lines (56 loc) · 1.58 KB
/
dns_remove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cmd
import (
"fmt"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
func init() {
dnsRemoveCmd := &cobra.Command{
Use: "remove DOMAIN-NAME|ID RECORD-NAME|ID",
Short: "Remove a domain record",
Aliases: gRemoveAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return cmd.Usage()
}
force, err := cmd.Flags().GetBool("force")
if err != nil {
return err
}
return removeDomainRecord(args[0], args[1], force)
},
}
dnsRemoveCmd.Flags().BoolP("force", "f", false, cmdFlagForceHelp)
dnsCmd.AddCommand(dnsRemoveCmd)
}
func removeDomainRecord(domainIdent, recordIdent string, force bool) error {
domain, err := domainFromIdent(domainIdent)
if err != nil {
return err
}
record, err := domainRecordFromIdent(*domain.ID, recordIdent, nil)
if err != nil {
return err
}
if !force && !askQuestion(fmt.Sprintf("Are you sure you want to delete record %q?", *record.ID)) {
return nil
}
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, account.CurrentAccount.DefaultZone))
decorateAsyncOperation(fmt.Sprintf("Deleting DNS record %q...", *domain.UnicodeName), func() {
err = globalstate.EgoscaleClient.DeleteDNSDomainRecord(
ctx,
account.CurrentAccount.DefaultZone,
*domain.ID,
record,
)
})
if err != nil {
return err
}
if !globalstate.Quiet {
fmt.Printf("Record %q removed successfully from %q\n", *record.ID, *domain.UnicodeName)
}
return nil
}