nicrudns

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: MIT Imports: 11 Imported by: 0

README

Golang client for NIC.ru API for libdns

Go Reference

This package implements the libdns interfaces for NIC.ru API, allowing you to manage DNS records.

Usage Example:

package examples

import (
	"context"
	"fmt"
	"github.com/libdns/libdns"
	"github.com/ek2505/nicrudns"
	"github.com/pkg/errors"
	"time"
)

var (
	provider = nicrudns.Provider{}
	zoneName string
)

func ExampleLibdnsProvider() error {
	ctx := context.TODO()
	var records = []libdns.Record{
		{
			Type:  `A`,
			Name:  `www`,
			Value: `1.2.3.4`,
			TTL:   time.Hour,
		},
	}
	if records, err := provider.AppendRecords(ctx, zoneName, records); err != nil {
		return errors.Wrap(err, `append records error`)
	} else {
		for _, record := range records {
			fmt.Println(record.Name, record.TTL, record.TTL, record.Value)
		}
		return nil
	}
}

func ExampleNicruClient() error {
	client := nicrudns.NewClient(&provider)
	var names = []string{`www`}
	if response, err := client.AddA(zoneName, names, `1.2.3.4`, `3600`); err != nil {
		return errors.Wrap(err, `add records error`)
	} else {
		for _, rr := range response.Data.Zone[0].Rr {
			fmt.Println(rr.Name, rr.Type, rr.Ttl, rr.A.String())
		}
		return nil
	}
}

Documentation

Index

Constants

View Source
const (
	BaseURL                 = `https://api.nic.ru`
	TokenURL                = BaseURL + `/oauth/token`
	GetRecordsUrlPattern    = BaseURL + `/dns-master/services/%s/zones/%s/records`
	DeleteRecordsUrlPattern = BaseURL + `/dns-master/services/%s/zones/%s/records/%d`
	AddRecordsUrlPattern    = BaseURL + `/dns-master/services/%s/zones/%s/records`
	GetServicesUrl          = BaseURL + `/dns-master/services`
	CommitUrlPattern        = BaseURL + `/dns-master/services/%s/zones/%s/commit`
	RollbackUrlPattern      = BaseURL + `/dns-master/services/%s/zones/%s/rollback`
	DownloadZoneUrlPattern  = BaseURL + `/dns-master/services/%s/zones/%s`
	SuccessStatus           = `success`
	OAuth2Scope             = `.+:/dns-master/.+`
)

Variables

View Source
var (
	XmlDecodeError            = errors.New(`xml decode error`)
	XmlEncodeError            = errors.New(`xml encode error`)
	JsonDecodeError           = errors.New(`json decode error`)
	JsonEncodeError           = errors.New(`json encode error`)
	CreateFileError           = errors.New(`create file error`)
	ReadFileError             = errors.New(`read file error`)
	ApiNonSuccessError        = errors.New(`api non-success error`)
	RequestError              = errors.New(`request error`)
	ResponseError             = errors.New(`response error`)
	InvalidStatusCode         = errors.New(`invalid status code`)
	BufferReadError           = errors.New(`buffer read error`)
	Oauth2ClientError         = errors.New(`oauth2 client error`)
	NameFilterError           = errors.New(`name filter error`)
	TargetFilterError         = errors.New(`target filter error`)
	UpdateTokenCacheFileError = errors.New(`update token cache file error`)
	AuthorizationError        = errors.New(`authorization error`)
	NotImplementedRecordType  = errors.New(`not implemented record type`)
)

Functions

This section is empty.

Types

type Address

type Address string

func (*Address) String

func (address *Address) String() string

type Client

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

func (*Client) Add

func (client *Client) Add(zoneName string, request *Request) (*Response, error)

func (*Client) AddA

func (client *Client) AddA(zoneName string, names []string, target string, ttl string) (*Response, error)

func (*Client) AddAAAA

func (client *Client) AddAAAA(zoneName string, names []string, target string, ttl string) (*Response, error)

func (*Client) AddCnames

func (client *Client) AddCnames(zoneName string, names []string, target string, ttl string) (*Response, error)

func (*Client) AddMx

func (client *Client) AddMx(zoneName string, names []string, target string, preference string, ttl string) (*Response, error)

func (*Client) AddTxt

func (client *Client) AddTxt(zoneName string, names []string, target string, ttl string) (*Response, error)

func (*Client) CommitZone

func (client *Client) CommitZone(zoneName string) (*Response, error)

func (*Client) DeleteRecord

func (client *Client) DeleteRecord(zoneName string, id int) (*Response, error)

func (*Client) Do

func (client *Client) Do(r *http.Request) (*http.Response, error)

func (*Client) DownloadZone

func (client *Client) DownloadZone(zoneName string) (string, error)

func (*Client) GetAAAARecords

func (client *Client) GetAAAARecords(zoneName string, nameFilter string, targetFilter string) ([]*RR, error)

func (*Client) GetARecords

func (client *Client) GetARecords(zoneName string, nameFilter string, targetFilter string) ([]*RR, error)

func (*Client) GetCnameRecords

func (client *Client) GetCnameRecords(zoneName string, nameFilter string, targetFilter string) ([]*RR, error)

func (*Client) GetMxRecords

func (client *Client) GetMxRecords(zoneName string, nameFilter string, targetFilter string) ([]*RR, error)

func (*Client) GetOauth2Client

func (client *Client) GetOauth2Client() (*http.Client, error)

func (*Client) GetRecords

func (client *Client) GetRecords(zoneName string) ([]*RR, error)

func (*Client) GetServices

func (client *Client) GetServices() ([]*Service, error)

func (*Client) GetTxtRecords

func (client *Client) GetTxtRecords(zoneName string, nameFilter string, targetFilter string) ([]*RR, error)

func (*Client) RollbackZone

func (client *Client) RollbackZone(zoneName string) (*Response, error)

type Cname

type Cname struct {
	Text    string `xml:",chardata" json:"text,omitempty"`
	Name    string `xml:"name" json:"name,omitempty"`
	IdnName string `xml:"idn-name,omitempty" json:"idn_name,omitempty"`
}

type Data

type Data struct {
	Text     string      `xml:",chardata" json:"text,omitempty"`
	Service  []*Service  `xml:"service" json:"service,omitempty"`
	Zone     []*Zone     `xml:"zone" json:"zone,omitempty"`
	Address  []*Address  `xml:"address" json:"address,omitempty"`
	Revision []*Revision `xml:"revision" json:"revision,omitempty"`
}

type Dname

type Dname struct {
	Text string `xml:",chardata" json:"text,omitempty"`
	Name string `xml:"name" json:"name,omitempty"`
}

type Error

type Error struct {
	Text string `xml:",chardata" json:"text,omitempty"`
	Code string `xml:"code,attr" json:"code,omitempty"`
}

type Exchange

type Exchange struct {
	Text string `xml:",chardata" json:"text,omitempty"`
	Name string `xml:"name" json:"name,omitempty"`
}

type Hinfo

type Hinfo struct {
	Text     string `xml:",chardata" json:"text,omitempty"`
	Hardware string `xml:"hardware" json:"hardware,omitempty"`
	Os       string `xml:"os" json:"os,omitempty"`
}

type IClient

type IClient interface {
	AddA(zoneName string, names []string, target string, ttl string) (*Response, error)
	AddAAAA(zoneName string, names []string, target string, ttl string) (*Response, error)
	AddCnames(zoneName string, names []string, target string, ttl string) (*Response, error)
	AddMx(zoneName string, names []string, target string, preference string, ttl string) (*Response, error)
	AddTxt(zoneName string, names []string, target string, ttl string) (*Response, error)
	CommitZone(zoneName string) (*Response, error)
	DeleteRecord(zoneName string, id int) (*Response, error)
	DownloadZone(zoneName string) (string, error)
	GetRecords(zoneName string) ([]*RR, error)
	GetARecords(zoneName string, nameFilter string, targetFilter string) ([]*RR, error)
	GetAAAARecords(zoneName string, nameFilter string, targetFilter string) ([]*RR, error)
	GetCnameRecords(zoneName string, nameFilter string, targetFilter string) ([]*RR, error)
	GetMxRecords(zoneName string, nameFilter string, targetFilter string) ([]*RR, error)
	GetTxtRecords(zoneName string, nameFilter string, targetFilter string) ([]*RR, error)
	RollbackZone(zoneName string) (*Response, error)
	GetServices() ([]*Service, error)
}

func NewClient

func NewClient(provider *Provider) IClient

type MboxDname

type MboxDname struct {
	Text string `xml:",chardata" json:"text,omitempty"`
	Name string `xml:"name" json:"name,omitempty"`
}

type Mname

type Mname struct {
	Text    string `xml:",chardata" json:"text,omitempty"`
	Name    string `xml:"name" json:"name,omitempty"`
	IdnName string `xml:"idn-name,omitempty" json:"idn_name,omitempty"`
}

type Mx

type Mx struct {
	Text       string    `xml:",chardata" json:"text,omitempty"`
	Preference string    `xml:"preference" json:"preference,omitempty"`
	Exchange   *Exchange `xml:"exchange" json:"exchange,omitempty"`
}

type Naptr

type Naptr struct {
	Text        string       `xml:",chardata" json:"text,omitempty"`
	Order       string       `xml:"order" json:"order,omitempty"`
	Preference  string       `xml:"preference" json:"preference,omitempty"`
	Flags       string       `xml:"flags" json:"flags,omitempty"`
	Service     string       `xml:"service" json:"service,omitempty"`
	Regexp      string       `xml:"regexp" json:"regexp,omitempty"`
	Replacement *Replacement `xml:"replacement" json:"replacement,omitempty"`
}

type Ns

type Ns struct {
	Text    string `xml:",chardata" json:"text,omitempty"`
	Name    string `xml:"name" json:"name,omitempty"`
	IdnName string `xml:"idn-name,omitempty" json:"idn_name,omitempty"`
}

type Provider

type Provider struct {
	OAuth2ClientID string `json:"oauth2_client_id"`
	OAuth2SecretID string `json:"oauth2_secret_id"`
	Username       string `json:"username"`
	Password       string `json:"password"`
	DnsServiceName string `json:"dns_service_name"`
	CachePath      string `json:"cache_path"`
}

Provider facilitates DNS record manipulation with NIC.ru.

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to the zone. It returns the records that were added.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the records from the zone. It returns the records that were deleted.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords lists all the records in the zone.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

SetRecords sets the records in the zone, either by updating existing records or creating new ones. It returns the updated records.

type Ptr

type Ptr struct {
	Text string `xml:",chardata" json:"text,omitempty"`
	Name string `xml:"name" json:"name,omitempty"`
}

type RR

type RR struct {
	Text    string   `xml:",chardata" json:"text,omitempty"`
	ID      string   `xml:"id,attr,omitempty" json:"id,omitempty"`
	Name    string   `xml:"name" json:"name,omitempty"`
	IdnName string   `xml:"idn-name,omitempty" json:"idn_name,omitempty"`
	Ttl     string   `xml:"ttl" json:"ttl,omitempty"`
	Type    string   `xml:"type" json:"type,omitempty"`
	Soa     *Soa     `xml:"soa" xml:"soa,omitempty"`
	A       *Address `xml:"a" json:"a,omitempty"`
	AAAA    *Address `xml:"aaaa" json:"aaaa,omitempty"`
	Cname   *Cname   `xml:"cname" json:"cname,omitempty"`
	Ns      *Ns      `xml:"ns" json:"ns,omitempty"`
	Mx      *Mx      `xml:"mx" json:"mx,omitempty"`
	Srv     *Srv     `xml:"srv" json:"srv,omitempty"`
	Ptr     *Ptr     `xml:"ptr" json:"ptr,omitempty"`
	Txt     *Txt     `xml:"txt" json:"txt,omitempty"`
	Dname   *Dname   `xml:"dname" json:"dname,omitempty"`
	Hinfo   *Hinfo   `xml:"hinfo" json:"hinfo,omitempty"`
	Naptr   *Naptr   `xml:"naptr" json:"naptr,omitempty"`
	Rp      *Rp      `xml:"rp" json:"rp,omitempty"`
}

type Replacement

type Replacement struct {
	Text string `xml:",chardata" json:"text,omitempty"`
	Name string `xml:"name" json:"name,omitempty"`
}

type Request

type Request struct {
	XMLName xml.Name `xml:"request" json:"xml_name,omitempty"`
	Text    string   `xml:",chardata" json:"text,omitempty"`
	RrList  *RrList  `xml:"rr-list" json:"rr_list,omitempty"`
}

type Response

type Response struct {
	XMLName xml.Name `xml:"response" json:"xml_name,omitempty"`
	Text    string   `xml:",chardata" json:"text,omitempty"`
	Status  string   `xml:"status" json:"status,omitempty"`
	Errors  struct {
		Text  string `xml:",chardata" json:"text,omitempty"`
		Error Error  `xml:"error" json:"error,omitempty"`
	} `xml:"errors" json:"errors,omitempty"`
	Data *Data `xml:"data" json:"data,omitempty"`
}

type Revision

type Revision struct {
	Text   string `xml:",chardata" json:"text,omitempty"`
	Date   string `xml:"date,attr" json:"date,omitempty"`
	Ip     string `xml:"ip,attr" json:"ip,omitempty"`
	Number string `xml:"number,attr" json:"number,omitempty"`
}

type Rname

type Rname struct {
	Text    string `xml:",chardata" json:"text,omitempty"`
	Name    string `xml:"name" json:"name,omitempty"`
	IdnName string `xml:"idn-name,omitempty" json:"idn_name,omitempty"`
}

type Rp

type Rp struct {
	Text      string     `xml:",chardata" json:"text,omitempty"`
	MboxDname *MboxDname `xml:"mbox-dname" json:"mbox_dname,omitempty"`
	TxtDname  *TxtDname  `xml:"txt-dname" json:"txt_dname,omitempty"`
}

type RrList

type RrList struct {
	Text string `xml:",chardata" json:"text,omitempty"`
	Rr   []*RR  `xml:"rr" json:"rr,omitempty"`
}

type Service

type Service struct {
	Text         string `xml:",chardata" json:"text,omitempty"`
	Admin        string `xml:"admin,attr" json:"admin,omitempty"`
	DomainsLimit string `xml:"domains-limit,attr" json:"domains_limit,omitempty"`
	DomainsNum   string `xml:"domains-num,attr" json:"domains_num,omitempty"`
	Enable       string `xml:"enable,attr" json:"enable,omitempty"`
	HasPrimary   string `xml:"has-primary,attr" json:"has_primary,omitempty"`
	Name         string `xml:"name,attr" json:"name,omitempty"`
	Payer        string `xml:"payer,attr" json:"payer,omitempty"`
	Tariff       string `xml:"tariff,attr" json:"tariff,omitempty"`
	RrLimit      string `xml:"rr-limit,attr" json:"rr_limit,omitempty"`
	RrNum        string `xml:"rr-num,attr" json:"rr_num,omitempty"`
}

type Soa

type Soa struct {
	Text    string `xml:",chardata" json:"text,omitempty"`
	Mname   *Mname `xml:"mname" json:"mname,omitempty"`
	Rname   *Rname `xml:"rname" json:"rname,omitempty"`
	Serial  string `xml:"serial" json:"serial,omitempty"`
	Refresh string `xml:"refresh" json:"refresh,omitempty"`
	Retry   string `xml:"retry" json:"retry,omitempty"`
	Expire  string `xml:"expire" json:"expire,omitempty"`
	Minimum string `xml:"minimum" json:"minimum,omitempty"`
}

type Srv

type Srv struct {
	Text     string  `xml:",chardata" json:"text,omitempty"`
	Priority string  `xml:"priority" json:"priority,omitempty"`
	Weight   string  `xml:"weight" json:"weight,omitempty"`
	Port     string  `xml:"port" json:"port,omitempty"`
	Target   *Target `xml:"target" json:"target,omitempty"`
}

type Target

type Target struct {
	Text string `xml:",chardata" json:"text,omitempty"`
	Name string `xml:"name" json:"name,omitempty"`
}

type Txt

type Txt struct {
	Text   string `xml:",chardata" json:"text,omitempty"`
	String string `xml:"string" json:"string,omitempty"`
}

type TxtDname

type TxtDname struct {
	Text string `xml:",chardata" json:"text,omitempty"`
	Name string `xml:"name" json:"name,omitempty"`
}

type Zone

type Zone struct {
	Text       string `xml:",chardata" json:"text,omitempty"`
	Admin      string `xml:"admin,attr" json:"admin,omitempty"`
	Enable     string `xml:"enable,attr" json:"enable,omitempty"`
	HasChanges string `xml:"has-changes,attr" json:"has_changes,omitempty"`
	HasPrimary string `xml:"has-primary,attr" json:"has_primary,omitempty"`
	ID         string `xml:"id,attr" json:"id,omitempty"`
	IdnName    string `xml:"idn-name,attr" json:"idn_name,omitempty"`
	Name       string `xml:"name,attr" json:"name,omitempty"`
	Payer      string `xml:"payer,attr" json:"payer,omitempty"`
	Service    string `xml:"service,attr" json:"service,omitempty"`
	Rr         []*RR  `xml:"rr" json:"rr,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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