datastore

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidQuery = errors.New("Invalid DB Query argument")
View Source
var ErrUserNotFound = errors.New("User account not found")

Functions

This section is empty.

Types

type ActionToken

type ActionToken struct {
	gorm.Model
	TokenID   string
	UserExtID string
	UserID    uint
	Action    string
	Used      bool
	UsedAt    time.Time
	ExpiresAt time.Time
}

ActionToken Time based One Time Password Token object

func (*ActionToken) GetAction

func (token *ActionToken) GetAction() string

GetAction fetches the token action

func (*ActionToken) GetExpiry

func (token *ActionToken) GetExpiry() time.Time

GetExpiry fetches the token expiry time

func (*ActionToken) GetTokenID

func (token *ActionToken) GetTokenID() string

GetTokenID fetches the action token ID

func (*ActionToken) GetUserExtID

func (token *ActionToken) GetUserExtID() string

func (*ActionToken) IsUsed

func (token *ActionToken) IsUsed() bool

IsUsed checks if a token has been used

func (*ActionToken) SetUsed

func (token *ActionToken) SetUsed(t time.Time)

SetUsed sets the used state for the action token

type AuditEvent

type AuditEvent struct {
	gorm.Model
	UserID uint
	Type   string
	Time   time.Time
	Data   string
}

AuditEvent for a user account

func (*AuditEvent) GetData

func (ae *AuditEvent) GetData() (map[string]string, error)

GetData fetches a map of the associated data

func (*AuditEvent) GetTime

func (ae *AuditEvent) GetTime() time.Time

GetTime fetches the time at which the event occured

func (*AuditEvent) GetType

func (ae *AuditEvent) GetType() string

GetType fetches the type of the event

type BackupToken

type BackupToken struct {
	gorm.Model
	UserID uint
	Name   string
	Secret string
	Used   bool
	UsedAt time.Time
}

BackupToken 2fa backup code object

func (*BackupToken) GetCreatedAt

func (token *BackupToken) GetCreatedAt() time.Time

func (*BackupToken) GetHashedSecret

func (token *BackupToken) GetHashedSecret() string

GetHashedSecret fetches the hashed token secret

func (*BackupToken) GetName

func (token *BackupToken) GetName() string

GetName fetches the token Name

func (*BackupToken) GetUsedAt

func (token *BackupToken) GetUsedAt() time.Time

func (*BackupToken) IsUsed

func (token *BackupToken) IsUsed() bool

IsUsed checks if a token has been used

func (*BackupToken) SetUsed

func (token *BackupToken) SetUsed()

SetUsed marks a token as used

type DataStore

type DataStore struct {
	*oauthstore.OauthStore
	// contains filtered or unexported fields
}

DataStore instance storage

func NewDataStore

func NewDataStore(dbString string) (*DataStore, error)

NewDataStore Create a datastore instance

func (*DataStore) AddAuditEvent

func (dataStore *DataStore) AddAuditEvent(userid, eventType string, eventTime time.Time, data map[string]string) (interface{}, error)

AddAuditEvent creates an audit event in the database

func (*DataStore) AddBackupToken

func (dataStore *DataStore) AddBackupToken(userid, name, secret string) (interface{}, error)

AddBackupToken creates a backupt token token instance to a user in the database

func (*DataStore) AddBackupTokens

func (dataStore *DataStore) AddBackupTokens(userid string, names, secrets []string) (interface{}, error)

AddBackupToken creates a backupt token token instance to a user in the database

func (*DataStore) AddFidoToken

func (dataStore *DataStore) AddFidoToken(userid, name, keyHandle, publicKey, certificate string, counter uint) (interface{}, error)

AddFidoToken creates a fido token instance in the database

func (*DataStore) AddTotpToken

func (ds *DataStore) AddTotpToken(userid, name, secret string, counter uint) (interface{}, error)

AddTotpToken adds a TOTP token to the provided user

func (*DataStore) AddUser

func (dataStore *DataStore) AddUser(email, username, pass string) (interface{}, error)

AddUser Adds a user to the datastore

func (*DataStore) ClearPendingBackupTokens

func (dataStore *DataStore) ClearPendingBackupTokens(userid string) error

ClearPendingBackupTokens removes any unused backup tokens

func (*DataStore) Close

func (dataStore *DataStore) Close()

Close an open datastore instance

func (*DataStore) CreateActionToken

func (ds *DataStore) CreateActionToken(userExtID, tokenID, action string, expiry time.Time) (interface{}, error)

CreateActionToken adds an action token to the provided user account

func (*DataStore) Drop

func (dataStore *DataStore) Drop()

func (*DataStore) ForceSync

func (dataStore *DataStore) ForceSync()

ForceSync Drop and create existing tables to match required schema WARNING: do not run this on a live database...

func (*DataStore) GetActionToken

func (ds *DataStore) GetActionToken(tokenID string) (interface{}, error)

GetActionToken fetches an action token by token id

func (*DataStore) GetActionTokens

func (ds *DataStore) GetActionTokens(userid string) ([]interface{}, error)

GetActionTokens fetches tokens attached to a given user

func (*DataStore) GetAuditEvents

func (dataStore *DataStore) GetAuditEvents(userid string) ([]interface{}, error)

GetAuditEvents fetches a list of audit events for a given userr

func (*DataStore) GetBackupTokenByName

func (dataStore *DataStore) GetBackupTokenByName(userid, name string) (interface{}, error)

GetBackupTokenByName fetches the named backup token for a specified user

func (*DataStore) GetBackupTokens

func (dataStore *DataStore) GetBackupTokens(userid string) ([]interface{}, error)

GetBackupTokens fetches the backup tokens for the specified user

func (*DataStore) GetFidoTokens

func (dataStore *DataStore) GetFidoTokens(userid string) ([]interface{}, error)

GetFidoTokens fetches the fido tokens for a provided user

func (*DataStore) GetTokens

func (dataStore *DataStore) GetTokens(user interface{}) (interface{}, error)

GetTokens Fetches tokens attached to a user account

func (*DataStore) GetTotpTokens

func (ds *DataStore) GetTotpTokens(userid string) ([]interface{}, error)

GetTotpTokens fetches tokens attached to a given user

func (*DataStore) GetUserByEmail

func (dataStore *DataStore) GetUserByEmail(email string) (interface{}, error)

GetUserByEmail Fetches a user account by email

func (*DataStore) GetUserByExtID

func (dataStore *DataStore) GetUserByExtID(extID string) (interface{}, error)

GetUserByExtID Fetch a user account by external id

func (*DataStore) GetUserByUsername

func (dataStore *DataStore) GetUserByUsername(username string) (interface{}, error)

GetUserByUsername Fetches a user account by username

func (*DataStore) RemoveFidoToken

func (dataStore *DataStore) RemoveFidoToken(token interface{}) error

RemoveFidoToken deletes a totp token

func (*DataStore) RemoveTotpToken

func (ds *DataStore) RemoveTotpToken(token interface{}) error

RemoveTotpToken deletes a totp token

func (*DataStore) Sync

func (dataStore *DataStore) Sync()

func (*DataStore) UpdateActionToken

func (ds *DataStore) UpdateActionToken(token interface{}) (interface{}, error)

UpdateActionToken updates a TOTP token instance in the database

func (*DataStore) UpdateBackupToken

func (dataStore *DataStore) UpdateBackupToken(token interface{}) (interface{}, error)

UpdateBackupToken updates a backup token instance

func (*DataStore) UpdateFidoToken

func (dataStore *DataStore) UpdateFidoToken(token interface{}) (interface{}, error)

UpdateFidoToken updates a fido token instance

func (*DataStore) UpdateTotpToken

func (ds *DataStore) UpdateTotpToken(token interface{}) (interface{}, error)

UpdateTotpToken updates a TOTP token instance in the database

func (*DataStore) UpdateUser

func (dataStore *DataStore) UpdateUser(user interface{}) (interface{}, error)

UpdateUser Update a user object

type FidoToken

type FidoToken struct {
	gorm.Model
	ExtID       string
	UserID      uint
	Name        string
	KeyHandle   string
	PublicKey   string
	Certificate string
	Counter     uint
	LastUsed    time.Time
}

FidoToken Fido/U2F token object

func (*FidoToken) GetCertificate

func (token *FidoToken) GetCertificate() string

GetCertificate fetches the token Certificate

func (*FidoToken) GetCounter

func (token *FidoToken) GetCounter() uint

GetCounter fetches the token usage counter

func (*FidoToken) GetExtID

func (token *FidoToken) GetExtID() string

GetExtID fetches the external ID for a token

func (*FidoToken) GetKeyHandle

func (token *FidoToken) GetKeyHandle() string

GetKeyHandle fetches the token KeyHandle

func (*FidoToken) GetLastUsed

func (token *FidoToken) GetLastUsed() time.Time

GetLastUsed fetches the token LastUsed time

func (*FidoToken) GetName

func (token *FidoToken) GetName() string

GetName fetches the token Name

func (*FidoToken) GetPublicKey

func (token *FidoToken) GetPublicKey() string

GetPublicKey fetches the token PublicKey

func (*FidoToken) SetCounter

func (token *FidoToken) SetCounter(count uint)

SetCounter Sets the token usage counter

func (*FidoToken) SetLastUsed

func (token *FidoToken) SetLastUsed(used time.Time)

SetLastUsed sets the token LastUsed time

type QueryFilter

type QueryFilter struct {
	Limit  uint // Number of objects to return
	Offset uint // Offset of objects to return
}

QueryFilter filter types

type TotpToken

type TotpToken struct {
	gorm.Model
	ExtID      string
	UserID     uint
	Name       string
	Secret     string
	UsageCount uint
	LastUsed   time.Time
}

TotpToken Time based One Time Password Token object

func (*TotpToken) GetCounter

func (token *TotpToken) GetCounter() uint

GetCounter fetches the fido token Counter

func (*TotpToken) GetExtID

func (token *TotpToken) GetExtID() string

GetExtID fetches the external ID for a token

func (*TotpToken) GetLastUsed

func (token *TotpToken) GetLastUsed() time.Time

GetLastUsed fetches the fido token LastUsed time

func (*TotpToken) GetName

func (token *TotpToken) GetName() string

GetName fetches the fido token Name

func (*TotpToken) GetSecret

func (token *TotpToken) GetSecret() string

GetSecret fetches the fido token Secret

func (*TotpToken) SetCounter

func (token *TotpToken) SetCounter(count uint)

SetCounter sets the fido token usage counter

func (*TotpToken) SetLastUsed

func (token *TotpToken) SetLastUsed(used time.Time)

SetLastUsed sets the fido token LastUsed time

type User

type User struct {
	ID              uint      `gorm:"primary_key" description:"External user ID"`
	CreatedAt       time.Time `description:"Creation time"`
	UpdatedAt       time.Time `description:"Last update time"`
	DeletedAt       *time.Time
	ExtID           string `gorm:"not null;unique"`
	Email           string `gorm:"not null;unique"`
	Username        string `gorm:"not null;unique"`
	Password        string `gorm:"not null"`
	PasswordChanged time.Time
	Activated       bool `gorm:"not null; default:false"`
	Enabled         bool `gorm:"not null; default:false"`
	Locked          bool `gorm:"not null; default:false"`
	Admin           bool `gorm:"not null; default:false"`
	LoginRetries    uint `gorm:"not null; default:0"`
	LastLogin       time.Time

	ActionTokens []ActionToken
	FidoTokens   []FidoToken
	TotpTokens   []TotpToken
	BackupTokens []BackupToken
	AuditEvents  []AuditEvent

	OauthClients               []oauthstore.OauthClient
	OauthAccessTokenSessions   []oauthstore.OauthAccessToken
	OauthAuthorizeCodeSessions []oauthstore.OauthAuthorizeCode
	OauthRefreshTokenSessions  []oauthstore.OauthRefreshToken
}

User represents the user for this application

func (*User) ClearLoginRetries

func (u *User) ClearLoginRetries()

ClearLoginRetries clears a users login retry count

func (*User) GetCreatedAt

func (u *User) GetCreatedAt() time.Time

GetCreatedAt fetches a users account creation time

func (*User) GetEmail

func (u *User) GetEmail() string

GetEmail fetches a users Email

func (*User) GetExtID

func (u *User) GetExtID() string

GetExtID fetches a users ExtID

func (*User) GetIntID

func (u *User) GetIntID() uint

GetIntID fetches a users internal ID

func (*User) GetLastLogin

func (u *User) GetLastLogin() time.Time

GetLastLogin fetches a users LastLogin time

func (*User) GetLoginRetries

func (u *User) GetLoginRetries() uint

GetLoginRetries fetches a users login retry count

func (*User) GetPassword

func (u *User) GetPassword() string

GetPassword fetches a users Password

func (*User) GetPasswordChanged

func (u *User) GetPasswordChanged() time.Time

GetPasswordChanged fetches a users PasswordChanged time

func (*User) GetUsername

func (u *User) GetUsername() string

GetUsername fetches a users Username

func (*User) IsActivated

func (u *User) IsActivated() bool

IsActivated checks if a user is activated

func (*User) IsAdmin

func (u *User) IsAdmin() bool

IsAdmin checks if a user is an admin

func (*User) IsEnabled

func (u *User) IsEnabled() bool

IsEnabled checks if a user is enabled

func (*User) IsLocked

func (u *User) IsLocked() bool

IsLocked checkes if a user account is locked

func (*User) SecondFactors

func (u *User) SecondFactors() bool

SecondFactors Checks if a user has attached second factors

func (*User) SetActivated

func (u *User) SetActivated(activated bool)

SetActivated sets a users activated status

func (*User) SetAdmin

func (u *User) SetAdmin(admin bool)

SetAdmin sets a users admin status

func (*User) SetEnabled

func (u *User) SetEnabled(enabled bool)

SetEnabled sets a users enabled status

func (*User) SetLastLogin

func (u *User) SetLastLogin(t time.Time)

SetLastLogin sets a users LastLogin time

func (*User) SetLocked

func (u *User) SetLocked(locked bool)

SetLocked sets a users locked status

func (*User) SetLoginRetries

func (u *User) SetLoginRetries(retries uint)

SetLoginRetries sets a users login retry count

func (*User) SetPassword

func (u *User) SetPassword(pass string)

SetPassword sets a user password

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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