Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to activate and deactivate DNS services for a zone #145

Merged
11 commits merged into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# CHANGELOG

## main

## 1.2.1 (Unreleased)

FEATURES:

- NEW: Added `ActivateZoneDns` to activate DNS services (resolution) for a zone. (dnsimple/dnsimple-go#145)
- NEW: Added `DeactivateZoneDns` to deactivate DNS services (resolution) for a zone. (dnsimple/dnsimple-go#145)

IMPROVEMENTS:

- `EmailForward` `From` is deprecated. Please use `AliasName` instead for creating email forwards. (dnsimple/dnsimple-go#145)
This conversation was marked as resolved.
Show resolved Hide resolved
- `EmailForward` `To` is deprecated. Please use `DestinationEmail` instead for creating email forwards. (dnsimple/dnsimple-go#145)

## 1.2.0

- NEW: Support `GetDomainRegistration` and `GetDomainRenewal` APIs (dnsimple/dnsimple-go#132)
Expand Down
15 changes: 10 additions & 5 deletions dnsimple/domains_email_forwards.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import (

// EmailForward represents an email forward in DNSimple.
type EmailForward struct {
ID int64 `json:"id,omitempty"`
DomainID int64 `json:"domain_id,omitempty"`
ID int64 `json:"id,omitempty"`
DomainID int64 `json:"domain_id,omitempty"`
// For requests, this field is deprecated, please use `AliasName` instead.
From string `json:"from,omitempty"`
This conversation was marked as resolved.
Show resolved Hide resolved
To string `json:"to,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
// WARNING: This is not set in responses, please use `From` instead.
This conversation was marked as resolved.
Show resolved Hide resolved
AliasName string `json:"alias_name,omitempty"`
// Deprecated: please use `DestinationEmail` instead.
To string `json:"to,omitempty"`
DestinationEmail string `json:"destination_email,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}

func emailForwardPath(accountID string, domainIdentifier string, forwardID int64) (path string) {
Expand Down
14 changes: 8 additions & 6 deletions dnsimple/domains_email_forwards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ func TestDomainsService_GetEmailForward(t *testing.T) {
assert.NoError(t, err)
forward := forwardResponse.Data
wantSingle := &EmailForward{
ID: 41872,
DomainID: 235146,
From: "example@dnsimple.xyz",
To: "example@example.com",
CreatedAt: "2021-01-25T13:54:40Z",
UpdatedAt: "2021-01-25T13:54:40Z"}
ID: 41872,
DomainID: 235146,
From: "example@dnsimple.xyz",
AliasName: "",
To: "example@example.com",
DestinationEmail: "example@example.com",
CreatedAt: "2021-01-25T13:54:40Z",
UpdatedAt: "2021-01-25T13:54:40Z"}
assert.Equal(t, wantSingle, forward)
}

Expand Down
32 changes: 32 additions & 0 deletions dnsimple/zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,35 @@ func (s *ZonesService) GetZoneFile(ctx context.Context, accountID string, zoneNa
zoneFileResponse.HTTPResponse = resp
return zoneFileResponse, nil
}

// ActivateDns activates DNS services for a zone.
//
// See https://developer.dnsimple.com/v2/zones/#activateZoneService
func (s *ZonesService) ActivateZoneDns(ctx context.Context, accountID string, zoneName string) (*ZoneResponse, error) {
This conversation was marked as resolved.
Show resolved Hide resolved
path := versioned(fmt.Sprintf("/%v/zones/%v/activation", accountID, zoneName))
zoneResponse := &ZoneResponse{}

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

zoneResponse.HTTPResponse = resp
return zoneResponse, nil
}

// DeactivateDns deactivates DNS services for a zone.
//
// See https://developer.dnsimple.com/v2/zones/#deactivateZoneService
func (s *ZonesService) DeactivateZoneDns(ctx context.Context, accountID string, zoneName string) (*ZoneResponse, error) {
This conversation was marked as resolved.
Show resolved Hide resolved
path := versioned(fmt.Sprintf("/%v/zones/%v/activation", accountID, zoneName))
zoneResponse := &ZoneResponse{}

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

zoneResponse.HTTPResponse = resp
return zoneResponse, nil
}
64 changes: 64 additions & 0 deletions dnsimple/zones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,67 @@ func TestZonesService_GetZoneFile(t *testing.T) {
}
assert.Equal(t, wantSingle, zoneFile)
}

func TestZonesService_ActivateZoneDns(t *testing.T) {
setupMockServer()
defer teardownMockServer()

mux.HandleFunc("/v2/1010/zones/example.com/activation", func(w http.ResponseWriter, r *http.Request) {
httpResponse := httpResponseFixture(t, "/api/activateZoneService/success.http")

testMethod(t, r, "PUT")
testHeaders(t, r)

w.WriteHeader(httpResponse.StatusCode)
_, _ = io.Copy(w, httpResponse.Body)
})

accountID := "1010"
zoneName := "example.com"

zoneResponse, err := client.Zones.ActivateZoneDns(context.Background(), accountID, zoneName)

assert.NoError(t, err)
zone := zoneResponse.Data
wantSingle := &Zone{
ID: 1,
AccountID: 1010,
Name: "example.com",
Reverse: false,
CreatedAt: "2015-04-23T07:40:03Z",
UpdatedAt: "2015-04-23T07:40:03Z",
}
assert.Equal(t, wantSingle, zone)
}

func TestZonesService_DeactivateZoneDns(t *testing.T) {
setupMockServer()
defer teardownMockServer()

mux.HandleFunc("/v2/1010/zones/example.com/activation", func(w http.ResponseWriter, r *http.Request) {
httpResponse := httpResponseFixture(t, "/api/deactivateZoneService/success.http")

testMethod(t, r, "DELETE")
testHeaders(t, r)

w.WriteHeader(httpResponse.StatusCode)
_, _ = io.Copy(w, httpResponse.Body)
})

accountID := "1010"
zoneName := "example.com"

zoneResponse, err := client.Zones.DeactivateZoneDns(context.Background(), accountID, zoneName)

assert.NoError(t, err)
zone := zoneResponse.Data
wantSingle := &Zone{
ID: 1,
AccountID: 1010,
Name: "example.com",
Reverse: false,
CreatedAt: "2015-04-23T07:40:03Z",
UpdatedAt: "2015-04-23T07:40:03Z",
}
assert.Equal(t, wantSingle, zone)
}
16 changes: 16 additions & 0 deletions fixtures.http/api/activateZoneService/success.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 08 Aug 2023 04:19:23 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2399
X-RateLimit-Reset: 1691471963
X-WORK-WITH-US: Love automation? So do we! https://dnsimple.com/jobs
ETag: W/"fe6afd982459be33146933235343d51d"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 8e8ac535-9f46-4304-8440-8c68c30427c3
X-Runtime: 0.176579
Strict-Transport-Security: max-age=63072000

{"data":{"id":1,"account_id":1010,"name":"example.com","reverse":false,"secondary":false,"last_transferred_at":null,"active":true,"created_at":"2015-04-23T07:40:03Z","updated_at":"2015-04-23T07:40:03Z"}}
16 changes: 16 additions & 0 deletions fixtures.http/api/deactivateZoneService/success.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 08 Aug 2023 04:19:52 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2398
X-RateLimit-Reset: 1691471962
X-WORK-WITH-US: Love automation? So do we! https://dnsimple.com/jobs
ETag: W/"5f30a37d01b99bb9e620ef1bbce9a014"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: d2f7bba4-4c81-4818-81d2-c9bbe95f104e
X-Runtime: 0.133278
Strict-Transport-Security: max-age=63072000

{"data":{"id":1,"account_id":1010,"name":"example.com","reverse":false,"secondary":false,"last_transferred_at":null,"active":false,"created_at":"2015-04-23T07:40:03Z","updated_at":"2015-04-23T07:40:03Z"}}
Loading