-
Notifications
You must be signed in to change notification settings - Fork 18
/
dns_records_update.go
71 lines (60 loc) · 1.63 KB
/
dns_records_update.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
68
69
70
71
package cmd
import (
"fmt"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
func init() {
for i := egoscale.A; i <= egoscale.URL; i++ {
recordType := egoscale.Record.String(i)
cmdUpdateRecord := &cobra.Command{
Use: fmt.Sprintf("%s DOMAIN RECORD-NAME|ID", recordType),
Short: fmt.Sprintf("Update %s record type to a domain", recordType),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return cmd.Usage()
}
recordID, err := getRecordIDByName(args[0], args[1])
if err != nil {
return err
}
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
addr, err := cmd.Flags().GetString("content")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.UpdateRecord(gContext, args[0], egoscale.UpdateDNSRecord{
ID: recordID,
DomainID: domain.ID,
TTL: ttl,
RecordType: recordType,
Name: name,
Content: addr,
})
if err != nil {
return err
}
if !gQuiet {
fmt.Printf("Record %q was updated successfully to %q\n", cmd.Name(), args[0])
}
return nil
},
}
cmdUpdateRecord.Flags().StringP("name", "n", "", "Update name")
cmdUpdateRecord.Flags().StringP("content", "c", "", "Update Content")
cmdUpdateRecord.Flags().IntP("ttl", "t", 0, "Update ttl")
cmdUpdateRecord.Flags().IntP("priority", "p", 0, "Update priority")
dnsUpdateCmd.AddCommand(cmdUpdateRecord)
}
}