ns1-go.v2: gopkg.in/ns1/ns1-go.v2/rest Index | Files | Directories

package rest

import "gopkg.in/ns1/ns1-go.v2/rest"

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

Index

Package Files

account_apikey.go account_setting.go account_team.go account_user.go account_warning.go client.go data_feed.go data_source.go dnssec.go doc.go headers.go monitor_job.go monitor_notify.go record.go stat.go util.go zone.go

Variables

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")
)
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")
)
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")
)
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")
)
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")
)
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")
)
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")
)

func CheckResponse Uses

func CheckResponse(resp *http.Response) error

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

func SetAPIKey Uses

func SetAPIKey(key string) func(*Client)

SetAPIKey sets a Client instances' APIKey.

func SetBoolParam Uses

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

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

func SetEndpoint Uses

func SetEndpoint(endpoint string) func(*Client)

SetEndpoint sets a Client instances' Endpoint.

func SetFollowPagination Uses

func SetFollowPagination(shouldFollow bool) func(*Client)

SetFollowPagination sets a Client instances' FollowPagination attribute.

func SetHTTPClient Uses

func SetHTTPClient(httpClient Doer) func(*Client)

SetHTTPClient sets a Client instances' httpClient.

func SetIntParam Uses

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

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

func SetRateLimitFunc Uses

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

SetRateLimitFunc sets a Client instances' RateLimitFunc.

func SetStringParam Uses

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

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

func SetTimeParam Uses

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

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

func SetUserAgent Uses

func SetUserAgent(ua string) func(*Client)

SetUserAgent sets a Client instances' user agent.

type APIKeysService Uses

type APIKeysService service

APIKeysService handles 'account/apikeys' endpoint.

func (*APIKeysService) Create Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Client Uses

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

    // Services used for communicating with different components of the NS1 API.
    APIKeys       *APIKeysService
    DataFeeds     *DataFeedsService
    DataSources   *DataSourcesService
    Jobs          *JobsService
    Notifications *NotificationsService
    Records       *RecordsService
    Settings      *SettingsService
    Stats         *StatsService
    Teams         *TeamsService
    Users         *UsersService
    Warnings      *WarningsService
    Zones         *ZonesService
    DNSSEC        *DNSSECService
    // contains filtered or unexported fields
}

Client manages communication with the NS1 Rest API.

func NewClient Uses

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

NewClient constructs and returns a reference to an instantiated Client.

func (Client) Do Uses

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 Uses

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 Uses

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

NewRequest constructs and returns a http.Request.

func (*Client) RateLimitStrategyConcurrent Uses

func (c *Client) RateLimitStrategyConcurrent(parallelism int)

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

func (*Client) RateLimitStrategySleep Uses

func (c *Client) RateLimitStrategySleep()

RateLimitStrategySleep sets RateLimitFunc to sleep by WaitTimeRemaining

type DNSSECService Uses

type DNSSECService service

DNSSECService handles 'zones/ZONE/dnssec' endpoint.

func (*DNSSECService) Get Uses

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 DataFeedsService Uses

type DataFeedsService service

DataFeedsService handles 'data/feeds' endpoint.

func (*DataFeedsService) Create Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

type DataSourcesService service

DataSourcesService handles 'data/sources' endpoint.

func (*DataSourcesService) Create Uses

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 Uses

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 Uses

func (s *DataSourcesService) Get(id string) (*data.Source, *http.Response, error)

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

Error contains all http responses outside the 2xx range.

func (*Error) Error Uses

func (re *Error) Error() string

Satisfy std lib error interface.

type JobsService Uses

type JobsService service

JobsService handles 'monitoring/jobs' endpoint.

func (*JobsService) Create Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (l Links) Next() string

Next gets the URI for "next", if present

type NextFunc Uses

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 Uses

type NotificationsService service

NotificationsService handles 'monitoring/lists' endpoint.

func (*NotificationsService) Create Uses

func (s *NotificationsService) Create(nl *monitor.NotifyList) (*http.Response, error)

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

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

func (*NotificationsService) Delete Uses

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 Uses

func (s *NotificationsService) Get(listID string) (*monitor.NotifyList, *http.Response, error)

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 Uses

func (s *NotificationsService) List() ([]*monitor.NotifyList, *http.Response, error)

List returns all configured notification lists.

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

func (*NotificationsService) Update Uses

func (s *NotificationsService) Update(nl *monitor.NotifyList) (*http.Response, error)

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

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

type RateLimit Uses

type RateLimit struct {
    Limit     int
    Remaining int
    Period    int
}

RateLimit stores X-Ratelimit-* headers

func (RateLimit) PercentageLeft Uses

func (rl RateLimit) PercentageLeft() int

PercentageLeft returns the ratio of Remaining to Limit as a percentage

func (RateLimit) WaitTime Uses

func (rl RateLimit) WaitTime() time.Duration

WaitTime returns the time.Duration ratio of Period to Limit

func (RateLimit) WaitTimeRemaining Uses

func (rl RateLimit) WaitTimeRemaining() time.Duration

WaitTimeRemaining returns the time.Duration ratio of Period to Remaining

type RateLimitFunc Uses

type RateLimitFunc func(RateLimit)

RateLimitFunc is rate limiting strategy for the Client instance.

type RecordsService Uses

type RecordsService service

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

func (*RecordsService) Create Uses

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 Uses

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 Uses

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 Uses

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 Response Uses

type Response struct {
    *http.Response
}

Response wraps stdlib http response.

type SettingsService Uses

type SettingsService service

SettingsService handles 'account/settings' endpoint.

func (*SettingsService) Get Uses

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

Get returns the basic contact details associated with the account.

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

func (*SettingsService) Update Uses

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 Uses

type StatsService service

StatsService handles 'stats/qps' endpoint.

func (*StatsService) GetQPS Uses

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 Uses

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 Uses

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 Uses

type TeamsService service

TeamsService handles 'account/teams' endpoint.

func (*TeamsService) Create Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 UsersService Uses

type UsersService service

UsersService handles 'account/users' endpoint.

func (*UsersService) Create Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

type WarningsService service

WarningsService handles 'account/usagewarnings' endpoint.

func (*WarningsService) Get Uses

func (s *WarningsService) Get() (*account.UsageWarning, *http.Response, error)

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 Uses

func (s *WarningsService) Update(uw *account.UsageWarning) (*http.Response, error)

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

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

type ZonesService Uses

type ZonesService service

ZonesService handles 'zones' endpoint.

func (*ZonesService) Create Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

PathSynopsis
modelPackage model defines structures for interacting with the NS1 API.
model/accountPackage account contains definitions for NS1 apikeys/teams/users/etc.
model/dataPackage data contains definitions for NS1 metadata/sources/feeds/etc.
model/dnsPackage dns contains definitions for NS1 zones/records/answers/etc.
model/filterPackage filter contains definitions for NS1 filter chains.
model/monitorPackage monitor contains definitions for NS1 monitoring jobs.

Package rest imports 16 packages (graph) and is imported by 22 packages. Updated 2019-11-27. Refresh now. Tools for package owners.