Skip to content

Commit

Permalink
Add new redirect objects (#226)
Browse files Browse the repository at this point in the history
* PENG-3135: add redirect, fixes

* Change not found handling

* PENG-3135: Update object definitions

* Fix cert pagination, add links to docs

* Use goimports in place of the old golint
  • Loading branch information
fformica authored May 31, 2024
1 parent 942c988 commit a9aa040
Show file tree
Hide file tree
Showing 29 changed files with 1,362 additions and 55 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.11.0 (May 23rd, 2024)

FEATURES:

* Adds support for creating and modifying HTTP/HTTPS redirects

## 2.10.0 (April 18th, 2024)

FEATURES:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fmt:
test:
go fmt ./...
go vet ./...
golint ./...
goimports -w .
go test ./...

.PHONY: all fmt test
3 changes: 2 additions & 1 deletion mockns1/application.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package mockns1

import (
"gopkg.in/ns1/ns1-go.v2/rest/model/pulsar"
"net/http"

"gopkg.in/ns1/ns1-go.v2/rest/model/pulsar"
)

// AddApplicationTestCase sets up a test case for the api.Client.application.List()
Expand Down
67 changes: 67 additions & 0 deletions mockns1/redirect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package mockns1

import (
"net/http"

"gopkg.in/ns1/ns1-go.v2/rest/model/redirect"
)

// AddRedirectListTestCase sets up a test case for the api.Client.Redirects.List()
// function
func (s *Service) AddRedirectListTestCase(
requestHeaders, responseHeaders http.Header,
response *redirect.ConfigurationList,
) error {
return s.AddTestCase(
http.MethodGet, "/redirect", http.StatusOK, requestHeaders,
responseHeaders, "", response,
)
}

// AddRedirectGetTestCase sets up a test case for the api.Client.Redirects.Get()
// function
func (s *Service) AddRedirectGetTestCase(
id string,
requestHeaders, responseHeaders http.Header,
response *redirect.Configuration,
) error {
return s.AddTestCase(
http.MethodGet, "/redirect/"+id, http.StatusOK, requestHeaders,
responseHeaders, "", response,
)
}

// AddRedirectCreateTestCase sets up a test case for the api.Client.Redirects.Create()
// function
func (s *Service) AddRedirectCreateTestCase(
requestHeaders, responseHeaders http.Header,
request, response *redirect.Configuration,
) error {
return s.AddTestCase(
http.MethodPut, "/redirect", http.StatusCreated, requestHeaders,
responseHeaders, request, response,
)
}

// AddRedirectUpdateTestCase sets up a test case for the api.Client.Redirects.Update()
// function
func (s *Service) AddRedirectUpdateTestCase(
requestHeaders, responseHeaders http.Header,
request, response *redirect.Configuration,
) error {
return s.AddTestCase(
http.MethodPost, "/redirect/"+*request.ID, http.StatusOK, requestHeaders,
responseHeaders, request, response,
)
}

// AddRedirectDeleteTestCase sets up a test case for the api.Client.Redirects.Delete()
// function
func (s *Service) AddRedirectDeleteTestCase(
id string, requestHeaders, responseHeaders http.Header,
) error {
return s.AddTestCase(
http.MethodDelete, "/redirect/"+id, http.StatusNoContent, requestHeaders,
responseHeaders, "", "",
)
}
67 changes: 67 additions & 0 deletions mockns1/redirect_certificate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package mockns1

import (
"net/http"

"gopkg.in/ns1/ns1-go.v2/rest/model/redirect"
)

// AddRedirectCertificateListTestCase sets up a test case for the api.Client.RedirectCertificates.List()
// function
func (s *Service) AddRedirectCertificateListTestCase(
requestHeaders, responseHeaders http.Header,
response *redirect.CertificateList,
) error {
return s.AddTestCase(
http.MethodGet, "/redirect/certificates", http.StatusOK, requestHeaders,
responseHeaders, "", response,
)
}

// AddRedirectCertificateGetTestCase sets up a test case for the api.Client.RedirectCertificates.Get()
// function
func (s *Service) AddRedirectCertificateGetTestCase(
id string,
requestHeaders, responseHeaders http.Header,
response *redirect.Certificate,
) error {
return s.AddTestCase(
http.MethodGet, "/redirect/certificates/"+id, http.StatusOK, requestHeaders,
responseHeaders, "", response,
)
}

// AddRedirectCertificateCreateTestCase sets up a test case for the api.Client.RedirectCertificates.Create()
// function
func (s *Service) AddRedirectCertificateCreateTestCase(
requestHeaders, responseHeaders http.Header,
request, response *redirect.Certificate,
) error {
return s.AddTestCase(
http.MethodPut, "/redirect/certificates", http.StatusCreated, requestHeaders,
responseHeaders, request, response,
)
}

// AddRedirectCertificateUpdateTestCase sets up a test case for the api.Client.RedirectCertificates.Update()
// function
func (s *Service) AddRedirectCertificateUpdateTestCase(
requestHeaders, responseHeaders http.Header,
id string, response *redirect.Certificate,
) error {
return s.AddTestCase(
http.MethodPost, "/redirect/certificates/"+id, http.StatusOK, requestHeaders,
responseHeaders, "", response,
)
}

// AddRedirectCertificateDeleteTestCase sets up a test case for the api.Client.RedirectCertificates.Delete()
// function
func (s *Service) AddRedirectCertificateDeleteTestCase(
id string, requestHeaders, responseHeaders http.Header,
) error {
return s.AddTestCase(
http.MethodDelete, "/redirect/certificates/"+id, http.StatusNoContent, requestHeaders,
responseHeaders, "", "",
)
}
3 changes: 2 additions & 1 deletion mockns1/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package mockns1

import (
"fmt"
"gopkg.in/ns1/ns1-go.v2/rest/model/dns"
"net/http"

"gopkg.in/ns1/ns1-go.v2/rest/model/dns"
)

// AddZoneListTestCase sets up a test case for the api.Client.Versions.List()
Expand Down
3 changes: 2 additions & 1 deletion rest/_examples/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package main

import (
"fmt"
"gopkg.in/ns1/ns1-go.v2/rest/model/pulsar"
"log"
"net/http"
"os"
"strconv"
"time"

"gopkg.in/ns1/ns1-go.v2/rest/model/pulsar"

api "gopkg.in/ns1/ns1-go.v2/rest"
)

Expand Down
3 changes: 2 additions & 1 deletion rest/_examples/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package main
import (
"encoding/json"
"fmt"
"gopkg.in/ns1/ns1-go.v2/rest/model/dataset"
"io"
"log"
"net/http"
"os"
"strings"
"time"

"gopkg.in/ns1/ns1-go.v2/rest/model/dataset"

api "gopkg.in/ns1/ns1-go.v2/rest"
)

Expand Down
71 changes: 37 additions & 34 deletions rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"regexp"
Expand All @@ -14,7 +13,7 @@ import (
)

const (
clientVersion = "2.10.0"
clientVersion = "2.11.0"

defaultEndpoint = "https://api.nsone.net/v1/"
defaultShouldFollowPagination = true
Expand Down Expand Up @@ -62,36 +61,38 @@ type Client struct {
common service // Reuse a single struct instead of allocating one for each service on the heap.

// Services used for communicating with different components of the NS1 API.
APIKeys *APIKeysService
DataFeeds *DataFeedsService
DataSources *DataSourcesService
Jobs *JobsService
MonitorRegions *MonitorRegionsService
PulsarJobs *PulsarJobsService
Notifications *NotificationsService
Records *RecordsService
Applications *ApplicationsService
RecordSearch *RecordSearchService
ZoneSearch *ZoneSearchService
Settings *SettingsService
Stats *StatsService
Teams *TeamsService
Users *UsersService
Warnings *WarningsService
Zones *ZonesService
Versions *VersionsService
DNSSEC *DNSSECService
IPAM *IPAMService
ScopeGroup *ScopeGroupService
Scope *ScopeService
Reservation *ReservationService
OptionDef *OptionDefService
TSIG *TsigService
View *DNSViewService
Network *NetworkService
GlobalIPWhitelist *GlobalIPWhitelistService
Datasets *DatasetsService
Activity *ActivityService
APIKeys *APIKeysService
DataFeeds *DataFeedsService
DataSources *DataSourcesService
Jobs *JobsService
MonitorRegions *MonitorRegionsService
PulsarJobs *PulsarJobsService
Notifications *NotificationsService
Records *RecordsService
Applications *ApplicationsService
RecordSearch *RecordSearchService
ZoneSearch *ZoneSearchService
Settings *SettingsService
Stats *StatsService
Teams *TeamsService
Users *UsersService
Warnings *WarningsService
Zones *ZonesService
Versions *VersionsService
DNSSEC *DNSSECService
IPAM *IPAMService
ScopeGroup *ScopeGroupService
Scope *ScopeService
Reservation *ReservationService
OptionDef *OptionDefService
TSIG *TsigService
View *DNSViewService
Network *NetworkService
GlobalIPWhitelist *GlobalIPWhitelistService
Datasets *DatasetsService
Activity *ActivityService
Redirects *RedirectService
RedirectCertificates *RedirectCertificateService
}

// NewClient constructs and returns a reference to an instantiated Client.
Expand Down Expand Up @@ -141,6 +142,8 @@ func NewClient(httpClient Doer, options ...func(*Client)) *Client {
c.GlobalIPWhitelist = (*GlobalIPWhitelistService)(&c.common)
c.Datasets = (*DatasetsService)(&c.common)
c.Activity = (*ActivityService)(&c.common)
c.Redirects = (*RedirectService)(&c.common)
c.RedirectCertificates = (*RedirectCertificateService)(&c.common)

for _, option := range options {
option(c)
Expand Down Expand Up @@ -187,7 +190,7 @@ func SetDDIAPI() func(*Client) {
return func(c *Client) { c.DDI = true }
}

// Param is a container struct which holds a `Key` and `Value` field corresponding to the values of a URL parameter.
// Param is a container struct which holds a `Key` and `Value` field corresponding to the values of a URL parameter.
type Param struct {
Key, Value string
}
Expand Down Expand Up @@ -316,7 +319,7 @@ func CheckResponse(resp *http.Response) error {

restErr := &Error{Resp: resp}

msgBody, err := ioutil.ReadAll(resp.Body)
msgBody, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions rest/dataset_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package rest_test

import (
"net/http"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/ns1/ns1-go.v2/mockns1"
api "gopkg.in/ns1/ns1-go.v2/rest"
"gopkg.in/ns1/ns1-go.v2/rest/model/dataset"
"net/http"
"testing"
)

func TestDatasetsService(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions rest/model/dataset/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package dataset

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var now = time.Unix(time.Now().Unix(), 0)
Expand Down
4 changes: 2 additions & 2 deletions rest/model/dns/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestMarshalRecords(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(result, tt.out) != 0 {
if !bytes.Equal(result, tt.out) {
t.Errorf("got %q, want %q", result, tt.out)
}
})
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestMarshalRecordsOverrideTTL(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(result, tt.out) != 0 {
if !bytes.Equal(result, tt.out) {
t.Errorf("got %q, want %q", result, tt.out)
}
})
Expand Down
3 changes: 2 additions & 1 deletion rest/model/pulsar/application_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package pulsar

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestNewBBPulsarApplication(t *testing.T) {
Expand Down
Loading

0 comments on commit a9aa040

Please sign in to comment.