File: registrar_delegation.go

package info (click to toggle)
golang-github-dnsimple-dnsimple-go 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,428 kB
  • sloc: makefile: 3
file content (85 lines) | stat: -rw-r--r-- 3,101 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package dnsimple

import (
	"context"
	"fmt"
)

// Delegation represents a list of name servers that correspond to a domain delegation.
type Delegation []string

// DelegationResponse represents a response from an API method that returns a delegation struct.
type DelegationResponse struct {
	Response
	Data *Delegation `json:"data"`
}

// VanityDelegationResponse represents a response for vanity name server enable and disable operations.
type VanityDelegationResponse struct {
	Response
	Data []VanityNameServer `json:"data"`
}

// GetDomainDelegation gets the current delegated name servers for the domain.
//
// See https://developer.dnsimple.com/v2/registrar/delegation/#get
func (s *RegistrarService) GetDomainDelegation(ctx context.Context, accountID string, domainName string) (*DelegationResponse, error) {
	path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation", accountID, domainName))
	delegationResponse := &DelegationResponse{}

	resp, err := s.client.get(ctx, path, delegationResponse)
	if err != nil {
		return nil, err
	}

	delegationResponse.HTTPResponse = resp
	return delegationResponse, nil
}

// ChangeDomainDelegation updates the delegated name severs for the domain.
//
// See https://developer.dnsimple.com/v2/registrar/delegation/#get
func (s *RegistrarService) ChangeDomainDelegation(ctx context.Context, accountID string, domainName string, newDelegation *Delegation) (*DelegationResponse, error) {
	path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation", accountID, domainName))
	delegationResponse := &DelegationResponse{}

	resp, err := s.client.put(ctx, path, newDelegation, delegationResponse)
	if err != nil {
		return nil, err
	}

	delegationResponse.HTTPResponse = resp
	return delegationResponse, nil
}

// ChangeDomainDelegationToVanity enables vanity name servers for the given domain.
//
// See https://developer.dnsimple.com/v2/registrar/delegation/#delegateToVanity
func (s *RegistrarService) ChangeDomainDelegationToVanity(ctx context.Context, accountID string, domainName string, newDelegation *Delegation) (*VanityDelegationResponse, error) {
	path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation/vanity", accountID, domainName))
	delegationResponse := &VanityDelegationResponse{}

	resp, err := s.client.put(ctx, path, newDelegation, delegationResponse)
	if err != nil {
		return nil, err
	}

	delegationResponse.HTTPResponse = resp
	return delegationResponse, nil
}

// ChangeDomainDelegationFromVanity disables vanity name servers for the given domain.
//
// See https://developer.dnsimple.com/v2/registrar/delegation/#dedelegateFromVanity
func (s *RegistrarService) ChangeDomainDelegationFromVanity(ctx context.Context, accountID string, domainName string) (*VanityDelegationResponse, error) {
	path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation/vanity", accountID, domainName))
	delegationResponse := &VanityDelegationResponse{}

	resp, err := s.client.delete(ctx, path, nil, nil)
	if err != nil {
		return nil, err
	}

	delegationResponse.HTTPResponse = resp
	return delegationResponse, nil
}