storage

package
v0.0.0-...-56de86b Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package storage provides a storage backend for the Sharkey server. It provides an API for recording issuance of certificates. By default it is backed by a SQL database, but you could swap this package out for another one if you prefer something else -- many key-value stores would probably work.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MysqlStorage

type MysqlStorage struct {
	*sql.DB
}

MysqlStorage implements the storage interface, using Mysql for storage.

func NewMysql

func NewMysql(cfg config.Database) (*MysqlStorage, error)

func (*MysqlStorage) Migrate

func (my *MysqlStorage) Migrate(migrationsDir string) error

Migrate runs any pending migrations

func (*MysqlStorage) QueryGitHubMapping

func (my *MysqlStorage) QueryGitHubMapping(ssoIdentity string) (string, error)

func (*MysqlStorage) QueryHostkeys

func (my *MysqlStorage) QueryHostkeys() (ResultIterator, error)

func (*MysqlStorage) RecordGitHubMapping

func (my *MysqlStorage) RecordGitHubMapping(mapping map[string]string) error

func (*MysqlStorage) RecordIssuance

func (my *MysqlStorage) RecordIssuance(certType uint32, principal string, pubkey ssh.PublicKey) (uint64, error)

type ResultIterator

type ResultIterator interface {
	Next() bool
	Get() (principal string, key ssh.PublicKey, err error)
}

ResultIterator works like a typed sql.Rows: Call Next() and then Get() until Next() returns false

type SqlResultIterator

type SqlResultIterator struct {
	*sql.Rows
}

This is shared between sqlite & mysql

func (*SqlResultIterator) Get

func (*SqlResultIterator) Next

func (r *SqlResultIterator) Next() bool

type SqliteStorage

type SqliteStorage struct {
	*sql.DB
}

SqliteStorage implements the storage interface, using Sqlite for storage.

func NewSqlite

func NewSqlite(cfg config.Database) (*SqliteStorage, error)

func (*SqliteStorage) Migrate

func (s *SqliteStorage) Migrate(migrationsDir string) error

func (*SqliteStorage) QueryGitHubMapping

func (s *SqliteStorage) QueryGitHubMapping(ssoIdentity string) (string, error)

func (*SqliteStorage) QueryHostkeys

func (s *SqliteStorage) QueryHostkeys() (ResultIterator, error)

func (*SqliteStorage) RecordGitHubMapping

func (s *SqliteStorage) RecordGitHubMapping(mapping map[string]string) error

func (*SqliteStorage) RecordIssuance

func (s *SqliteStorage) RecordIssuance(certType uint32, principal string, pubkey ssh.PublicKey) (uint64, error)

type Storage

type Storage interface {
	// Record an issuance of type (host or client) to principal with pubkey string
	// Returns an integer ID for the record (ie, database row primary key)
	RecordIssuance(certType uint32, principal string, pubkey ssh.PublicKey) (uint64, error)

	// Query all hostkeys
	QueryHostkeys() (ResultIterator, error)

	// Takes a path to DB migration locations
	Migrate(string) error

	// Record mapping of user identities to github username
	RecordGitHubMapping(mapping map[string]string) error

	// Retrieve github username given sso identity
	QueryGitHubMapping(ssoIdentity string) (string, error)

	Ping() error
	Close() error
}

func FromConfig

func FromConfig(cfg config.Database) (Storage, error)

Given a database configuration, return an appropriate Storage interface

Jump to

Keyboard shortcuts

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