db

package
v0.0.76 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2022 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserExistingZoneMember = errors.New("user is already a member of this zone")
	ErrUserNotFound           = errors.New("user not found")
	ErrZoneNotFound           = errors.New("zone not found")
	ErrLastZoneUser           = errors.New("unable to remove last user from zone")
)
View Source
var (
	GroupEnabled = "core.ENABLED" // User is permitted to make API requests
	GroupAdmin   = "core.ADMIN"   // User is permitted to modify all resources

	ErrInvalidOrExpiredPasswordResetToken = errors.New("password reset token is invalid or expired")
	ErrUserOwnsZones                      = errors.New("user has zones without other users, delete or add another user to these zones before deleting this user account")
)
View Source
var (
	ErrValidationTimeExceeded = errors.New("script validation time exceeded: " + validationTimeInterval.String())
)

Functions

func Connect

func Connect(dsn string) (*gorm.DB, error)

Connect opens a connection to the database and runs migrations

func CredentialAddOrUpdate added in v0.0.69

func CredentialAddOrUpdate(db *gorm.DB, fqdn, cert, key string) error

CredentialAddOrUpdate adds a new credential to the database

func CredentialDelete added in v0.0.73

func CredentialDelete(db *gorm.DB, fqdn string) error

CredentialDelete deletes a credential from the database

func CredentialsContains added in v0.0.73

func CredentialsContains(credentials []Credential, fqdn string) bool

CredentialsContains checks if a FQDN is in the given list of credentials

func Open added in v0.0.74

func Open(dsn string) (*gorm.DB, error)

Open opens a postgres database connection with a new logger

func RecordAdd

func RecordAdd(db *gorm.DB, record *Record) error

RecordAdd adds a new record to a zone

func RecordDelete

func RecordDelete(db *gorm.DB, recordID string) (bool, error)

RecordDelete deletes a DNS record from a zone

func RecordUpdate

func RecordUpdate(db *gorm.DB, updates *Record) error

RecordUpdate updates a DNS record

func ScriptRecords added in v0.0.51

func ScriptRecords(db *gorm.DB) (map[string]string, error)

ScriptRecords returns a map of DNS labels to script strings

func ScriptValidate added in v0.0.48

func ScriptValidate(script, origin string) error

ScriptValidate attempts to compile a script

func SuffixList

func SuffixList() ([]string, error)

SuffixList gets the public suffix list

func TestSetup

func TestSetup() (*gorm.DB, error)

TestSetup sets up the test environment by opening a database connection, dropping all tables, and inserting test data

func UserAdd

func UserAdd(db *gorm.DB, email string, password string, refer string) error

UserAdd creates a new user

func UserCreatePasswordResetToken added in v0.0.41

func UserCreatePasswordResetToken(db *gorm.DB, email string) (string, error)

UserCreatePasswordResetToken creates a User's password reset token

func UserDelete

func UserDelete(db *gorm.DB, email string) error

UserDelete deletes a user

func UserGroupAdd

func UserGroupAdd(db *gorm.DB, uuid string, group string) error

UserGroupAdd adds a role to a Group

func UserGroupDelete

func UserGroupDelete(db *gorm.DB, uuid string, group string) error

UserGroupDelete removes a role from a Group

func UserResetPassword

func UserResetPassword(db *gorm.DB, email string, password string) error

UserResetPassword resets a User's password

func UserValidatePasswordResetToken added in v0.0.41

func UserValidatePasswordResetToken(db *gorm.DB, email, token string) error

UserValidatePasswordResetToken checks that a provided password reset token is valid

func ZoneAdd

func ZoneAdd(db *gorm.DB, zone string, user string) error

ZoneAdd adds a DNS zone by zone name and user email

func ZoneDelete

func ZoneDelete(db *gorm.DB, zone string) (bool, error)

ZoneDelete deletes a DNS zone

func ZoneIncrementSerial added in v0.0.60

func ZoneIncrementSerial(db *gorm.DB, uuid string) error

ZoneIncrementSerial increments a zone's SOA serial by 1

func ZoneRotateDNSSECKey

func ZoneRotateDNSSECKey(db *gorm.DB, uuid string) error

ZoneRotateDNSSECKey rotates a zone's DNSSEC key

func ZoneUserAdd

func ZoneUserAdd(db *gorm.DB, zoneID string, userEmail string) error

ZoneUserAdd adds a user to a zone

func ZoneUserAuthorized

func ZoneUserAuthorized(db *gorm.DB, zoneUuid string, userUuid string) error

ZoneUserAuthorized checks if a user is authorized for a zone

func ZoneUserDelete

func ZoneUserDelete(db *gorm.DB, zoneUuid string, userEmail string) error

ZoneUserDelete deletes a user from a zone

Types

type Credential added in v0.0.69

type Credential struct {
	FQDN      string    `gorm:"primary_key" json:"id"`
	Cert      string    `json:"cert"`
	Key       string    `json:"key"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

func CredentialList added in v0.0.69

func CredentialList(db *gorm.DB) ([]Credential, error)

CredentialList gets a list of credentials

type DNSSECKey

type DNSSECKey struct {
	Base           string // Base key filename prefix
	Key            string // DNSKEY
	Private        string // Private key
	DSKeyTag       int    // DS key tag
	DSAlgo         int    // DS algorithm
	DSDigestType   int    // DS digest type
	DSDigest       string // DS digest
	DSRecordString string // Full DS record in zone file format
}

DNSSECKey stores a DNSSEC signing key

func NewKey

func NewKey(zone string) (*DNSSECKey, error)

NewKey generates a new DNSSEC signing key for a zone

type Record

type Record struct {
	ID     string `gorm:"primaryKey,type:uuid;default:uuid_generate_v4()" json:"id"`
	Type   string `json:"type" validate:"required,dns-rrtype"`
	Label  string `json:"label" validate:"required"`
	Value  string `json:"value"`
	TTL    uint32 `json:"ttl" validate:"gte=300,lte=2147483647"`
	Proxy  bool   `json:"proxy"`
	ZoneID string `json:"zone"`

	Zone      Zone      `json:"-" validate:"-"` // Zone is populated by the database so will be zero value at record creation time
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

Record stores a DNS record

func RecordList

func RecordList(db *gorm.DB, zone string) ([]Record, error)

RecordList returns a list of DNS records for a zone

func RecordListAll added in v0.0.74

func RecordListAll(db *gorm.DB) ([]Record, error)

RecordListAll returns a list of all DNS records

type User

type User struct {
	ID                 string         `gorm:"primaryKey,type:uuid;default:uuid_generate_v4()" json:"id"`
	Email              string         `gorm:"uniqueIndex" json:"email" validate:"required,email,min=6,max=32"`
	Password           string         `gorm:"-" json:"password" validate:"required,min=8,max=256"`
	Refer              string         `json:"refer"` // Where did you hear about Packetframe?
	Groups             pq.StringArray `gorm:"type:text[]" json:"groups"`
	PasswordHash       []byte         `json:"-"`
	APIKey             string         `json:"-"` // Rotated manually by user if needed
	Token              string         `json:"-"` // Rotated every n minutes (TODO: autorotate this)
	PasswordResetToken string         `json:"-"` // <token>:<unix timestamp when it was created>
	CreatedAt          time.Time      `json:"-"`
	UpdatedAt          time.Time      `json:"-"`
}

func UserFindByAuth

func UserFindByAuth(db *gorm.DB, id string) (*User, error)

UserFindByAuth finds a user by API key and returns nil if no user exists

func UserFindByEmail

func UserFindByEmail(db *gorm.DB, email string) (*User, error)

UserFindByEmail finds a user by email and returns nil if no user exists

func UserFindById added in v0.0.33

func UserFindById(db *gorm.DB, userId string) (*User, error)

UserFindById finds a user by ID and returns nil if no user exists

func UserList

func UserList(db *gorm.DB) ([]User, error)

UserList gets a list of all users

type Zone

type Zone struct {
	ID         string         `gorm:"primaryKey,type:uuid;default:uuid_generate_v4()" json:"id"`
	Zone       string         `gorm:"uniqueIndex" json:"zone" validate:"required,fqdn"`
	Serial     uint64         `json:"-"`
	DNSSEC     DNSSECKey      `gorm:"embedded" json:"-"`
	Users      pq.StringArray `gorm:"type:text[]" json:"users"`
	UserEmails pq.StringArray `gorm:"type:text[]" json:"user_emails"`
	CreatedAt  time.Time      `json:"-"`
	UpdatedAt  time.Time      `json:"-"`
}

Zone stores a DNS zone

func ZoneFind

func ZoneFind(db *gorm.DB, zone string) (*Zone, error)

ZoneFind finds a zone by FQDN and returns nil if no zone exists

func ZoneFindByID

func ZoneFindByID(db *gorm.DB, zoneUuid string) (*Zone, error)

ZoneFindByID gets a zone by UUID

func ZoneList

func ZoneList(db *gorm.DB) ([]Zone, error)

ZoneList gets a list of all zones

func ZoneUserGetZones

func ZoneUserGetZones(db *gorm.DB, userUuid string) ([]Zone, error)

ZoneUserGetZones gets all zones a user is a member of

Jump to

Keyboard shortcuts

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