rest

package
v2.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 19 Imported by: 222

Documentation

Overview

Package rest defines the api services used to communicate with NS1.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyExists bundles PUT create error.
	ErrKeyExists = errors.New("key already exists")
	// ErrKeyMissing bundles GET/POST/DELETE error.
	ErrKeyMissing = errors.New("key does not exist")
)
View Source
var (
	// ErrTeamExists bundles PUT create error.
	ErrTeamExists = errors.New("team already exists")
	// ErrTeamMissing bundles GET/POST/DELETE error.
	ErrTeamMissing = errors.New("team does not exist")
)
View Source
var (
	// ErrUserExists bundles PUT create error.
	ErrUserExists = errors.New("user already exists")
	// ErrUserMissing bundles GET/POST/DELETE error.
	ErrUserMissing = errors.New("user does not exist")
)
View Source
var (
	// ErrViewExists bundles CREATE error.
	ErrViewExists = errors.New("DNS view already exists")

	// ErrViewExists bundles GET error.
	ErrViewMissing = errors.New("DNS view not found")
)
View Source
var (
	// ErrListExists bundles PUT create error.
	ErrListExists = errors.New("notify List already exists")
	// ErrListMissing bundles GET/POST/DELETE error.
	ErrListMissing = errors.New("notify List does not exist")
)
View Source
var (
	// ErrAppMissing bundles GET/PUT/POST/DELETE
	ErrAppMissing = errors.New("pulsar application does not exist")
	// ErrJobMissing bundles GET/POST/DELETE error.
	ErrJobMissing = errors.New("pulsar job does not exist")
)
View Source
var (
	// ErrRecordExists bundles PUT create error.
	ErrRecordExists = errors.New("record already exists")
	// ErrRecordMissing bundles GET/POST/DELETE error.
	ErrRecordMissing = errors.New("record does not exist")
)
View Source
var (
	// ErrTsigKeyExists bundles PUT create error.
	ErrTsigKeyExists = errors.New("TSIG key already exists")
	// ErrTsigKeyMissing bundles GET/POST/DELETE error.
	ErrTsigKeyMissing = errors.New("TSIG key does not exist")
)
View Source
var (
	// ErrZoneExists bundles PUT create error.
	ErrZoneExists = errors.New("zone already exists")
	// ErrZoneMissing bundles GET/POST/DELETE error.
	ErrZoneMissing = errors.New("zone does not exist")
)
View Source
var (
	// ErrApplicationMissing bundles GET/POST/DELETE error.
	ErrApplicationMissing = errors.New("application does not exist")
)
View Source
var (
	// ErrDNSECNotEnabled if DNSSEC is not enabled for the zone, regardless of
	// account-level DNSSEC permission.
	ErrDNSECNotEnabled = errors.New("DNSSEC is not enabled on the zone")
)

Functions

func CheckResponse

func CheckResponse(resp *http.Response) error

CheckResponse handles parsing of rest api errors. Returns nil if no error.

func SetAPIKey

func SetAPIKey(key string) func(*Client)

SetAPIKey sets a Client instances' APIKey.

func SetBoolParam

func SetBoolParam(key string, b bool) func(*url.Values)

SetBoolParam sets a url boolean query param given the parameters name.

func SetDDIAPI

func SetDDIAPI() func(*Client)

SetDDIAPI configures the client to use permissions compatible with the DDI API.

func SetEndpoint

func SetEndpoint(endpoint string) func(*Client)

SetEndpoint sets a Client instances' Endpoint.

func SetFollowPagination

func SetFollowPagination(shouldFollow bool) func(*Client)

SetFollowPagination sets a Client instances' FollowPagination attribute.

func SetHTTPClient

func SetHTTPClient(httpClient Doer) func(*Client)

SetHTTPClient sets a Client instances' httpClient.

func SetIntParam

func SetIntParam(key string, val int) func(*url.Values)

SetIntParam sets a url integer query param given the parameters name.

func SetRateLimitFunc

func SetRateLimitFunc(ratefunc func(rl RateLimit)) func(*Client)

SetRateLimitFunc sets a Client instances' RateLimitFunc.

func SetStringParam

func SetStringParam(key, val string) func(*url.Values)

SetStringParam sets a url string query param given the parameters name.

func SetTimeParam

func SetTimeParam(key string, t time.Time) func(*url.Values)

SetTimeParam sets a url timestamp query param given the parameters name.

func SetUserAgent

func SetUserAgent(ua string) func(*Client)

SetUserAgent sets a Client instances' user agent.

Types

type APIKeysService

type APIKeysService service

APIKeysService handles 'account/apikeys' endpoint.

func (*APIKeysService) Create

func (s *APIKeysService) Create(a *account.APIKey) (*http.Response, error)

Create takes a *APIKey and creates a new account apikey.

NS1 API docs: https://ns1.com/api/#apikeys-put

func (*APIKeysService) Delete

func (s *APIKeysService) Delete(keyID string) (*http.Response, error)

Delete deletes an apikey.

NS1 API docs: https://ns1.com/api/#apikeys-id-delete

func (*APIKeysService) Get

func (s *APIKeysService) Get(keyID string) (*account.APIKey, *http.Response, error)

Get returns details of an api key, including permissions, for a single API Key. Note: do not use the API Key itself as the keyid in the URL — use the id of the key.

NS1 API docs: https://ns1.com/api/#apikeys-id-get

func (*APIKeysService) List

func (s *APIKeysService) List() ([]*account.APIKey, *http.Response, error)

List returns all api keys in the account.

NS1 API docs: https://ns1.com/api/#apikeys-get

func (*APIKeysService) Update

func (s *APIKeysService) Update(a *account.APIKey) (*http.Response, error)

Update changes the name or access rights for an API Key.

NS1 API docs: https://ns1.com/api/#apikeys-id-post

type ApplicationsService

type ApplicationsService service

ApplicationsService handles 'pulsar/apps/' endpoint.

func (*ApplicationsService) Create

Create takes a *pulsar.Application and creates a new Application.

The given application must have at least the name NS1 API docs: https://ns1.com/api#put-create-a-pulsar-application

func (*ApplicationsService) Delete

func (s *ApplicationsService) Delete(id string) (*http.Response, error)

Delete takes a application Id, and removes an existing application

NS1 API docs: https://ns1.com/api#delete-delete-a-pulsar-application

func (*ApplicationsService) Get

Get takes a application id and returns application struct.

NS1 API docs: https://ns1.com/api#get-list-pulsar-applications

func (*ApplicationsService) List

List returns all pulsar Applications

NS1 API docs: https://ns1.com/api#get-list-pulsar-applications

func (*ApplicationsService) Update

Update takes a *pulsar.Application and updates the application with same id on Ns1.

NS1 API docs: https://ns1.com/api#post-modify-an-application

type Client

type Client struct {

	// NS1 rest endpoint, overrides default if given.
	Endpoint *url.URL

	// NS1 api key (value for http request header 'X-NSONE-Key').
	APIKey string

	// NS1 go rest user agent (value for http request header 'User-Agent').
	UserAgent string

	// Func to call after response is returned in Do
	RateLimitFunc func(RateLimit)

	// Whether the client should handle paginated responses automatically.
	FollowPagination bool

	// Enables permissions compatibility with the DDI API.
	DDI bool

	// Services used for communicating with different components of the NS1 API.
	APIKeys       *APIKeysService
	DataFeeds     *DataFeedsService
	DataSources   *DataSourcesService
	Jobs          *JobsService
	PulsarJobs    *PulsarJobsService
	Notifications *NotificationsService
	Records       *RecordsService
	Applications  *ApplicationsService
	Settings      *SettingsService
	Stats         *StatsService
	Teams         *TeamsService
	Users         *UsersService
	Warnings      *WarningsService
	Zones         *ZonesService
	DNSSEC        *DNSSECService
	IPAM          *IPAMService
	ScopeGroup    *ScopeGroupService
	Scope         *ScopeService
	Reservation   *ReservationService
	OptionDef     *OptionDefService
	TSIG          *TsigService
	View          *DNSViewService
	// contains filtered or unexported fields
}

Client manages communication with the NS1 Rest API.

func NewClient

func NewClient(httpClient Doer, options ...func(*Client)) *Client

NewClient constructs and returns a reference to an instantiated Client.

func (Client) Do

func (c Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do satisfies the Doer interface. resp will be nil if a non-HTTP error occurs, otherwise it is available for inspection when the error reflects a non-2XX response.

func (Client) DoWithPagination

func (c Client) DoWithPagination(req *http.Request, v interface{}, f NextFunc) (*http.Response, error)

DoWithPagination Does, and follows Link headers for pagination. The returned Response is from the last URI visited - either the last page, or one that responded with a non-2XX status. If a non-HTTP error occurs, resp will be nil.

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, body interface{}) (*http.Request, error)

NewRequest constructs and returns a http.Request.

func (*Client) RateLimitStrategyConcurrent

func (c *Client) RateLimitStrategyConcurrent(parallelism int)

RateLimitStrategyConcurrent sleeps for WaitTime * parallelism when remaining is less than or equal to parallelism.

func (*Client) RateLimitStrategySleep

func (c *Client) RateLimitStrategySleep()

RateLimitStrategySleep sets RateLimitFunc to sleep by WaitTimeRemaining

type DNSSECService

type DNSSECService service

DNSSECService handles 'zones/ZONE/dnssec' endpoint.

func (*DNSSECService) Get

func (s *DNSSECService) Get(zone string) (*dns.ZoneDNSSEC, *http.Response, error)

Get takes a zone, and returns DNSSEC information.

NS1 API docs: https://ns1.com/api#get-get-dnssec-details-for-a-zone

type DNSViewService

type DNSViewService service

DNSViewService handles 'views/' endpoint.

func (*DNSViewService) Create

func (s *DNSViewService) Create(v *dns.DNSView) (*http.Response, error)

Create takes a *dns.DNSView and creates a new DNS View.

The given DNSView must have at least the name NS1 API docs: https://ns1.com/api#putcreate-a-dns-view

func (*DNSViewService) Delete

func (s *DNSViewService) Delete(viewName string) (*http.Response, error)

Delete takes a DNS view name, and removes an existing DNS view

NS1 API docs: https://ns1.com/api#deletedelete-a-dns-view

func (*DNSViewService) Get

func (s *DNSViewService) Get(viewName string) (*dns.DNSView, *http.Response, error)

Get takes a DNS view name and returns DNSView struct.

NS1 API docs: https://ns1.com/api#getview-dns-view-details

func (*DNSViewService) GetPreferences

func (s *DNSViewService) GetPreferences() (map[string]int, *http.Response, error)

GetPreference returns a map[string]int of preferences.

NS1 API docs: https://ns1.com/api#getget-dns-view-preference

func (*DNSViewService) List

func (s *DNSViewService) List() ([]*dns.DNSView, *http.Response, error)

List returns all DNS Views

NS1 API docs: https://ns1.com/api#getlist-all-dns-views

func (*DNSViewService) Update

func (s *DNSViewService) Update(v *dns.DNSView) (*http.Response, error)

Update takes a *dns.DNSView and updates the DNS view with same name on NS1.

NS1 API docs: https://ns1.com/api#postedit-a-dns-view

func (*DNSViewService) UpdatePreferences

func (s *DNSViewService) UpdatePreferences(m map[string]int) (map[string]int, *http.Response, error)

UpdatePreference takes a map[string]int and returns a map[string]int of preferences.

NS1 API docs: https://ns1.com/api#postedit-dns-view-preference

type DataFeedsService

type DataFeedsService service

DataFeedsService handles 'data/feeds' endpoint.

func (*DataFeedsService) Create

func (s *DataFeedsService) Create(sourceID string, df *data.Feed) (*http.Response, error)

Create takes a *DataFeed and connects a new data feed to an existing data source.

NS1 API docs: https://ns1.com/api/#feeds-put

func (*DataFeedsService) Delete

func (s *DataFeedsService) Delete(sourceID string, feedID string) (*http.Response, error)

Delete takes a data source ID and a data feed ID and disconnects the feed from the data source and all attached destination metadata tables.

NS1 API docs: https://ns1.com/api/#feeds-delete

func (*DataFeedsService) Get

func (s *DataFeedsService) Get(sourceID string, feedID string) (*data.Feed, *http.Response, error)

Get takes a data source ID and a data feed ID and returns the details of a single data feed

NS1 API docs: https://ns1.com/api/#feeds-feed-get

func (*DataFeedsService) List

func (s *DataFeedsService) List(sourceID string) ([]*data.Feed, *http.Response, error)

List returns all data feeds connected to a given data source.

NS1 API docs: https://ns1.com/api/#feeds-get

func (*DataFeedsService) Update

func (s *DataFeedsService) Update(sourceID string, df *data.Feed) (*http.Response, error)

Update takes a *Feed and modifies and existing data feed. Note:

  • The 'data' portion of a feed does not actually get updated during a POST. In order to update a feeds' 'data' attribute, one must use the Publish method.
  • Both the 'destinations' and 'networks' attributes are not updated during a POST.

NS1 API docs: https://ns1.com/api/#feeds-post

type DataSourcesService

type DataSourcesService service

DataSourcesService handles 'data/sources' endpoint.

func (*DataSourcesService) Create

func (s *DataSourcesService) Create(ds *data.Source) (*http.Response, error)

Create takes a *DataSource and creates a new data source.

NS1 API docs: https://ns1.com/api/#sources-put

func (*DataSourcesService) Delete

func (s *DataSourcesService) Delete(id string) (*http.Response, error)

Delete takes an ID and removes an existing data source and all connected feeds from the source.

NS1 API docs: https://ns1.com/api/#sources-delete

func (*DataSourcesService) Get

Get takes an ID returns the details for a single data source.

NS1 API docs: https://ns1.com/api/#sources-source-get

func (*DataSourcesService) List

func (s *DataSourcesService) List() ([]*data.Source, *http.Response, error)

List returns all connected data sources.

NS1 API docs: https://ns1.com/api/#sources-get

func (*DataSourcesService) Publish

func (s *DataSourcesService) Publish(dsID string, data interface{}) (*http.Response, error)

Publish takes a datasources' id and data to publish.

NS1 API docs: https://ns1.com/api/#feed-post

func (*DataSourcesService) Update

func (s *DataSourcesService) Update(ds *data.Source) (*http.Response, error)

Update takes a *DataSource modifies basic details of a data source. NOTE: This does not 'publish' data. See the Publish method.

NS1 API docs: https://ns1.com/api/#sources-post

type Decorator

type Decorator func(Doer) Doer

A Decorator wraps a Doer with extra behavior, and doesnt affect the behavior of other instances of the same type.

func Logging

func Logging(l *log.Logger) Decorator

Logging returns a Decorator that logs a Doer's requests. Dependency injection for the logger instance(inside the closures environment).

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

Doer is a single method interface that allows a user to extend/augment an http.Client instance. Note: http.Client satisfies the Doer interface.

func Decorate

func Decorate(d Doer, ds ...Decorator) Doer

Decorate decorates a Doer c with all the given Decorators, in order. Core object(Doer instance) that we want to apply layers(Decorator slice) to.

type DoerFunc

type DoerFunc func(*http.Request) (*http.Response, error)

DoerFunc satisfies Interface. DoerFuncs are useful for adding logging/instrumentation to the http.Client that is used within the rest.APIClient.

func (DoerFunc) Do

func (f DoerFunc) Do(r *http.Request) (*http.Response, error)

Do is implementation of rest.Doer interface. Calls itself on the given http.Request.

type Error

type Error struct {
	Resp    *http.Response
	Message string
}

Error contains all http responses outside the 2xx range.

func (*Error) Error

func (re *Error) Error() string

Satisfy std lib error interface.

type IPAMService

type IPAMService service

IPAMService handles the 'ipam' endpoint.

func (*IPAMService) CreateSubnet

func (s *IPAMService) CreateSubnet(addr *ipam.Address) (*ipam.Address, *http.Response, error)

CreateSubnet creates an address or subnet. The Prefix and Network fields are required.

NS1 API docs: https://ns1.com/api#putcreate-a-subnet

func (*IPAMService) DeleteSubnet

func (s *IPAMService) DeleteSubnet(id int) (*http.Response, error)

DeleteSubnet removes a subnet entirely.

NS1 API docs: https://ns1.com/api#deletedelete-a-subnet

func (*IPAMService) EditSubnet

func (s *IPAMService) EditSubnet(addr *ipam.Address, parent bool) (newAddr, parentAddr *ipam.Address, resp *http.Response, err error)

EditSubnet updates an existing subnet. The ID field is required. Parent is whether or not to include the parent in the parent field.

NS1 API docs: https://ns1.com/api#postedit-a-subnet

func (*IPAMService) GetChildren

func (s *IPAMService) GetChildren(addrID int) ([]*ipam.Address, *http.Response, error)

GetChildren requests a list of all child addresses (or subnets) for the specified IP address.

NS1 API docs: https://ns1.com/api#getview-address-children

func (*IPAMService) GetParent

func (s *IPAMService) GetParent(addrID int) (*ipam.Address, *http.Response, error)

GetParent fetches the addresses parent.

NS1 API docs: https://ns1.com/api#getview-address-parent

func (*IPAMService) GetSubnet

func (s *IPAMService) GetSubnet(addrID int) (*ipam.Address, *http.Response, error)

GetSubnet returns the subnet corresponding to the provided address ID.

NS1 API docs: https://ns1.com/api#getview-a-subnet

func (*IPAMService) ListAddrs

func (s *IPAMService) ListAddrs() ([]ipam.Address, *http.Response, error)

ListAddrs returns a list of all root addresses (i.e. Parent == 0) in all networks.

NS1 API docs: https://ns1.com/api#getview-a-list-of-root-addresses

func (*IPAMService) MergeSubnet

func (s *IPAMService) MergeSubnet(rootID, mergeID int) (*ipam.Address, *http.Response, error)

MergeSubnet merges several subnets together.

NS1 API docs: https://ns1.com/api#postmerge-a-subnet

func (*IPAMService) SplitSubnet

func (s *IPAMService) SplitSubnet(id, prefix int) (rootAddr int, prefixIDs []int, resp *http.Response, err error)

SplitSubnet splits a block of unassigned IP space into equal pieces. This will not function with ranges or individual hosts. Normal breaking out of a subnet is done with the standard PUT route. (Eg. root address is a /24 and request for /29s will break it into 32 /29s)

  • Only planned subnets can be split
  • Name and description will be unset on children
  • KVPS and options will be copied; tags will be inherited

NS1 API docs: https://ns1.com/api#postsplit-a-subnet

type JobsService

type JobsService service

JobsService handles 'monitoring/jobs' endpoint.

func (*JobsService) Create

func (s *JobsService) Create(mj *monitor.Job) (*http.Response, error)

Create takes a *MonitoringJob and creates a new monitoring job.

NS1 API docs: https://ns1.com/api/#jobs-put

func (*JobsService) Delete

func (s *JobsService) Delete(id string) (*http.Response, error)

Delete takes an ID and immediately terminates and deletes and existing monitoring job.

NS1 API docs: https://ns1.com/api/#jobs-jobid-delete

func (*JobsService) Get

func (s *JobsService) Get(id string) (*monitor.Job, *http.Response, error)

Get takes an ID and returns details for a specific monitoring job.

NS1 API docs: https://ns1.com/api/#jobs-jobid-get

func (*JobsService) History

func (s *JobsService) History(id string, opts ...func(*url.Values)) ([]*monitor.StatusLog, *http.Response, error)

History takes an ID and returns status log history for a specific monitoring job.

NS1 API docs: https://ns1.com/api/#history-get

func (*JobsService) List

func (s *JobsService) List() ([]*monitor.Job, *http.Response, error)

List returns all monitoring jobs for the account.

NS1 API docs: https://ns1.com/api/#jobs-get

func (*JobsService) Update

func (s *JobsService) Update(mj *monitor.Job) (*http.Response, error)

Update takes a *MonitoringJob and change the configuration details of an existing monitoring job.

NS1 API docs: https://ns1.com/api/#jobs-jobid-post

type Link struct {
	URI   string
	Rel   string
	Extra map[string]string
}

Link has a URI and its relation (next/prev/last/etc)

type Links map[string]*Link

Links represents a Link Header, keyed by the Rel attribute

func ParseLink(s string, forceHTTPS bool) Links

ParseLink parses a Link header value into a Links, mainly cribbed from: https://github.com/peterhellberg/link/blob/master/link.go The forceHTTPS parameter will rewrite any HTTP URLs it finds to HTTPS.

func (Links) Next

func (l Links) Next() string

Next gets the URI for "next", if present

type NextFunc

type NextFunc func(v *interface{}, uri string) (*http.Response, error)

NextFunc knows how to get and parse additional info from uri into v.

type NotificationsService

type NotificationsService service

NotificationsService handles 'monitoring/lists' endpoint.

func (*NotificationsService) Create

Create takes a *NotifyList and creates a new notify list.

NS1 API docs: https://ns1.com/api/#lists-put

func (*NotificationsService) Delete

func (s *NotificationsService) Delete(listID string) (*http.Response, error)

Delete immediately deletes an existing notification list.

NS1 API docs: https://ns1.com/api/#lists-listid-delete

func (*NotificationsService) Get

Get returns the details and notifiers associated with a specific notification list.

NS1 API docs: https://ns1.com/api/#lists-listid-get

func (*NotificationsService) List

List returns all configured notification lists.

NS1 API docs: https://ns1.com/api/#lists-get

func (*NotificationsService) Update

Update adds or removes entries or otherwise update a notification list.

NS1 API docs: https://ns1.com/api/#list-listid-post

type OptionDefService

type OptionDefService service

OptionDefService handles the 'scope group' endpoints.

func (*OptionDefService) Create

func (s *OptionDefService) Create(od *dhcp.OptionDef, odSpace, odKey string) (*dhcp.OptionDef, *http.Response, error)

Create creates or updates an option definition. The FriendlyName, Description, Code, Schema.Type fields are required.

NS1 API docs: https://ns1.com/api#putcreate-an-custom-dhcp-option-definition

func (*OptionDefService) Delete

func (s *OptionDefService) Delete(odSpace, odKey string) (*http.Response, error)

Delete removes a option definition entirely.

NS1 API docs: https://ns1.com/api#deletedelete-a-custom-dhcp-option-definition

func (*OptionDefService) Get

func (s *OptionDefService) Get(odSpace, odKey string) (*dhcp.OptionDef, *http.Response, error)

Get returns the option definition corresponding to the provided ID.

NS1 API docs: https://ns1.com/api#getview-dhcp-option-definition

func (*OptionDefService) List

func (s *OptionDefService) List() ([]dhcp.OptionDef, *http.Response, error)

List returns a list of all option definitions.

NS1 API docs: https://ns1.com/api#getlist-dhcp-option-definitions

type PulsarJobsService

type PulsarJobsService service

JobsService handles 'pulsar/apps/APPID/jobs/JOBID' endpoint.

func (*PulsarJobsService) Create

Create takes a *PulsarJob and an AppId and creates a new Pulsar Job in the specified Application with the specific name, typeid, host and url_path.

NS1 API docs: https://ns1.com/api/#putcreate-a-pulsar-job

func (*PulsarJobsService) Delete

func (s *PulsarJobsService) Delete(pulsarJob *pulsar.PulsarJob) (*http.Response, error)

Delete takes a appId and jobId and removes an existing Pulsar job .

NS1 API docs: https://ns1.com/api/#deletedelete-a-pulsar-job

func (*PulsarJobsService) Get

func (s *PulsarJobsService) Get(appId string, jobId string) (*pulsar.PulsarJob, *http.Response, error)

Get takes an Application ID and Job Id and returns full configuration for a pulsar Job.

NS1 API docs: https://ns1.com/api/#getview-job-details

func (*PulsarJobsService) List

func (s *PulsarJobsService) List(appId string) ([]*pulsar.PulsarJob, *http.Response, error)

List takes an Application ID and returns all Jobs inside said Application.

NS1 API docs: https://ns1.com/api/#getlist-jobs-within-an-app

func (*PulsarJobsService) Update

Update takes a *PulsarJob and modifies configuration details for an existing Pulsar job.

Only the fields to be updated are required in the given job. NS1 API docs: https://ns1.com/api/#postmodify-a-pulsar-job

type RateLimit

type RateLimit struct {
	Limit     int
	Remaining int
	Period    int
}

RateLimit stores X-Ratelimit-* headers

func (RateLimit) PercentageLeft

func (rl RateLimit) PercentageLeft() int

PercentageLeft returns the ratio of Remaining to Limit as a percentage

func (RateLimit) WaitTime

func (rl RateLimit) WaitTime() time.Duration

WaitTime returns the time.Duration ratio of Period to Limit

func (RateLimit) WaitTimeRemaining

func (rl RateLimit) WaitTimeRemaining() time.Duration

WaitTimeRemaining returns the time.Duration ratio of Period to Remaining

type RateLimitFunc

type RateLimitFunc func(RateLimit)

RateLimitFunc is rate limiting strategy for the Client instance.

type RecordsService

type RecordsService service

RecordsService handles 'zones/ZONE/DOMAIN/TYPE' endpoint.

func (*RecordsService) Create

func (s *RecordsService) Create(r *dns.Record) (*http.Response, error)

Create takes a *Record and creates a new DNS record in the specified zone, for the specified domain, of the given record type.

The given record must have at least one answer. NS1 API docs: https://ns1.com/api/#record-put

func (*RecordsService) Delete

func (s *RecordsService) Delete(zone string, domain string, t string) (*http.Response, error)

Delete takes a zone, domain and record type t and removes an existing record and all associated answers and configuration details.

NS1 API docs: https://ns1.com/api/#record-delete

func (*RecordsService) Get

func (s *RecordsService) Get(zone, domain, t string) (*dns.Record, *http.Response, error)

Get takes a zone, domain and record type t and returns full configuration for a DNS record.

NS1 API docs: https://ns1.com/api/#record-get

func (*RecordsService) Update

func (s *RecordsService) Update(r *dns.Record) (*http.Response, error)

Update takes a *Record and modifies configuration details for an existing DNS record.

Only the fields to be updated are required in the given record. NS1 API docs: https://ns1.com/api/#record-post

type ReservationService

type ReservationService service

ReservationService handles the 'reservation' endpoints.

func (*ReservationService) Create

Create creates a reservation. The Options field is required.

NS1 API docs: https://ns1.com/api#putcreate-a-reservation

func (*ReservationService) Delete

func (s *ReservationService) Delete(id int) (*http.Response, error)

Delete removes a reservation entirely.

NS1 API docs: https://ns1.com/api#deletedelete-a-reservation

func (*ReservationService) Edit

Edit updates an existing reservation. The ID, Options fields are required.

NS1 API docs: https://ns1.com/api#postmodify-a-reservation

func (*ReservationService) Get

Get returns the reservation corresponding to the provided reservation ID.

NS1 API docs: https://ns1.com/api#getview-a-reservations-details

func (*ReservationService) List

List returns a list of all reservations.

NS1 API docs: https://ns1.com/api#getlist-reservations

type Response

type Response struct {
	*http.Response
}

Response wraps stdlib http response.

type ScopeGroupService

type ScopeGroupService service

ScopeGroupService handles the 'scope group' endpoints.

func (*ScopeGroupService) Create

Create creates a scope group. The Name field is required.

NS1 API docs: https://ns1.com/api#putcreate-a-scope-group

func (*ScopeGroupService) Delete

func (s *ScopeGroupService) Delete(id int) (*http.Response, error)

Delete removes a Scope Group entirely.

NS1 API docs: https://ns1.com/api#deleteremove-scope-group-by-id

func (*ScopeGroupService) Edit

Edit updates an existing scope group. The ID field is required.

NS1 API docs: https://ns1.com/api#postedit-scope-group

func (*ScopeGroupService) Get

func (s *ScopeGroupService) Get(sgID int) (*dhcp.ScopeGroup, *http.Response, error)

Get returns the Scope Group corresponding to the provided scope group ID.

NS1 API docs: https://ns1.com/api#getview-scope-group

func (*ScopeGroupService) List

List returns a list of all scope groups.

NS1 API docs: https://ns1.com/api#getlist-scope-groups

type ScopeService

type ScopeService service

ScopeService handles the 'scope' endpoints.

func (*ScopeService) Create

func (s *ScopeService) Create(sc *dhcp.Scope) (*dhcp.Scope, *http.Response, error)

Create creates a scope. The IDAddress field is required.

NS1 API docs: https://ns1.com/api#putcreate-a-scope

func (*ScopeService) Delete

func (s *ScopeService) Delete(id int) (*http.Response, error)

Delete removes a scope entirely.

NS1 API docs: https://ns1.com/api#deleteremove-a-scope

func (*ScopeService) Edit

func (s *ScopeService) Edit(sc *dhcp.Scope) (*dhcp.Scope, *http.Response, error)

Edit updates an existing scope. The IDAddress field is required.

NS1 API docs: https://ns1.com/api#postmodify-a-scope

func (*ScopeService) Get

func (s *ScopeService) Get(scID int) (*dhcp.Scope, *http.Response, error)

Get returns the scope corresponding to the provided scope ID.

NS1 API docs: https://ns1.com/api#getview-scope-details

func (*ScopeService) List

func (s *ScopeService) List() ([]dhcp.Scope, *http.Response, error)

List returns a list of all scopes.

NS1 API docs: https://ns1.com/api#getlist-scopes

type SettingsService

type SettingsService service

SettingsService handles 'account/settings' endpoint.

func (*SettingsService) Get

Get returns the basic contact details associated with the account.

NS1 API docs: https://ns1.com/api/#settings-get

func (*SettingsService) Update

func (s *SettingsService) Update(us *account.Setting) (*http.Response, error)

Update changes most of the basic contact details, except customerid.

NS1 API docs: https://ns1.com/api/#settings-post

type StatsService

type StatsService service

StatsService handles 'stats/qps' endpoint.

func (*StatsService) GetQPS

func (s *StatsService) GetQPS() (float32, *http.Response, error)

GetQPS returns current queries per second (QPS) for the account. The QPS number is lagged by approximately 30 seconds for statistics collection; and the rate is computed over the preceding minute.

func (*StatsService) GetRecordQPS

func (s *StatsService) GetRecordQPS(zone, record, t string) (float32, *http.Response, error)

GetRecordQPS returns current queries per second (QPS) for a specific record. The QPS number is lagged by approximately 30 seconds for statistics collection; and the rate is computed over the preceding minute.

func (*StatsService) GetZoneQPS

func (s *StatsService) GetZoneQPS(zone string) (float32, *http.Response, error)

GetZoneQPS returns current queries per second (QPS) for a specific zone. The QPS number is lagged by approximately 30 seconds for statistics collection; and the rate is computed over the preceding minute.

type TeamsService

type TeamsService service

TeamsService handles 'account/teams' endpoint.

func (*TeamsService) Create

func (s *TeamsService) Create(t *account.Team) (*http.Response, error)

Create takes a *Team and creates a new account team.

NS1 API docs: https://ns1.com/api/#teams-put

func (*TeamsService) Delete

func (s *TeamsService) Delete(id string) (*http.Response, error)

Delete deletes a team.

NS1 API docs: https://ns1.com/api/#teams-id-delete

func (*TeamsService) Get

func (s *TeamsService) Get(id string) (*account.Team, *http.Response, error)

Get returns details of a single team.

NS1 API docs: https://ns1.com/api/#teams-id-get

func (*TeamsService) List

func (s *TeamsService) List() ([]*account.Team, *http.Response, error)

List returns all teams in the account.

NS1 API docs: https://ns1.com/api/#teams-get

func (*TeamsService) Update

func (s *TeamsService) Update(t *account.Team) (*http.Response, error)

Update changes the name or access rights for a team.

NS1 API docs: https://ns1.com/api/#teams-id-post

type TsigService

type TsigService service

TsigService handles 'tsig' endpoint.

func (*TsigService) Create

func (s *TsigService) Create(tk *dns.TSIGKey) (*http.Response, error)

Create takes a *TSIGkey and creates a new TSIG key.

NS1 API docs: https://ns1.com/api/#putcreate-a-tsig-key

func (*TsigService) Delete

func (s *TsigService) Delete(name string) (*http.Response, error)

Delete takes a TSIG key name and destroys an existing TSIG key.

NS1 API docs: https://ns1.com/api/#deleteremove-a-tsig-key

func (*TsigService) Get

func (s *TsigService) Get(name string) (*dns.TSIGKey, *http.Response, error)

Get takes a TSIG key name and returns a single TSIG key and its basic configuration details.

NS1 API docs: https://ns1.com/api/#getview-tsig-key-details

func (*TsigService) List

func (s *TsigService) List() ([]*dns.TSIGKey, *http.Response, error)

List returns all tsig keys and basic tsig keys configuration details for each.

NS1 API docs: https://ns1.com/api/#getlist-tsig-keys

func (*TsigService) Update

func (s *TsigService) Update(tk *dns.TSIGKey) (*http.Response, error)

Update takes a *TSIGKey and modifies basic details of a TSIG key.

NS1 API docs: https://ns1.com/api/#postmodify-a-tsig-key

type UsersService

type UsersService service

UsersService handles 'account/users' endpoint.

func (*UsersService) Create

func (s *UsersService) Create(u *account.User) (*http.Response, error)

Create takes a *User and creates a new account user.

NS1 API docs: https://ns1.com/api/#users-put

func (*UsersService) Delete

func (s *UsersService) Delete(username string) (*http.Response, error)

Delete deletes a user.

NS1 API docs: https://ns1.com/api/#users-user-delete

func (*UsersService) Get

func (s *UsersService) Get(username string) (*account.User, *http.Response, error)

Get returns details of a single user.

NS1 API docs: https://ns1.com/api/#users-user-get

func (*UsersService) List

func (s *UsersService) List() ([]*account.User, *http.Response, error)

List returns all users in the account.

NS1 API docs: https://ns1.com/api/#users-get

func (*UsersService) Update

func (s *UsersService) Update(u *account.User) (*http.Response, error)

Update change contact details, notification settings, or access rights for a user.

NS1 API docs: https://ns1.com/api/#users-user-post

type WarningsService

type WarningsService service

WarningsService handles 'account/usagewarnings' endpoint.

func (*WarningsService) Get

Get returns toggles and thresholds used when sending overage warning alert messages to users with billing notifications enabled.

NS1 API docs: https://ns1.com/api/#usagewarnings-get

func (*WarningsService) Update

Update changes alerting toggles and thresholds for overage warning alert messages.

NS1 API docs: https://ns1.com/api/#usagewarnings-post

type ZonesService

type ZonesService service

ZonesService handles 'zones' endpoint.

func (*ZonesService) Create

func (s *ZonesService) Create(z *dns.Zone) (*http.Response, error)

Create takes a *Zone and creates a new DNS zone.

NS1 API docs: https://ns1.com/api/#zones-put

func (*ZonesService) Delete

func (s *ZonesService) Delete(zone string) (*http.Response, error)

Delete takes a zone and destroys an existing DNS zone and all records in the zone.

NS1 API docs: https://ns1.com/api/#zones-delete

func (*ZonesService) Get

func (s *ZonesService) Get(zone string) (*dns.Zone, *http.Response, error)

Get takes a zone name and returns a single active zone and its basic configuration details.

NS1 API docs: https://ns1.com/api/#zones-zone-get

func (*ZonesService) List

func (s *ZonesService) List() ([]*dns.Zone, *http.Response, error)

List returns all active zones and basic zone configuration details for each.

NS1 API docs: https://ns1.com/api/#zones-get

func (*ZonesService) Update

func (s *ZonesService) Update(z *dns.Zone) (*http.Response, error)

Update takes a *Zone and modifies basic details of a DNS zone.

NS1 API docs: https://ns1.com/api/#zones-post

Directories

Path Synopsis
Example referencing https://ns1.com/articles/automated-failover
Example referencing https://ns1.com/articles/automated-failover
Package model defines structures for interacting with the NS1 API.
Package model defines structures for interacting with the NS1 API.
account
Package account contains definitions for NS1 apikeys/teams/users/etc.
Package account contains definitions for NS1 apikeys/teams/users/etc.
data
Package data contains definitions for NS1 metadata/sources/feeds/etc.
Package data contains definitions for NS1 metadata/sources/feeds/etc.
dhcp
Package dhcp contains definitions for scope groups, scopes, etc.
Package dhcp contains definitions for scope groups, scopes, etc.
dns
Package dns contains definitions for NS1 zones/records/answers/etc.
Package dns contains definitions for NS1 zones/records/answers/etc.
filter
Package filter contains definitions for NS1 filter chains.
Package filter contains definitions for NS1 filter chains.
ipam
Package ipam contains definitions for networks, addresses, etc.
Package ipam contains definitions for networks, addresses, etc.
monitor
Package monitor contains definitions for NS1 monitoring jobs.
Package monitor contains definitions for NS1 monitoring jobs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL