client

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

README

client

import "github.com/SuperBuker/terraform-provider-dns-he-net/client/client"

Index

Constants

const endpoint = "https://dns.he.net"
const retries = 3
const retryDelay = 30 * time.Second

func getRecordsParams

func getRecordsParams(zoneID uint) map[string]string

getRecordsParams returns the generic query parameters for the record operations.

func initResult

func initResult(_ *resty.Client, resp *resty.Response) (err error)

initResult initializes the Result field to enable ResultX

func retryCondition

func retryCondition(resp *resty.Response, err error) (retry bool)

retryCondition returns true if the request should be retried, includes pause.

func unwrapResult

func unwrapResult(_ *resty.Client, resp *resty.Response) (err error)

unwrapResult unwraps the ResultX, parses the body if known type and sets the resp.Result

type Client

Client is a client for the dns.he.net API.

type Client struct {
    // SubObjts
    auth   auth.Auth
    client *resty.Client
    log    logging.Logger
    // State
    status  auth.Status
    account string
    // Options
    options Options
}
func NewClient
func NewClient(ctx context.Context, authAuth auth.Auth, log logging.Logger, options ...Option) (*Client, error)

NewClient returns a new client, requires a context and an auth.Auth. Autehticates the client against the API.

func newClient
func newClient(ctx context.Context, authAuth auth.Auth, log logging.Logger, options Options) *Client

newClient returns a new client, handles the go-resty client configuration.

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

CreateZone creates a new zone, then returns it, or an error.

func (*Client) DDNS
func (c *Client) DDNS() ddns.Client
func (*Client) DeleteRecord
func (c *Client) DeleteRecord(ctx context.Context, record models.RecordX) error

DeleteRecord deletes a record, returns an error.

func (*Client) DeleteZone
func (c *Client) DeleteZone(ctx context.Context, zone models.Zone) error

DeleteZone deletes a zone, returns an error.

func (*Client) GetAccount
func (c *Client) GetAccount() string

GetAccount returns the account ID.

func (*Client) GetRecords
func (c *Client) GetRecords(ctx context.Context, zoneID uint) ([]models.Record, error)

GetRecords retrieves all records from the API and returns them in a slice.

func (*Client) GetZones
func (c *Client) GetZones(ctx context.Context) ([]models.Zone, error)

GetZones retrieves all zones from the API and returns them in a slice

func (*Client) SetDDNSKey
func (c *Client) SetDDNSKey(ctx context.Context, dk models.DDNSKey) (string, error)

SetDDNSKey creates or updates a ddns domain key, then returns the result message or an error.

func (*Client) SetRecord
func (c *Client) SetRecord(ctx context.Context, record models.RecordX) (models.RecordX, error)

SetRecord creates or updates a record, then returns it, or an error.

func (*Client) authBasic
func (c *Client) authBasic(ctx context.Context, client *resty.Client) ([]*http.Cookie, error)
func (*Client) authOTP
func (c *Client) authOTP(ctx context.Context, client *resty.Client) error
func (*Client) authValidation
func (c *Client) authValidation(rc *resty.Client, req *resty.Request) error
func (*Client) autheticate
func (c *Client) autheticate(ctx context.Context) ([]*http.Cookie, error)

autheticate authenticates the client against the API on a separated go-resty client, then returns the cookies.

func (*Client) setAccount
func (c *Client) setAccount(resp *resty.Response)
func (*Client) statusCheck
func (c *Client) statusCheck(_ *resty.Client, resp *resty.Response) (err error)
func (*Client) statusCheckLog
func (c *Client) statusCheckLog(resp *resty.Response) error

type ErrItemNotFound

ErrItemNotFound is an error that indicates a resource was not found.

type ErrItemNotFound struct {
    Resource string
}
func (*ErrItemNotFound) Error
func (e *ErrItemNotFound) Error() string
func (*ErrItemNotFound) Unwrap
func (e *ErrItemNotFound) Unwrap() []error

type Option

type Option struct {
    ClientFn     func(*resty.Client) *resty.Client
    AuthClientFn func(*resty.Client) *resty.Client
    DDNSClientFn func(*resty.Client) *resty.Client
    LogFn        func(logging.Logger) logging.Logger
}
func WithDebug
func WithDebug() Option

WithDebug sets the debug mode for the client

func WithProxy
func WithProxy(proxy string) Option

WithProxy sets the proxy for the client

func WithUserAgent
func WithUserAgent(ua string) Option

WithUserAgent sets the user agent for the client

type Options

type Options []Option
func (Options) ApplyAuthClient
func (opts Options) ApplyAuthClient(client *resty.Client) *resty.Client
func (Options) ApplyClient
func (opts Options) ApplyClient(client *resty.Client) *resty.Client

Proc Options

func (Options) ApplyDDNSClient
func (opts Options) ApplyDDNSClient(client *resty.Client) *resty.Client
func (Options) ApplyLogger
func (opts Options) ApplyLogger(logger logging.Logger) logging.Logger

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a client for the dns.he.net API.

func NewClient

func NewClient(ctx context.Context, authAuth auth.Auth, log logging.Logger, options ...Option) (*Client, error)

NewClient returns a new client, requires a context and an auth.Auth. Autehticates the client against the API.

func (*Client) CreateZone

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

CreateZone creates a new zone, then returns it, or an error.

func (*Client) DDNS

func (c *Client) DDNS() ddns.Client

func (*Client) DeleteRecord

func (c *Client) DeleteRecord(ctx context.Context, record models.RecordX) error

DeleteRecord deletes a record, returns an error.

func (*Client) DeleteZone

func (c *Client) DeleteZone(ctx context.Context, zone models.Zone) error

DeleteZone deletes a zone, returns an error.

func (*Client) GetAccount

func (c *Client) GetAccount() string

GetAccount returns the account ID.

func (*Client) GetRecords

func (c *Client) GetRecords(ctx context.Context, zoneID uint) ([]models.Record, error)

GetRecords retrieves all records from the API and returns them in a slice.

func (*Client) GetZones

func (c *Client) GetZones(ctx context.Context) ([]models.Zone, error)

GetZones retrieves all zones from the API and returns them in a slice

func (*Client) SetDDNSKey

func (c *Client) SetDDNSKey(ctx context.Context, dk models.DDNSKey) (string, error)

SetDDNSKey creates or updates a ddns domain key, then returns the result message or an error.

func (*Client) SetRecord

func (c *Client) SetRecord(ctx context.Context, record models.RecordX) (models.RecordX, error)

SetRecord creates or updates a record, then returns it, or an error.

type ErrItemNotFound

type ErrItemNotFound struct {
	Resource string
}

ErrItemNotFound is an error that indicates a resource was not found.

func (*ErrItemNotFound) Error

func (e *ErrItemNotFound) Error() string

func (*ErrItemNotFound) Unwrap

func (e *ErrItemNotFound) Unwrap() []error

type Option

type Option struct {
	ClientFn     func(*resty.Client) *resty.Client
	AuthClientFn func(*resty.Client) *resty.Client
	DDNSClientFn func(*resty.Client) *resty.Client
	LogFn        func(logging.Logger) logging.Logger
}

func WithDebug

func WithDebug() Option

WithDebug sets the debug mode for the client

func WithProxy

func WithProxy(proxy string) Option

WithProxy sets the proxy for the client

func WithUserAgent

func WithUserAgent(ua string) Option

WithUserAgent sets the user agent for the client

type Options

type Options []Option

func (Options) ApplyAuthClient

func (opts Options) ApplyAuthClient(client *resty.Client) *resty.Client

func (Options) ApplyClient

func (opts Options) ApplyClient(client *resty.Client) *resty.Client

Proc Options

func (Options) ApplyDDNSClient

func (opts Options) ApplyDDNSClient(client *resty.Client) *resty.Client

func (Options) ApplyLogger

func (opts Options) ApplyLogger(logger logging.Logger) logging.Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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