postgres

package
v0.0.0-...-02d3d6b Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: MIT Imports: 8 Imported by: 0

README

Hancock PostgreSQL Driver

Implements the hancock key.Storage interface with PostgreSQL.

Config

Typical configuration may look like the following:

{
    "backend": "postgres",
    "storage": {
        "encryption": "aes",
	"key": "secret",

        "user": "hancock",
	"password": "password",

	"host": "127.0.0.1",
	"port": 5432,
        "dbname": "hancock",

	"sslmode": "require"
    }
}

The database password may also be passed as environment variable by setting HANCOCK_POSTGRES_PASSWORD. The configuration file has precendence over environment variables.

Running migrations

Migrations are supported by rambler. Please install rambler:

go install github.com/elwinar/rambler

Then edit the rambler.dev.config database connections settings appropriately for your setup, and, from this directory, run:

rambler -c rambler.dev.config apply --all

Documentation

Overview

Package postgres is postgres database implementation of the `key.Storage` interface

Index

Constants

View Source
const (
	// EnvPostgresPassword is the environment variable name for the postgres password.
	EnvPostgresPassword = "HANCOCK_POSTGRES_PASSWORD"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	key.Config

	// The database user
	User string `json:"user"`
	// The user password
	Password string `json:"password"`

	// The hostname of the database
	Host string `json:"host"`
	// The port of the database
	Port int `json:"port"`
	// The database name
	Name string `json:"dbname"`

	// The ssl mode for connecting to the database.
	// See https://www.postgresql.org/docs/9.1/ssl-tcp.html for options and info.
	SSLMode string `json:"sslmode"`
}

Config is a struct for holding settings for a postgres backed key `Storage`.

func LoadConfig

func LoadConfig(rawConfig []byte) (*Config, error)

LoadConfig loads the config provided in the []byte rawConfig. It is assummed the array encodes a json configuration of `Config`.

type KeyStorage

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

KeyStorage is an implementation of `key.Storage` using a postgres as a backend.

func (*KeyStorage) Create

func (s *KeyStorage) Create(alg string, opts key.Opts) (*key.Key, error)

Create inserts a new `key.Key` into the database. The id will be generated as a v4 uuid.

func (*KeyStorage) Get

func (s *KeyStorage) Get(sid string) (*key.Key, error)

Get fetches the `key.Key` specified by the unique sid from the database. All IDs MUST parse to a valid uuid.

func (*KeyStorage) Open

func (s *KeyStorage) Open(rawConfig []byte) error

Open configures the `KeyStorage` using rawConfig and connects to the database. If validation passes, the return value is the result of pinging the database.

Jump to

Keyboard shortcuts

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