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

fix: add ability to pass query params to Get() dns resources and records #90

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion api/dns_resource_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (
// DNSResourceRecords is an interface for listing and creaing
// DNSResourceRecord records
type DNSResourceRecords interface {
Get() ([]entity.DNSResourceRecord, error)
Get(params *entity.DNSResourceRecordsParams) ([]entity.DNSResourceRecord, error)
Create(params *entity.DNSResourceRecordParams) (*entity.DNSResourceRecord, error)
}
2 changes: 1 addition & 1 deletion api/dns_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (
// DNSResources is an interface for listing and creating
// DNSResource records
type DNSResources interface {
Get() ([]entity.DNSResource, error)
Get(params *entity.DNSResourcesParams) ([]entity.DNSResource, error)
Create(params *entity.DNSResourceParams) (*entity.DNSResource, error)
}
10 changes: 7 additions & 3 deletions client/dns_resource_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client

import (
"encoding/json"
"net/url"

"github.com/canonical/gomaasclient/entity"
"github.com/google/go-querystring/query"
Expand All @@ -19,9 +18,14 @@ func (d *DNSResourceRecords) client() APIClient {
}

// Get fetches a list of DNSResourceRecord objectts
func (d *DNSResourceRecords) Get() ([]entity.DNSResourceRecord, error) {
func (d *DNSResourceRecords) Get(params *entity.DNSResourceRecordsParams) ([]entity.DNSResourceRecord, error) {
qsp, err := query.Values(params)
if err != nil {
return nil, err
}

dnsResourceRecords := make([]entity.DNSResourceRecord, 0)
err := d.client().Get("", url.Values{}, func(data []byte) error {
err = d.client().Get("", qsp, func(data []byte) error {
return json.Unmarshal(data, &dnsResourceRecords)
})

Expand Down
10 changes: 7 additions & 3 deletions client/dns_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client

import (
"encoding/json"
"net/url"

"github.com/canonical/gomaasclient/entity"
"github.com/google/go-querystring/query"
Expand All @@ -19,9 +18,14 @@ func (d *DNSResources) client() APIClient {
}

// Get fetches a list of DNSResource objects
func (d *DNSResources) Get() ([]entity.DNSResource, error) {
func (d *DNSResources) Get(params *entity.DNSResourcesParams) ([]entity.DNSResource, error) {
qsp, err := query.Values(params)
if err != nil {
return nil, err
}

dnsresources := make([]entity.DNSResource, 0)
err := d.client().Get("", url.Values{}, func(data []byte) error {
err = d.client().Get("", qsp, func(data []byte) error {
return json.Unmarshal(data, &dnsresources)
})

Expand Down
8 changes: 8 additions & 0 deletions entity/dns_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ type DNSResourceParams struct {
IPAddresses string `url:"ip_addresses,omitempty"`
AddressTTL int `url:"address_ttl"`
}

type DNSResourcesParams struct {
Domain string `url:"domain,omitempty"`
FQDN string `url:"fqdn,omitempty"`
Name string `url:"name,omitempty"`
RRType string `url:"rrtype,omitempty"`
All bool `url:"all,omitempty"`
}
7 changes: 7 additions & 0 deletions entity/dns_resource_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ type DNSResourceRecordParams struct {
RRData string `url:"rrdata,omitempty"`
TTL int `url:"ttl"`
}

type DNSResourceRecordsParams struct {
Domain string `url:"domain,omitempty"`
FQDN string `url:"fqdn,omitmepty"`
Name string `url:"name,omitempty"`
RRType string `url:"rrtype,omitempty"`
}
Loading