-
Notifications
You must be signed in to change notification settings - Fork 20
/
dns_add.go
48 lines (39 loc) · 1.16 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
46
47
48
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exo "github.com/exoscale/egoscale/v2"
exoapi "github.com/exoscale/egoscale/v2/api"
)
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(account.CurrentAccount.Environment, account.CurrentAccount.DefaultZone))
decorateAsyncOperation(fmt.Sprintf("Adding DNS record %q to %q...", rType, *domain.UnicodeName), func() {
_, err = globalstate.EgoscaleClient.CreateDNSDomainRecord(ctx, account.CurrentAccount.DefaultZone, *domain.ID, &exo.DNSDomainRecord{
Name: &name,
Type: &rType,
Content: &content,
TTL: &ttl,
Priority: priority,
})
})
if err != nil {
return err
}
if !globalstate.Quiet {
fmt.Printf("Record %q was created successfully to %q\n", rType, *domain.UnicodeName)
}
return nil
}