dnssdk

package module
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 17 Imported by: 3

README

G-Core Labs DNS API Golang SDK

The purpose of this project is to cover G-Core DNS API methods related with G-Core Terraform plugin (https://github.com/G-Core/terraform-provider-gcorelabs).

Status

Build Status

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BearerAuth

func BearerAuth(token string) func() authHeader

BearerAuth by header

func ContentFromValue

func ContentFromValue(recordType, content string) []any

ContentFromValue convertor from flat value to valid for api

func PermanentAPIKeyAuth

func PermanentAPIKeyAuth(token string) func() authHeader

PermanentAPIKeyAuth by header

Types

type APIError

type APIError struct {
	StatusCode int    `json:"-"`
	Message    string `json:"error,omitempty"`
}

APIError customization for API calls

func (APIError) Error

func (a APIError) Error() string

Error implementation

type AddZone

type AddZone struct {
	Name string `json:"name"`
}

AddZone dto to create new zone

type AddZoneOpt

type AddZoneOpt func(*RRSet)

AddZoneOpt setup RRSet

func WithFilters

func WithFilters(filters ...RecordFilter) AddZoneOpt

WithFilters add filters to RRSet

type Client

type Client struct {
	HTTPClient *http.Client
	UserAgent  string
	BaseURL    *url.URL

	Debug bool
	// contains filtered or unexported fields
}

Client for DNS API.

func NewClient

func NewClient(authorizer func() authHeader, opts ...func(*Client)) *Client

NewClient constructor of Client.

func (*Client) AddZoneRRSet

func (c *Client) AddZoneRRSet(ctx context.Context,
	zone, recordName, recordType string,
	values []ResourceRecord, ttl int, opts ...AddZoneOpt) error

AddZoneRRSet create or extend resource record.

func (*Client) AllZones added in v0.2.7

func (c *Client) AllZones(ctx context.Context, nameFilters []string) ([]Zone, error)

AllZones get all zones per 1k

func (*Client) AllZonesWithRecords added in v0.2.8

func (c *Client) AllZonesWithRecords(ctx context.Context, nameFilters []string) ([]Zone, error)

AllZonesWithRecords gets all zones with records information.

func (*Client) CreateRRSet

func (c *Client) CreateRRSet(ctx context.Context, zone, name, recordType string, record RRSet) error

CreateRRSet https://apidocs.gcore.com/dns#tag/rrsets/operation/CreateRRSet

func (*Client) CreateZone

func (c *Client) CreateZone(ctx context.Context, name string) (uint64, error)

CreateZone adds new zone. https://apidocs.gcore.com/dns#tag/zones/operation/CreateZone

func (*Client) DNSSecDS added in v0.2.9

func (c *Client) DNSSecDS(ctx context.Context, zone string) (DNSSecDS, error)

DNSSecDS https://api.gcore.com/docs/dns#tag/DNSSEC/operation/GetDNSSECDS

func (*Client) DeleteRRSet

func (c *Client) DeleteRRSet(ctx context.Context, zone, name, recordType string) error

DeleteRRSet removes RRSet type records. https://apidocs.gcore.com/dns#tag/rrsets/operation/DeleteRRSet

func (*Client) DeleteRRSetRecord

func (c *Client) DeleteRRSetRecord(ctx context.Context, zone, name, recordType string, contents ...string) error

DeleteRRSetRecord removes RRSet record.

func (*Client) DeleteZone

func (c *Client) DeleteZone(ctx context.Context, name string) error

DeleteZone gets zone information. https://apidocs.gcore.com/dns#tag/zones/operation/DeleteZone

func (*Client) RRSet

func (c *Client) RRSet(ctx context.Context, zone, name, recordType string) (RRSet, error)

RRSet gets RRSet item. https://apidocs.gcore.com/dns#tag/rrsets/operation/RRSet

func (*Client) ToggleDnssec added in v0.2.9

func (c *Client) ToggleDnssec(ctx context.Context, zone string, enable bool) (DNSSecDS, error)

ToggleDnssec https://api.gcore.com/docs/dns#tag/DNSSEC/operation/ToggleDNSSEC

func (*Client) UpdateRRSet

func (c *Client) UpdateRRSet(ctx context.Context, zone, name, recordType string, record RRSet) error

UpdateRRSet https://apidocs.gcore.com/dns#tag/rrsets/operation/UpdateRRSet

func (*Client) Zone

func (c *Client) Zone(ctx context.Context, name string) (Zone, error)

Zone gets zone information. https://apidocs.gcore.com/dns#tag/zones/operation/Zone

func (*Client) ZoneNameservers added in v0.2.4

func (c *Client) ZoneNameservers(ctx context.Context, name string) ([]string, error)

ZoneNameservers gets zone nameservers.

func (*Client) Zones

func (c *Client) Zones(ctx context.Context, filters ...func(zone *ZonesFilter)) ([]Zone, error)

Zones gets first 100 zones. https://apidocs.gcore.com/dns#tag/zones/operation/Zones

func (*Client) ZonesWithParam added in v0.2.7

func (c *Client) ZonesWithParam(ctx context.Context, param ZonesParam) (res ListZones, err error)

ZonesWithParam gets zones with params.

func (*Client) ZonesWithRecords

func (c *Client) ZonesWithRecords(ctx context.Context, filters ...func(zone *ZonesFilter)) ([]Zone, error)

ZonesWithRecords gets first 100 zones with records information.

type CreateResponse

type CreateResponse struct {
	ID    uint64 `json:"id,omitempty"`
	Error string `json:"error,omitempty"`
}

CreateResponse dto to create new zone

type DNSSecDS added in v0.2.9

type DNSSecDS struct {
	Algorithm       string `json:"algorithm"`
	Digest          string `json:"digest"`
	DigestAlgorithm string `json:"digest_algorithm"`
	DigestType      string `json:"digest_type"`
	Ds              string `json:"ds"`
	Flags           int    `json:"flags"`
	KeyTag          int    `json:"key_tag"`
	KeyType         string `json:"key_type"`
	PublicKey       string `json:"public_key"`
	Uuid            string `json:"uuid"`
}

DNSSecDS dto describe DS records that returned from API on DNSSec requests

type FailoverHttpCheck added in v0.2.7

type FailoverHttpCheck struct {
	Protocol  string `json:"protocol"` // HTTP
	Port      uint16 `json:"port"`
	Frequency uint16 `json:"frequency"`
	Timeout   uint16 `json:"timeout"`
	// HTTP only
	Method         string  `json:"method,omitempty"` // GET, POST, PUT, DELETE, PATCH
	URL            string  `json:"url,omitempty"`    // without / prefix
	Host           *string `json:"host,omitempty"`
	HttpStatusCode *uint16 `json:"http_status_code,omitempty"` // 100-599
	Regexp         *string `json:"regexp,omitempty"`
	TLS            bool    `json:"tls"`
}

FailoverHttpCheck for failover meta property with protocol=HTTP

type FailoverIcmpCheck added in v0.2.7

type FailoverIcmpCheck struct {
	Protocol  string `json:"protocol"` // ICMP
	Port      uint16 `json:"port"`
	Frequency uint16 `json:"frequency"`
	Timeout   uint16 `json:"timeout"`
}

FailoverIcmpCheck for failover meta property with protocol=ICMP

type FailoverTcpUdpCheck added in v0.2.7

type FailoverTcpUdpCheck struct {
	Protocol  string `json:"protocol"` // TCP or UDP
	Port      uint16 `json:"port"`
	Frequency uint16 `json:"frequency"`
	Timeout   uint16 `json:"timeout"`
	// TCP/UDP only
	Command *string `json:"command"` // bytes to sent
	Regexp  *string `json:"regexp,omitempty"`
}

FailoverTcpUdpCheck for failover meta property with protocol=TCP|UDP

type ListZones

type ListZones struct {
	Zones       []Zone `json:"zones"`
	TotalAmount int    `json:"total_amount"`
	Error       string `json:"error,omitempty"`
}

ListZones dto to read list of zones from API

type RRSet

type RRSet struct {
	Type    string           `json:"type"`
	TTL     int              `json:"ttl"`
	Records []ResourceRecord `json:"resource_records"`
	Filters []RecordFilter   `json:"filters"`
	Meta    RRSetMeta        `json:"meta"` // this one for failover, not Meta property inside Records

}

RRSet dto as part of zone info from API

func (*RRSet) AddFilter

func (rr *RRSet) AddFilter(filters ...RecordFilter) *RRSet

AddFilter to RRSet

func (*RRSet) SetMetaAsn added in v0.2.7

func (r *RRSet) SetMetaAsn(asns []int) *RRSet

SetMetaAsn

func (*RRSet) SetMetaBackup added in v0.2.7

func (r *RRSet) SetMetaBackup(backup bool) *RRSet

SetMetaBackup

func (*RRSet) SetMetaContinents added in v0.2.7

func (r *RRSet) SetMetaContinents(continents []string) *RRSet

SetMetaContinents

func (*RRSet) SetMetaCountries added in v0.2.7

func (r *RRSet) SetMetaCountries(countries []string) *RRSet

SetMetaCountries

func (*RRSet) SetMetaFailover added in v0.2.7

func (r *RRSet) SetMetaFailover(failover map[string]any) *RRSet

SetMetaFailover

func (*RRSet) SetMetaFailoverHttp added in v0.2.7

func (r *RRSet) SetMetaFailoverHttp(check FailoverHttpCheck) *RRSet

SetMetaFailoverHttp for failover

func (*RRSet) SetMetaFailoverIcmp added in v0.2.7

func (r *RRSet) SetMetaFailoverIcmp(check FailoverIcmpCheck) *RRSet

SetMetaFailoverIcmp for ICMP failover

func (*RRSet) SetMetaFailoverTcpUdp added in v0.2.7

func (r *RRSet) SetMetaFailoverTcpUdp(check FailoverTcpUdpCheck) *RRSet

SetMetaFailoverTcpUdp for TCP/DUP failover

func (*RRSet) SetMetaFallback added in v0.2.7

func (r *RRSet) SetMetaFallback(fallback bool) *RRSet

SetMetaFallback

func (r *RRSet) SetMetaGeodnsLink(link string) *RRSet

SetMetaGeodnsLink

func (*RRSet) SetMetaIP added in v0.2.7

func (r *RRSet) SetMetaIP(ip string) *RRSet

SetMetaIP

func (*RRSet) SetMetaLatLong added in v0.2.7

func (r *RRSet) SetMetaLatLong(lat, long float64) *RRSet

SetMetaLatLong

func (*RRSet) SetMetaNotes added in v0.2.7

func (r *RRSet) SetMetaNotes(notes string) *RRSet

SetMetaNotes

func (*RRSet) SetMetaWeight added in v0.2.7

func (r *RRSet) SetMetaWeight(weight float64) *RRSet

SetMetaWeight

type RRSetMeta added in v0.2.7

type RRSetMeta map[string]any

func NewRRSetMetaFailoverFromMap added in v0.2.7

func NewRRSetMetaFailoverFromMap(failover map[string]any) *RRSetMeta

NewRRSetMetaFailoverFromMap for failover

func NewRRSetMetaGeodnsLink(link string) *RRSetMeta

func NewRRSetMetaMetaFailoverFromHttp added in v0.2.7

func NewRRSetMetaMetaFailoverFromHttp(failover FailoverHttpCheck) *RRSetMeta

NewRRSetMetaMetaFailoverFromHttp for failover

func NewRRSetMetaMetaFailoverFromIcmp added in v0.2.7

func NewRRSetMetaMetaFailoverFromIcmp(failover FailoverIcmpCheck) *RRSetMeta

NewRRSetMetaMetaFailoverFromIcmp for ICMP failover

func NewRRSetMetaMetaFailoverFromTcpUdp added in v0.2.7

func NewRRSetMetaMetaFailoverFromTcpUdp(failover FailoverTcpUdpCheck) *RRSetMeta

NewRRSetMetaMetaFailoverFromTcpUdp for TCP/DUP failover

type RRSets added in v0.2.4

type RRSets struct {
	RRSets []RRSet `json:"rrsets"`
}

type RecordFilter

type RecordFilter struct {
	Limit  uint   `json:"limit"`
	Type   string `json:"type"`
	Strict bool   `json:"strict"`
}

RecordFilter describe Filters in RRSet

func NewDefaultFilter

func NewDefaultFilter(limit uint, strict bool) RecordFilter

NewDefaultFilter for RRSet

func NewFirstNFilter

func NewFirstNFilter(limit uint, strict bool) RecordFilter

NewFirstNFilter for RRSet

func NewGeoDNSFilter

func NewGeoDNSFilter(limit uint, strict bool) RecordFilter

NewGeoDNSFilter for RRSet

func NewGeoDistanceFilter

func NewGeoDistanceFilter(limit uint, strict bool) RecordFilter

NewGeoDistanceFilter for RRSet

type RecordType

type RecordType interface {
	ToContent() []any
}

RecordType contract

func ToRecordType

func ToRecordType(rType, content string) RecordType

ToRecordType builder

type RecordTypeAny

type RecordTypeAny string

RecordTypeAny as type of record

func (RecordTypeAny) ToContent

func (x RecordTypeAny) ToContent() []any

ToContent convertor

type RecordTypeCAA

type RecordTypeCAA string

RecordTypeCAA as type of record

func (RecordTypeCAA) ToContent

func (caa RecordTypeCAA) ToContent() []any

ToContent convertor

type RecordTypeHTTPS_SCVB added in v0.2.5

type RecordTypeHTTPS_SCVB string

RecordTypeHTTPS_SCVB as type of record

func (RecordTypeHTTPS_SCVB) ToContent added in v0.2.5

func (r RecordTypeHTTPS_SCVB) ToContent() (res []any)

ToContent convertor

type RecordTypeMX

type RecordTypeMX string

RecordTypeMX as type of record

func (RecordTypeMX) ToContent

func (mx RecordTypeMX) ToContent() []any

ToContent convertor

type RecordTypeSRV

type RecordTypeSRV string

RecordTypeSRV as type of record

func (RecordTypeSRV) ToContent

func (srv RecordTypeSRV) ToContent() []any

ToContent convertor

type ResourceMeta

type ResourceMeta struct {
	// contains filtered or unexported fields
}

ResourceMeta for ResourceRecord

func NewResourceMetaAsn

func NewResourceMetaAsn(asn ...uint64) ResourceMeta

NewResourceMetaAsn for asn meta

func NewResourceMetaBackup added in v0.2.7

func NewResourceMetaBackup() ResourceMeta

NewResourceMetaBackup for backup meta

func NewResourceMetaContinents

func NewResourceMetaContinents(continents ...string) ResourceMeta

NewResourceMetaContinents for continents meta

func NewResourceMetaCountries

func NewResourceMetaCountries(countries ...string) ResourceMeta

NewResourceMetaCountries for Countries meta

func NewResourceMetaDefault

func NewResourceMetaDefault() ResourceMeta

NewResourceMetaDefault for default meta

func NewResourceMetaFallback added in v0.2.7

func NewResourceMetaFallback() ResourceMeta

NewResourceMetaFallback for fallback meta

func NewResourceMetaIP

func NewResourceMetaIP(ips ...string) ResourceMeta

NewResourceMetaIP for ip meta

func NewResourceMetaLatLong

func NewResourceMetaLatLong(latlong string) ResourceMeta

NewResourceMetaLatLong for lat long meta

func NewResourceMetaNotes

func NewResourceMetaNotes(notes ...string) ResourceMeta

NewResourceMetaNotes for notes meta

func NewResourceMetaWeight added in v0.2.7

func NewResourceMetaWeight(weight int) ResourceMeta

NewResourceMetaWeight for fallback meta

func (ResourceMeta) Valid

func (rm ResourceMeta) Valid() error

Valid error

type ResourceRecord

type ResourceRecord struct {
	Content []any          `json:"content"`
	Meta    map[string]any `json:"meta"`
	Enabled bool           `json:"enabled"`
}

ResourceRecord dto describe records in RRSet

func (*ResourceRecord) AddMeta

func (r *ResourceRecord) AddMeta(meta ResourceMeta) *ResourceRecord

AddMeta to ResourceRecord

func (ResourceRecord) ContentToString

func (r ResourceRecord) ContentToString() string

ContentToString as short value example from: tls-ech.dev. 899 IN HTTPS 1 . ech=AEn+DQBFKwAgACABWIHUGj4u+PIggYXcR5JF0gYk3dCRioBW8uJq9H4mKAAIAAEAAQABAANAEnB1YmxpYy50bHMtZWNoLmRldgAA clickhouse.com. 899 IN HTTPS 1 . alpn="h3,h3-29,h2" ipv4hint=172.66.40.249,172.66.43.7 ipv6hint=2606:4700:3108::ac42:28f9,2606:4700:3108::ac42:2b07

func (*ResourceRecord) SetContent

func (r *ResourceRecord) SetContent(recordType, val string) *ResourceRecord

SetContent to ResourceRecord

type Zone

type Zone struct {
	Name    string       `json:"name"`
	Records []ZoneRecord `json:"records"`
}

Zone dto to read info from API

type ZoneRecord

type ZoneRecord struct {
	Name         string   `json:"name"`
	Type         string   `json:"type"`
	TTL          uint     `json:"ttl"`
	ShortAnswers []string `json:"short_answers"`
}

ZoneRecord dto describe records in Zone

type ZonesFilter

type ZonesFilter struct {
	Names []string
}

ZonesFilter find zones

type ZonesParam added in v0.2.7

type ZonesParam struct {
	Offset         uint64
	Limit          uint64
	OrderBy        string
	OrderDirection string
	ID             []uint64
	ClientID       []uint64
	ResellerID     []uint64
	IAMResellerID  []uint64
	Name           []string
	CaseSensitive  bool
	ExactMatch     bool
	Enabled        bool
	Status         string
	Dynamic        bool
	Healthcheck    bool
	UpdatedAtFrom  time.Time
	UpdatedAtTo    time.Time
}

ZonesParam parameter for ZonesWithParam method

offset integer <uint64> Amount of records to skip before beginning to write in response.

limit integer <uint64> Max number of records in response

order_by string Field name to sort by

order_direction string Enum: "asc" "desc"

Ascending or descending order id Array of integers <int64> [ items <int64 > ]

to pass several ids id=1&id=3&id=5... client_id Array of integers <int64> [ items <int64 > ]

to pass several client_ids client_id=1&client_id=3&client_id=5... reseller_id Array of integers <int64> [ items <int64 > ]

iam_reseller_id Array of integers <int64> [ items <int64 > ]

name Array of strings to pass several names name=first&name=second...

case_sensitive boolean

exact_match boolean

enabled boolean

status string

dynamic boolean Zones with dynamic RRsets

healthcheck boolean Zones with RRsets that have healthchecks

updated_at_from string <date-time>

updated_at_to string <date-time>

Jump to

Keyboard shortcuts

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