Skip to content

Commit b4115da

Browse files
committed
add record history api
1 parent 98968c0 commit b4115da

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

vinyldns/endpoints.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ func recordSetChangesEP(c *Client, zoneID string, f ListFilter) string {
7272
return concatStrs("", zoneEP(c, zoneID), "/recordsetchanges", query)
7373
}
7474

75+
func recordSetChangeHistoryListEP(c *Client, f ListRecordHistoryFilter) string {
76+
query := buildRecordHistoryQuery(f)
77+
base := concatStrs("", c.Host, "/recordsetchange/history")
78+
79+
return concatStrs("", base, query)
80+
}
81+
7582
func recordSetChangeEP(c *Client, zoneID, recordSetID, changeID string) string {
7683
return concatStrs("", recordSetEP(c, zoneID, recordSetID), "/changes/", changeID)
7784
}
@@ -133,6 +140,37 @@ func buildQuery(f ListFilter, nameFilterName string) string {
133140
return query + strings.Join(params, "&")
134141
}
135142

143+
func buildRecordHistoryQuery(f ListRecordHistoryFilter) string {
144+
params := []string{}
145+
query := "?"
146+
147+
if f.ZoneId != "" {
148+
params = append(params, fmt.Sprintf("%s=%s", "zoneId", f.ZoneId))
149+
}
150+
151+
if f.Fqdn != "" {
152+
params = append(params, fmt.Sprintf("%s=%s", "fqdn", f.Fqdn))
153+
}
154+
155+
if f.RecordType != "" {
156+
params = append(params, fmt.Sprintf("%s=%s", "recordType", f.RecordType))
157+
}
158+
159+
if f.StartFrom != 0 {
160+
params = append(params, fmt.Sprintf("startFrom=%d", f.StartFrom))
161+
}
162+
163+
if f.MaxItems != 0 {
164+
params = append(params, fmt.Sprintf("maxItems=%d", f.MaxItems))
165+
}
166+
167+
if len(params) == 0 {
168+
query = ""
169+
}
170+
171+
return query + strings.Join(params, "&")
172+
}
173+
136174
func buildGlobalListQuery(f GlobalListFilter) string {
137175
params := []string{}
138176
query := "?"

vinyldns/endpoints_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,38 @@ func TestRecordSetChangesEPWithQuery(t *testing.T) {
251251
}
252252
}
253253

254+
func TestRecordSetChangeHistoryEP(t *testing.T) {
255+
rsc := recordSetChangeHistoryListEP(c, ListRecordHistoryFilter{
256+
ZoneId: "123",
257+
Fqdn: "ok.",
258+
RecordType: "A",
259+
})
260+
expected := "http://host.com/recordsetchange/history?zoneId=123&fqdn=ok.&recordType=A"
261+
262+
if rsc != expected {
263+
fmt.Printf("Expected: %s", expected)
264+
fmt.Printf("Actual: %s", rsc)
265+
t.Error("recordSetChangesEP should return the right endpoint")
266+
}
267+
}
268+
269+
func TestRecordSetChangeHistoryEPWithStartMaxQuery(t *testing.T) {
270+
rsc := recordSetChangeHistoryListEP(c, ListRecordHistoryFilter{
271+
ZoneId: "123",
272+
Fqdn: "ok.",
273+
RecordType: "A",
274+
MaxItems: 3,
275+
StartFrom: 1,
276+
})
277+
expected := "http://host.com/recordsetchange/history?zoneId=123&fqdn=ok.&recordType=A&startFrom=1&maxItems=3"
278+
279+
if rsc != expected {
280+
fmt.Printf("Expected: %s", expected)
281+
fmt.Printf("Actual: %s", rsc)
282+
t.Error("recordSetChangesEP should return the right endpoint")
283+
}
284+
}
285+
254286
func TestRecordSetChangeEP(t *testing.T) {
255287
rsc := recordSetChangeEP(c, "123", "456", "789")
256288
expected := "http://host.com/zones/123/recordsets/456/changes/789"

vinyldns/recordsets.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,17 @@ func (c *Client) RecordSetChanges(zoneID string, f ListFilter) (*RecordSetChange
219219
return rsc, nil
220220
}
221221

222+
// RecordSetChangeHistory retrieves the RecordSetChangeHistory response for that particular record using the ListRecordHistoryFilter passed.
223+
func (c *Client) RecordSetChangeHistory(f ListRecordHistoryFilter) (*RecordSetChangeHistory, error) {
224+
rsc := &RecordSetChangeHistory{}
225+
err := resourceRequest(c, recordSetChangeHistoryListEP(c, f), "GET", nil, rsc)
226+
if err != nil {
227+
return &RecordSetChangeHistory{}, err
228+
}
229+
230+
return rsc, nil
231+
}
232+
222233
// RecordSetChangesListAll retrieves the complete list of record set changes for the Zone ListFilter criteria passed.
223234
// Handles paging through results on the user's behalf.
224235
func (c *Client) RecordSetChangesListAll(zoneID string, filter ListFilter) ([]RecordSetChange, error) {

vinyldns/recordsets_resources.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ type RecordSetChanges struct {
3434
Status string `json:"status,omitempty"`
3535
}
3636

37+
// RecordSetChanges represents a recordset changes response
38+
type RecordSetChangeHistory struct {
39+
RecordSetChanges []RecordSetChange `json:"recordSetChanges"`
40+
ZoneID string `json:"zoneId,omitempty"`
41+
StartFrom int `json:"startFrom,omitempty"`
42+
NextID int `json:"nextId,omitempty"`
43+
MaxItems int `json:"maxItems,omitempty"`
44+
}
45+
3746
// RecordSet represents a DNS record set.
3847
type RecordSet struct {
3948
ID string `json:"id,omitempty"`

vinyldns/resources.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ type ListFilter struct {
5050
MaxItems int
5151
}
5252

53+
// ListRecordHistoryFilter represents the list query parameters that may be passed to
54+
// VinylDNS API endpoint: recordsetchange/history
55+
type ListRecordHistoryFilter struct {
56+
ZoneId string
57+
StartFrom int
58+
MaxItems int
59+
Fqdn string
60+
RecordType string
61+
}
62+
5363
// NameSort specifies the name sort order for record sets returned by the global list record set response.
5464
// Valid values are ASC (ascending; default) and DESC (descending).
5565
type NameSort string

0 commit comments

Comments
 (0)