database

package
v0.0.0-...-cc87309 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package database provides functions and types for interacting with MongoDB, as well as a message queue built on mongo

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DNSRecord

type DNSRecord struct {
	RRString string `json:"rr" validate:"required"`
}

DNSRecord stores a DNS RR string

type Database

type Database struct {
	Db *mongo.Database
}

Database wraps a *mongo.Database

func New

func New() *Database

New constructs a new database object

func (Database) AddMetadata

func (d Database) AddMetadata(m MetadataElement) error

AddMetadata adds a MetadataElement to the database

func (Database) AddQueueMessage

func (d Database) AddQueueMessage(message QueueMessage) error

AddQueueMessage appends a message to the queue

func (Database) GetMetadata

func (d Database) GetMetadata(l MetaLabel) (MetadataElement, error)

GetMetadata returns the metadata object with specified label

func (Database) GetNode

func (d Database) GetNode(id string) bson.M

GetNode looks up a node by string ID

func (Database) ListQueue

func (d Database) ListQueue() ([]QueueMessage, error)

ListQueue returns all messages in queue

func (Database) NextQueueMessage

func (d Database) NextQueueMessage() (QueueMessage, error)

NextQueueMessage retrieves a single queue message

func (Database) QueueConfirm

func (d Database) QueueConfirm(message QueueMessage) error

QueueConfirm marks a queue message as complete

type MetaLabel

type MetaLabel int

Metadata label "enum"

const (
	LabelAcmeAccount MetaLabel = iota
	LabelNetworkConfig
)

func (MetaLabel) String

func (l MetaLabel) String() string

String gets the string representation of MetaLabel

type MetadataElement

type MetadataElement struct {
	ID      primitive.ObjectID `bson:"-" bson:"_id,omitempty"`
	Label   string             `bson:"label"`
	Payload map[string]string  `bson:"payload"`
}

MetadataElement stores a document in the metadata collection in mongo

type Node

type Node struct {
	ID         string  `json:"-" bson:"_id,omitempty"`
	Endpoint   string  `json:"endpoint" validate:"required"`
	Provider   string  `json:"provider" validate:"required"`
	Latitude   float32 `json:"latitude" validate:"required"`
	Longitude  float32 `json:"longitude" validate:"required"`
	Region     string  `json:"region" validate:"region"`
	Authorized bool    `json:"-"`
}

Node stores a single edge node

type QueueMessage

type QueueMessage struct {
	ID       primitive.ObjectID `json:"-" bson:"_id,omitempty"`
	Payload  map[string]string  `json:"payload"`
	Created  int64              `json:"-"`
	Locked   bool               `json:"-"`
	LockedAt int64              `json:"-"`
}

QueueMessage stores a single queue entry

type User

type User struct {
	ID       string `json:"-" bson:"_id,omitempty"`
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required"`
	APIKey   string `json:"-"`
	Enabled  bool   `json:"-"`
	Admin    bool   `json:"-"`
	Hash     []byte `json:"-"`
}

User stores a CDN user

type Zone

type Zone struct {
	ID      string           `json:"-" bson:"_id,omitempty"`
	Zone    string           `json:"zone" validate:"required,fqdn"`
	Users   []string         `json:"-"`
	Serial  uint64           `json:"-"`
	Records []string         `json:"-"`
	DNSSEC  crypto.DNSSECKey `json:"-"`
}

Zone stores a DNS zone

Jump to

Keyboard shortcuts

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