store

package
v0.0.0-...-d28c369 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OS_READ        = 04
	OS_WRITE       = 02
	OS_EX          = 01
	OS_USER_SHIFT  = 6
	OS_GROUP_SHIFT = 3
	OS_OTH_SHIFT   = 0

	OS_USER_R   = OS_READ << OS_USER_SHIFT
	OS_USER_W   = OS_WRITE << OS_USER_SHIFT
	OS_USER_X   = OS_EX << OS_USER_SHIFT
	OS_USER_RW  = OS_USER_R | OS_USER_W
	OS_USER_RWX = OS_USER_RW | OS_USER_X

	OS_GROUP_R   = OS_READ << OS_GROUP_SHIFT
	OS_GROUP_W   = OS_WRITE << OS_GROUP_SHIFT
	OS_GROUP_X   = OS_EX << OS_GROUP_SHIFT
	OS_GROUP_RW  = OS_GROUP_R | OS_GROUP_W
	OS_GROUP_RWX = OS_GROUP_RW | OS_GROUP_X

	OS_OTH_R   = OS_READ << OS_OTH_SHIFT
	OS_OTH_W   = OS_WRITE << OS_OTH_SHIFT
	OS_OTH_X   = OS_EX << OS_OTH_SHIFT
	OS_OTH_RW  = OS_OTH_R | OS_OTH_W
	OS_OTH_RWX = OS_OTH_RW | OS_OTH_X

	OS_ALL_R   = OS_USER_R | OS_GROUP_R | OS_OTH_R
	OS_ALL_W   = OS_USER_W | OS_GROUP_W | OS_OTH_W
	OS_ALL_X   = OS_USER_X | OS_GROUP_X | OS_OTH_X
	OS_ALL_RW  = OS_ALL_R | OS_ALL_W
	OS_ALL_RWX = OS_ALL_RW | OS_GROUP_X
)

filemode.go will contain a readable and accessible list of file modes to simplify a filesystem interaction (such as saving configuration, DNS records and logfiles to a file).

ref: https://stackoverflow.com/questions/28969455/how-to-properly-instantiate-os-filemode

Variables

View Source
var (
	ErrNoAddr           error = errors.New("no IP address provided")
	ErrNoName           error = errors.New("no domain name provided")
	ErrNoType           error = errors.New("no DNS record type provided")
	ErrNotFound         error = errors.New("entry was not found")
	ErrDoesNotExist     error = errors.New("record does not exist")
	ErrAlreadyExists    error = errors.New("entry already exists")
	ErrZeroBytesWritten error = errors.New("zero bytes written")
	ErrSync             error = errors.New("sync error")
	ErrZeroRecords      error = errors.New("zero records in the store")
)
View Source
var (
	// RecordTypeKeys converts a RecordType to uint16
	RecordTypeKeys = map[RecordType]uint16{
		TypeNone:  0,
		TypeA:     1,
		TypeCNAME: 5,
		TypeAAAA:  28,
		TypeANY:   255,
	}
	// RecordTypeKeys converts a RecordType to string
	RecordTypeStrings = map[RecordType]string{
		TypeNone:  "",
		TypeA:     "A",
		TypeCNAME: "CNAME",
		TypeAAAA:  "AAAA",
		TypeANY:   "ANY",
	}
	// RecordTypeKeys converts a string to RecordType
	RecordTypeVals = map[string]RecordType{
		"":      TypeNone,
		"A":     TypeA,
		"CNAME": TypeCNAME,
		"AAAA":  TypeAAAA,
		"ANY":   TypeANY,
	}
	// RecordTypeKeys converts a RecordType string to uint16
	RecordTypeInts = map[string]uint16{
		"":      0,
		"A":     1,
		"CNAME": 5,
		"AAAA":  28,
		"ANY":   255,
	}
)
View Source
var (
	ErrUnimplemented error = errors.New("unimplemented DNS Record Store")
)

Functions

func Unimplemented

func Unimplemented() unimplemented

Unimplemented returns an unimplemented (and invalid) store.Repository

Types

type Record

type Record struct {
	Type string `json:"type,omitempty"`
	Name string `json:"name,omitempty"`
	Addr string `json:"address,omitempty"`
}

Record defines the basic elements of a DNS Record

type RecordBuilder

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

RecordBuilder is a helper struct to modularly build a store.Record

func New

func New() *RecordBuilder

New returns a new pointer to a RecordBuilder

func (*RecordBuilder) Addr

func (b *RecordBuilder) Addr(s string) *RecordBuilder

Addr sets the record's IP address, in the RecordBuilder.

Returns itself to allow method chaining

func (*RecordBuilder) Build

func (b *RecordBuilder) Build() *Record

Build returns a record with the set variables in the builder

func (*RecordBuilder) Name

func (b *RecordBuilder) Name(s string) *RecordBuilder

Name sets the record's domain name, in the RecordBuilder.

Returns itself to allow method chaining

func (*RecordBuilder) Type

func (b *RecordBuilder) Type(s string) *RecordBuilder

Type sets the record's type, in the RecordBuilder.

Returns itself to allow method chaining

type RecordType

type RecordType uint16

RecordType holds an enum of the supported DNS record types, from github.com/miekg/dns

const (
	TypeNone  RecordType = 0  // Unset
	TypeA     RecordType = 1  // A record
	TypeCNAME RecordType = 5  // AAAA record
	TypeAAAA  RecordType = 28 // CNAME record
	TypeANY   RecordType = 255
)

func (RecordType) String

func (t RecordType) String() string

String implements the Stringer interface

type RecordWithTarget

type RecordWithTarget struct {
	Record `json:"record,omitempty"`
	Target string `json:"target,omitempty"`
}

type Repository

type Repository interface {
	// Create will add a new entry in they key-value store to include a
	// new Record, returning an error
	Create(context.Context, ...*Record) error

	// List will fetch all records in the key-value store
	List(context.Context) ([]*Record, error)

	// FindByTypeAndDomain will fetch an address based on its address and type strings
	//
	// FindByTypeAndDomain(ctx, "A", "service.mydomain") -> { "127.0.0.1", nil }
	FindByTypeAndDomain(context.Context, string, string) (*Record, error)

	// FilterByDomain will fetch an address based on its address for all types
	//
	// FilterByDomain(ctx, "service.mydomain") -> { ["127.0.0.1"], nil }
	FilterByDomain(context.Context, string) ([]*Record, error)

	// FilterByDest will fetch an address based on its target IP
	//
	// FilterByDest(ctx, "127.0.0.1") -> { ["service.mydomain"], nil }
	FilterByDest(context.Context, string) ([]*Record, error)

	// Update will modify an existing record by targetting its domain string,
	// and by supplying a new version of the Record to update. Returns an error
	Update(context.Context, string, *Record) error

	// DeleteByAddress removes all records with IP address `addr`
	DeleteByAddress(ctx context.Context, addr string) error

	// DeleteByDomain removes all records with domain name `name`
	DeleteByDomain(ctx context.Context, name string) error

	// DeleteByTypeAndDomain removes all records with record type `rtype` and domain name `name`
	DeleteByTypeAndDomain(ctx context.Context, rtype, name string) error
}

Repository defines the set of operations that a record store should expose

This will consist of basic CRUD operations against a key-value store, to add, list, get, update or delete DNS Records from the key-value store.

Additionally, it is exposing both GetByAddr and GetByDest methods to fetch items in the records list interchangeably

func WithTrace

func WithTrace(r Repository) Repository

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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