model

package
v0.0.0-...-007fb03 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTransaction

func CreateTransaction() (*runner.Tx, error)

CreateTransaction creates a new transaction without exposing the db pool.

func InitDB

func InitDB(ds string)

InitDB initializes the database pool and stores it in the model package scope.

func NukeKeysForSecret

func NukeKeysForSecret(secret Secret) error

NukeKeysForSecret blows away all keys for a given secret due to the fact that they all need to be updated when a secret is updated.

Types

type Credentials

type Credentials struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

Credentials is a convenience struct for login use.

type Key

type Key struct {
	ID     uuid.UUID `db:"id" json:"id"`
	Secret Secret    `db:"secret" json:"secret,omitempty"`
	Owner  User      `db:"owner" json:"owner"`
	Key    string    `db:"key" json:"key"`
}

Key represents an asymmetrically encrypted symmetrically key. Once decrypted, this will decrypt the associated secret.

func (Key) Create

func (k Key) Create(tx *runner.Tx, s Secret) (Key, error)

Create assigns a UUID and stores the Key struct representation into the database.

type Keys

type Keys []Key

Keys is a convenience type representing a slice of Key.

func AllKeysForSecret

func AllKeysForSecret(secret Secret) (Keys, error)

AllKeysForSecret queries for associated keys. The referenced secret in the key is assigned to the secret passed in.

type Secret

type Secret struct {
	ID         uuid.UUID `db:"id" json:"id"`
	Author     User      `db:"author" json:"author"`
	Keys       Keys      `json:"keys"`
	CipherText string    `db:"cipher_text" json:"cipher_text"`
	IV         string    `db:"iv" json:"iv"`
}

Secret represents an symmetrically encrypted piece of data. It does not encompass an individual key.

func GetSecret

func GetSecret(id uuid.UUID) (Secret, error)

GetSecret retreives a Secret for the given ID.

func (Secret) Create

func (s Secret) Create() (Secret, error)

Create assigns a UUID and stores the Secret struct representation into the database.

func (Secret) Delete

func (s Secret) Delete() error

Delete removes a saved Secret. Please note to any consumer of this function that this removes the Secret and associated Keys from the database. You still have to roll the password in this Secret as individuals may still hold a copy. Common sense, but just a friendly reminder :)

func (Secret) Update

func (s Secret) Update() (Secret, error)

Update modifies a saved Secret. This will delete all current Keys associated with the Secret and replace all fields with what got provided.

func (Secret) Validate

func (s Secret) Validate() error

Validate ensures that nested usage of Secret contains an ID

type Secrets

type Secrets []Secret

Secrets is a convenience type representing a slice of Secret.

func AllSecrets

func AllSecrets(author uuid.UUID) (Secrets, error)

AllSecrets returns all secrets authored by given user id (taken from JWT)

type Token

type Token struct {
	Token string
}

Token is a simple wrapper for compatibility with the generalized API handler.

type User

type User struct {
	ID        uuid.UUID `db:"id" json:"id,omitempty"`
	Fullname  string    `db:"fullname" json:"fullname"`
	Username  string    `db:"username" json:"username"`
	Password  string    `db:"password" json:"password,omitempty"`
	PublicKey string    `db:"public_key" json:"public_key,omitempty"`
}

User represents an individual that has access to Roccaforte

func UserByUsername

func UserByUsername(un string) (User, error)

UserByUsername retreives a user based on provided username.

func (User) Create

func (u User) Create() (User, error)

Create assigns a UUID and stores the User struct representation into the database.

func (User) MarshalJSON

func (u User) MarshalJSON() ([]byte, error)

MarshalJSON overrides default functionality and sets password to empty string to omit on serialization.

func (User) Validate

func (u User) Validate() error

Validate ensures that nested usage of User contains an ID

type Users

type Users []User

Users is a convenience type representing a slice of User.

func AllUsers

func AllUsers() (Users, error)

AllUsers retreives all users from the database.

Jump to

Keyboard shortcuts

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