storage

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingUser = errors.New("no user found")
)

Functions

func PublicKeySha

func PublicKeySha(key string) string

PublicKeySha returns the SHA for a public key in hex format.

Types

type DB

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

func NewTursoDB

func NewTursoDB(dbURL string) (*DB, error)

func (*DB) AddUserPublicKey

func (me *DB) AddUserPublicKey(userID int, key string) error

func (*DB) CheckUserInfo

func (me *DB) CheckUserInfo(email string, username string) error

func (*DB) CreateSession

func (me *DB) CreateSession(email string, host string) (string, error)

func (*DB) CreateUser

func (me *DB) CreateUser(key string, email string, username string) (*User, error)

func (*DB) DeleteUserPublicKey

func (me *DB) DeleteUserPublicKey(userID int, key string) error

func (*DB) GetSession

func (me *DB) GetSession(sessionID string) (*Session, error)

func (*DB) GetUserWithEmail

func (me *DB) GetUserWithEmail(email string) (*User, error)

func (*DB) GetUserWithName

func (me *DB) GetUserWithName(name string) (*User, error)

func (*DB) SetUserName

func (me *DB) SetUserName(publicID string, name string) (*User, error)

SetUserName sets a user name for the given user id.

func (*DB) UserForKey

func (me *DB) UserForKey(key string) (*User, error)

UserForKey returns the user for the given key, or optionally creates a new user with it.

func (*DB) UserFromContext

func (me *DB) UserFromContext(ctx ssh.Context) (*User, error)

func (*DB) WrapTransaction

func (me *DB) WrapTransaction(f func(tx *sql.Tx) error) error

WrapTransaction runs the given function within a transaction.

type PublicKey

type PublicKey struct {
	ID        int        `json:"id"`
	UserID    int        `json:"user_id,omitempty"`
	Key       string     `json:"key"`
	CreatedAt *time.Time `json:"created_at"`
}

PublicKey represents to public SSH key for a Smallweb user.

type Session

type Session struct {
	ID        string
	Email     string
	Host      string
	ExpiresAt time.Time
}

type User

type User struct {
	ID        int        `json:"id"`
	PublicID  string     `json:"public_id"`
	PublicKey *PublicKey `json:"public_key,omitempty"`
	Name      string     `json:"name"`
	Email     string     `json:"email"`
	CreatedAt *time.Time `json:"created_at"`
}

Jump to

Keyboard shortcuts

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