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 for the v1 alerts api. #244

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.13.0 (Oct 28th, 2024)
## 2.13.0 (Dec 5th, 2024)

FEATURES:

Expand Down
2 changes: 1 addition & 1 deletion mockns1/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type mockAlertListResponse struct {
TotalResults *int64 `json:"total_results,omitempty"`
}

const alertPath = "../alerting/v1beta1/alerts"
const alertPath = "../alerting/v1/alerts"

// AddAlertListTestCase sets up a test case for the api.Client.Alert.List()
// function
Expand Down
10 changes: 7 additions & 3 deletions rest/_examples/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func init() {

func prettyPrint(header string, v interface{}) {
fmt.Println(header)
fmt.Printf("%#v \n", v)
b, _ := json.MarshalIndent(v, "", " ")
fmt.Println(string(b))
}
Expand Down Expand Up @@ -66,6 +65,11 @@ func main() {

z := dns.NewZone(domain)
z.NxTTL = 3600
z.Secondary = &dns.ZoneSecondary{
Enabled: true,
PrimaryIP: "127.0.0.1",
PrimaryPort: 67,
}
_, err = client.Zones.Create(z)
if err != nil {
// Ignore if zone already exists
Expand All @@ -75,10 +79,10 @@ func main() {
log.Println("Zone already exists, continuing...")
}
}

prettyPrint("Zone:", z)
fmt.Printf("Creating alert...\n")

alert := alerting.NewZoneAlert("myalerttest.com - transfer failed", "transfer_failed", []string{webhookList.ID}, []string{domain})
prettyPrint("Creating alert: ", alert)
_, err = client.Alerts.Create(alert)
if err != nil {
if err == api.ErrAlertExists {
Expand Down
2 changes: 1 addition & 1 deletion rest/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type AlertsService service

// The base for the alerting api relative to /v1
// client.NewRequest will call ResolveReference and remove /v1/../
const alertingRelativeBase = "../alerting/v1beta1"
const alertingRelativeBase = "../alerting/v1"

type alertListResponse struct {
Limit *int64 `json:"limit,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion rest/alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestAlert(t *testing.T) {
defer mock.ClearTestCases()

linkHeader := http.Header{}
linkHeader.Set("Link", `</alerting/v1beta1/alerts?next=`+*alertList[1].Name+`>; rel="next"`)
linkHeader.Set("Link", `</alerting/v1/alerts?next=`+*alertList[1].Name+`>; rel="next"`)
require.Nil(t, mock.AddAlertListTestCase("", nil, linkHeader, alertList[0:1]))
require.Nil(t, mock.AddAlertListTestCase("next="+*alertList[1].Name, nil, nil, alertList[2:3]))

Expand Down
4 changes: 2 additions & 2 deletions rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
)

const (
clientVersion = "2.12.2"
clientVersion = "2.13.0"

defaultBase = "http://localhost:80"
defaultBase = "https://api.nsone.net"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change this?

defaultEndpoint = defaultBase + "/v1/"
defaultShouldFollowPagination = true
defaultUserAgent = "go-ns1/" + clientVersion
Expand Down
Loading