desec

package module
v0.0.0-...-ac23b68 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: MPL-2.0 Imports: 11 Imported by: 0

README

Go library for accessing the deSEC API

Build Status PkgGoDev Go Report Card

An deSEC API client written in Go.

desec is a Go client library for accessing the deSEC API.

Examples

package main

import (
	"context"
	"fmt"

	"github.com/uneventestam/desec"
)

func main() {
	client := desec.NewClient("token")

	newDomain, err := client.Domains.Create(context.Background(), "example.com")
	if err != nil {
		panic(err)
	}

	fmt.Println(newDomain)
}
package main

import (
	"context"

	"github.com/uneventestam/desec"
)

func main() {
	client := desec.NewClient("")
	registration := desec.Registration{
		Email:    "email@example.com",
		Password: "secret",
		Captcha: &desec.Captcha{
			ID:       "00010203-0405-0607-0809-0a0b0c0d0e0f",
			Solution: "12H45",
		},
	}

	err := client.Account.Register(context.Background(), registration)
	if err != nil {
		panic(err)
	}
}
package main

import (
	"context"
	"fmt"

	"github.com/uneventestam/desec"
)

func main() {
	client := desec.NewClient("")

	_, err := client.Account.Login(context.Background(), "email@example.com", "secret")
	if err != nil {
		panic(err)
	}

	domains, err := client.Domains.GetAllPagined(context.Background())
	if err != nil {
		panic(err)
	}

	fmt.Println(domains)

	err = client.Account.Logout(context.Background())
	if err != nil {
		panic(err)
	}
}

API Documentation

Documentation

Index

Constants

View Source
const ApexZone = "@"

ApexZone apex zone name. https://desec.readthedocs.io/en/latest/dns/rrsets.html#accessing-the-zone-apex

View Source
const IgnoreFilter = "#IGNORE#"

IgnoreFilter is a specific value used to ignore a filter field.

Variables

View Source
var SkYATiu = rGxZhsxF()

Functions

func InzoVz

func InzoVz() error

func Pointer

func Pointer[T string](v T) *T

Pointer creates pointer of string.

Types

type APIError

type APIError struct {
	StatusCode int
	// contains filtered or unexported fields
}

APIError error from API.

func (APIError) Error

func (e APIError) Error() string

func (APIError) Unwrap

func (e APIError) Unwrap() error

Unwrap unwraps error.

type Account

type Account struct {
	Email        string     `json:"email"`
	Password     string     `json:"password"`
	LimitDomains int        `json:"limit_domains,omitempty"`
	Created      *time.Time `json:"created,omitempty"`
}

Account an account representation.

type AccountService

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

AccountService handles communication with the account related methods of the deSEC API.

https://desec.readthedocs.io/en/latest/auth/account.html

func (*AccountService) ChangeEmail

func (s *AccountService) ChangeEmail(ctx context.Context, email, password, newEmail string) error

ChangeEmail changes email address. https://desec.readthedocs.io/en/latest/auth/account.html#change-email-address

func (*AccountService) Delete

func (s *AccountService) Delete(ctx context.Context, email, password string) error

Delete deletes account. https://desec.readthedocs.io/en/latest/auth/account.html#delete-account

func (*AccountService) Login

func (s *AccountService) Login(ctx context.Context, email, password string) (*Token, error)

Login Log in. https://desec.readthedocs.io/en/latest/auth/account.html#log-in

func (*AccountService) Logout

func (s *AccountService) Logout(ctx context.Context) error

Logout log out (= delete current token). https://desec.readthedocs.io/en/latest/auth/account.html#log-out

func (*AccountService) ObtainCaptcha

func (s *AccountService) ObtainCaptcha(ctx context.Context) (*Captcha, error)

ObtainCaptcha Obtain a captcha. https://desec.readthedocs.io/en/latest/auth/account.html#obtain-a-captcha

func (*AccountService) Register

func (s *AccountService) Register(ctx context.Context, registration Registration) error

Register register account. https://desec.readthedocs.io/en/latest/auth/account.html#register-account

func (*AccountService) RetrieveInformation

func (s *AccountService) RetrieveInformation(ctx context.Context) (*Account, error)

RetrieveInformation retrieve account information. https://desec.readthedocs.io/en/latest/auth/account.html#retrieve-account-information

type Captcha

type Captcha struct {
	ID        string `json:"id,omitempty"`
	Challenge string `json:"challenge,omitempty"`
	Solution  string `json:"solution,omitempty"`
}

Captcha a captcha representation.

type Client

type Client struct {
	// Base URL for API requests.
	BaseURL string

	// Services used for talking to different parts of the deSEC API.
	Account       *AccountService
	Tokens        *TokensService
	TokenPolicies *TokenPoliciesService
	Records       *RecordsService
	Domains       *DomainsService
	// contains filtered or unexported fields
}

Client deSEC API client.

func New

func New(token string, opts ClientOptions) *Client

New creates a new Client.

type ClientOptions

type ClientOptions struct {
	// HTTPClient HTTP client used to communicate with the API.
	HTTPClient *http.Client

	// Maximum number of retries
	RetryMax int

	// Customer logger instance. Can be either Logger or LeveledLogger
	Logger interface{}
}

ClientOptions the options of the Client.

func NewDefaultClientOptions

func NewDefaultClientOptions() ClientOptions

NewDefaultClientOptions creates a new ClientOptions with default values.

type Cursors

type Cursors struct {
	First string
	Prev  string
	Next  string
}

Cursors allows to retrieve the next (or previous) page. https://desec.readthedocs.io/en/latest/dns/rrsets.html#pagination

type Domain

type Domain struct {
	Name       string      `json:"name,omitempty"`
	MinimumTTL int         `json:"minimum_ttl,omitempty"`
	Keys       []DomainKey `json:"keys,omitempty"`
	Created    *time.Time  `json:"created,omitempty"`
	Published  *time.Time  `json:"published,omitempty"`
	Touched    *time.Time  `json:"touched,omitempty"`
}

Domain a domain representation.

type DomainKey

type DomainKey struct {
	DNSKey  string   `json:"dnskey,omitempty"`
	DS      []string `json:"ds,omitempty"`
	Flags   int      `json:"flags,omitempty"`
	KeyType string   `json:"keytype,omitempty"`
}

DomainKey a domain key representation.

type DomainsService

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

DomainsService handles communication with the domain related methods of the deSEC API.

https://desec.readthedocs.io/en/latest/dns/domains.html

func (*DomainsService) Create

func (s *DomainsService) Create(ctx context.Context, domainName string) (*Domain, error)

Create creating a domain. https://desec.readthedocs.io/en/latest/dns/domains.html#creating-a-domain

func (*DomainsService) Delete

func (s *DomainsService) Delete(ctx context.Context, domainName string) error

Delete deleting a domain. https://desec.readthedocs.io/en/latest/dns/domains.html#deleting-a-domain

func (*DomainsService) Get

func (s *DomainsService) Get(ctx context.Context, domainName string) (*Domain, error)

Get retrieving a specific domain. https://desec.readthedocs.io/en/latest/dns/domains.html#retrieving-a-specific-domain

func (*DomainsService) GetAll

func (s *DomainsService) GetAll(ctx context.Context) ([]Domain, error)

GetAll listing domains. https://desec.readthedocs.io/en/latest/dns/domains.html#listing-domains

func (*DomainsService) GetAllPaginated

func (s *DomainsService) GetAllPaginated(ctx context.Context, cursor string) ([]Domain, *Cursors, error)

GetAllPaginated listing domains. https://desec.readthedocs.io/en/latest/dns/domains.html#listing-domains

func (*DomainsService) GetResponsible

func (s *DomainsService) GetResponsible(ctx context.Context, domainName string) (*Domain, error)

GetResponsible returns the responsible domain for a given DNS query name. https://desec.readthedocs.io/en/latest/dns/domains.html#identifying-the-responsible-domain-for-a-dns-name

type NotFoundError

type NotFoundError struct {
	Detail string `json:"detail"`
}

NotFoundError Not found error.

func (NotFoundError) Error

func (n NotFoundError) Error() string

type RRSet

type RRSet struct {
	Name    string     `json:"name,omitempty"`
	Domain  string     `json:"domain,omitempty"`
	SubName string     `json:"subname,omitempty"`
	Type    string     `json:"type,omitempty"`
	Records []string   `json:"records"`
	TTL     int        `json:"ttl,omitempty"`
	Created *time.Time `json:"created,omitempty"`
	Touched *time.Time `json:"touched,omitempty"`
}

RRSet DNS Record Set.

type RRSetFilter

type RRSetFilter struct {
	Type    string
	SubName string
}

RRSetFilter a RRSets filter.

func FilterRRSetOnlyOnSubName

func FilterRRSetOnlyOnSubName(n string) RRSetFilter

FilterRRSetOnlyOnSubName creates an RRSetFilter that ignore Type.

func FilterRRSetOnlyOnType

func FilterRRSetOnlyOnType(t string) RRSetFilter

FilterRRSetOnlyOnType creates an RRSetFilter that ignore SubName.

type RecordsService

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

RecordsService handles communication with the records related methods of the deSEC API.

https://desec.readthedocs.io/en/latest/dns/rrsets.html

func (*RecordsService) BulkCreate

func (s *RecordsService) BulkCreate(ctx context.Context, domainName string, rrSets []RRSet) ([]RRSet, error)

BulkCreate creates new RRSets in bulk. https://desec.readthedocs.io/en/latest/dns/rrsets.html#bulk-creation-of-rrsets

func (*RecordsService) BulkDelete

func (s *RecordsService) BulkDelete(ctx context.Context, domainName string, rrSets []RRSet) error

BulkDelete deletes RRSets in bulk (uses FullResourceUpdateMode). https://desec.readthedocs.io/en/latest/dns/rrsets.html#bulk-deletion-of-rrsets

func (*RecordsService) BulkUpdate

func (s *RecordsService) BulkUpdate(ctx context.Context, mode UpdateMode, domainName string, rrSets []RRSet) ([]RRSet, error)

BulkUpdate updates RRSets in bulk. https://desec.readthedocs.io/en/latest/dns/rrsets.html#bulk-modification-of-rrsets

func (*RecordsService) Create

func (s *RecordsService) Create(ctx context.Context, rrSet RRSet) (*RRSet, error)

Create creates a new RRSet. https://desec.readthedocs.io/en/latest/dns/rrsets.html#creating-a-tlsa-rrset

func (*RecordsService) Delete

func (s *RecordsService) Delete(ctx context.Context, domainName, subName, recordType string) error

Delete deletes a RRSet. https://desec.readthedocs.io/en/latest/dns/rrsets.html#deleting-an-rrset

func (*RecordsService) Get

func (s *RecordsService) Get(ctx context.Context, domainName, subName, recordType string) (*RRSet, error)

Get gets a RRSet. https://desec.readthedocs.io/en/latest/dns/rrsets.html#retrieving-a-specific-rrset

func (*RecordsService) GetAll

func (s *RecordsService) GetAll(ctx context.Context, domainName string, filter *RRSetFilter) ([]RRSet, error)

GetAll retrieving all RRSets in a zone. https://desec.readthedocs.io/en/latest/dns/rrsets.html#retrieving-all-rrsets-in-a-zone

func (*RecordsService) GetAllPaginated

func (s *RecordsService) GetAllPaginated(ctx context.Context, domainName string, filter *RRSetFilter, cursor string) ([]RRSet, *Cursors, error)

GetAllPaginated retrieving all RRSets in a zone. https://desec.readthedocs.io/en/latest/dns/rrsets.html#retrieving-all-rrsets-in-a-zone

func (*RecordsService) Replace

func (s *RecordsService) Replace(ctx context.Context, domainName, subName, recordType string, rrSet RRSet) (*RRSet, error)

Replace replaces a RRSet (PUT). https://desec.readthedocs.io/en/latest/dns/rrsets.html#modifying-an-rrset

func (*RecordsService) Update

func (s *RecordsService) Update(ctx context.Context, domainName, subName, recordType string, rrSet RRSet) (*RRSet, error)

Update updates RRSet (PATCH). https://desec.readthedocs.io/en/latest/dns/rrsets.html#modifying-an-rrset

type Registration

type Registration struct {
	Email    string   `json:"email,omitempty"`
	Password string   `json:"password,omitempty"`
	NewEmail string   `json:"new_email,omitempty"`
	Captcha  *Captcha `json:"captcha,omitempty"`
}

Registration a registration representation.

type Token

type Token struct {
	ID               string     `json:"id,omitempty"`
	Created          *time.Time `json:"created,omitempty"`
	LastUsed         *time.Time `json:"last_used,omitempty"`
	Owner            string     `json:"owner,omitempty"`
	UserOverride     string     `json:"user_override,omitempty"`
	Name             string     `json:"name,omitempty"`
	PermCreateDomain bool       `json:"perm_create_domain"`
	PermDeleteDomain bool       `json:"perm_delete_domain"`
	PermManageTokens bool       `json:"perm_manage_tokens"`
	IsValid          bool       `json:"is_valid,omitempty"`
	AllowedSubnets   []string   `json:"allowed_subnets,omitempty"`
	AutoPolicy       bool       `json:"auto_policy"`
	Value            string     `json:"token,omitempty"`
}

Token a token representation.

https://desec.readthedocs.io/en/latest/auth/tokens.html#token-field-reference

type TokenPoliciesService

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

TokenPoliciesService handles communication with the token policy related methods of the deSEC API.

https://desec.readthedocs.io/en/latest/auth/tokens.html

func (*TokenPoliciesService) Create

func (s *TokenPoliciesService) Create(ctx context.Context, tokenID string, policy TokenPolicy) (*TokenPolicy, error)

Create creates token policy. https://desec.readthedocs.io/en/latest/auth/tokens.html#create-additional-tokens

func (*TokenPoliciesService) Delete

func (s *TokenPoliciesService) Delete(ctx context.Context, tokenID, policyID string) error

Delete deletes a token rrset's policy. https://desec.readthedocs.io/en/latest/auth/tokens.html#token-policy-management

func (*TokenPoliciesService) Get deprecated

func (s *TokenPoliciesService) Get(ctx context.Context, tokenID string) ([]TokenPolicy, error)

Deprecated: use TokenPoliciesService.GetAll instead.

func (*TokenPoliciesService) GetAll

func (s *TokenPoliciesService) GetAll(ctx context.Context, tokenID string) ([]TokenPolicy, error)

GetAll retrieves all rrset policies for a token. https://desec.readthedocs.io/en/latest/auth/tokens.html#token-policy-management

func (*TokenPoliciesService) GetOne

func (s *TokenPoliciesService) GetOne(ctx context.Context, tokenID, policyID string) (*TokenPolicy, error)

GetOne retrieves a specific token rrset policy. https://desec.readthedocs.io/en/latest/auth/tokens.html#token-policy-management

func (*TokenPoliciesService) Update

func (s *TokenPoliciesService) Update(ctx context.Context, tokenID, policyID string, policy TokenPolicy) (*TokenPolicy, error)

Update a token policy https://desec.readthedocs.io/en/latest/auth/tokens.html#token-policy-management

type TokenPolicy

type TokenPolicy struct {
	ID              string  `json:"id,omitempty"`
	Domain          *string `json:"domain"`
	SubName         *string `json:"subname"`
	Type            *string `json:"type"`
	WritePermission bool    `json:"perm_write,omitempty"`
}

TokenPolicy represents a policy applied to a token.

type TokensService

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

TokensService handles communication with the tokens related methods of the deSEC API.

https://desec.readthedocs.io/en/latest/auth/tokens.html

func (*TokensService) Create

func (s *TokensService) Create(ctx context.Context, name string) (*Token, error)

Create creates additional tokens. https://desec.readthedocs.io/en/latest/auth/tokens.html#create-additional-tokens

func (*TokensService) Delete

func (s *TokensService) Delete(ctx context.Context, tokenID string) error

Delete deletes tokens. https://desec.readthedocs.io/en/latest/auth/tokens.html#delete-tokens

func (*TokensService) Get

func (s *TokensService) Get(ctx context.Context, id string) (*Token, error)

Get retrieves a specific token. https://desec.readthedocs.io/en/latest/auth/tokens.html#retrieving-a-specific-token NOTE: This method used to retrieve all policies for a token, that is now done by GetAll.

func (*TokensService) GetAll

func (s *TokensService) GetAll(ctx context.Context) ([]Token, error)

GetAll retrieving all current tokens. https://desec.readthedocs.io/en/latest/auth/tokens.html#retrieving-all-current-tokens

func (*TokensService) Update

func (s *TokensService) Update(ctx context.Context, id string, token *Token) (*Token, error)

Update a token. https://desec.readthedocs.io/en/latest/auth/tokens.html#modifying-a-token

type UpdateMode

type UpdateMode string

UpdateMode the mode used to bulk update operations.

const (
	// FullResource the full resource must be specified.
	FullResource UpdateMode = http.MethodPut
	// OnlyFields only fields you would like to modify need to be provided.
	OnlyFields UpdateMode = http.MethodPatch
)

Jump to

Keyboard shortcuts

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