-
Notifications
You must be signed in to change notification settings - Fork 19
/
dns_add.go
45 lines (37 loc) · 1.02 KB
/
dns_add.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
package cmd
import (
"fmt"
exo "github.com/exoscale/egoscale/v2"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
var dnsAddCmd = &cobra.Command{
Use: "add",
Short: "Add record to domain",
}
func init() {
dnsCmd.AddCommand(dnsAddCmd)
}
func addDomainRecord(domainIdent, name, rType, content string, ttl int64, priority *int64) error {
domain, err := domainFromIdent(domainIdent)
if err != nil {
return err
}
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(gCurrentAccount.Environment, gCurrentAccount.DefaultZone))
decorateAsyncOperation(fmt.Sprintf("Adding DNS record %q to %q...", rType, *domain.UnicodeName), func() {
_, err = cs.CreateDNSDomainRecord(ctx, gCurrentAccount.DefaultZone, *domain.ID, &exo.DNSDomainRecord{
Name: &name,
Type: &rType,
Content: &content,
TTL: &ttl,
Priority: priority,
})
})
if err != nil {
return err
}
if !gQuiet {
fmt.Printf("Record %q was created successfully to %q\n", rType, *domain.UnicodeName)
}
return nil
}