db

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

Types

type AppsManagementStore

type AppsManagementStore interface {
	// GetApp looks up a applications by the app ID.
	GetApp(appID string) (*app.Apps, error)
	GetMyApps(userID string) ([]byte, error)
	GetUserApps(userID string) ([]byte, error)
	RegisterApp(payload *app.AppPayload, userID string) (*app.RegApps, error)
	DeleteApp(appID string) error
	UpdateApp(payload *app.AppPayload, appID string) (*app.Apps, error)
	RegenerateSecret(appID string) ([]byte, error)
	FindApp(id, secret string) (*ClientApp, error)
}

AppsManagementStore defaines the interface for accessing the application data.

func NewAppsManagementStore

func NewAppsManagementStore(cfg *config.DBConfig) (store AppsManagementStore, cleanup func(), err error)

NewAppsManagementStore creates new AppsManagementStore implementation that supports multiple backend types.

type BackendAppsManagementStore

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

BackendAppsManagementStore holds a repository for a certain backend. Implements the AppsManagementStore interface.

func (*BackendAppsManagementStore) DeleteApp

func (c *BackendAppsManagementStore) DeleteApp(appID string) error

DeleteApp deletes an application by id

func (*BackendAppsManagementStore) FindApp

func (c *BackendAppsManagementStore) FindApp(ID, secret string) (*ClientApp, error)

FindApp tries to find an application (client) by its ID and secret. Returns nil if no such app is found.

func (*BackendAppsManagementStore) GetApp

func (c *BackendAppsManagementStore) GetApp(appID string) (*app.Apps, error)

GetApp retrieves an application by id

func (*BackendAppsManagementStore) GetMyApps

func (c *BackendAppsManagementStore) GetMyApps(userID string) ([]byte, error)

GetMyApps retrieves applications for current user

func (*BackendAppsManagementStore) GetUserApps

func (c *BackendAppsManagementStore) GetUserApps(userID string) ([]byte, error)

GetUserApps retrieves applications for a user

func (*BackendAppsManagementStore) RegenerateSecret

func (c *BackendAppsManagementStore) RegenerateSecret(appID string) ([]byte, error)

RegenerateSecret creates a new secret for an application by id

func (*BackendAppsManagementStore) RegisterApp

func (c *BackendAppsManagementStore) RegisterApp(payload *app.AppPayload, userID string) (*app.RegApps, error)

RegisterApp creates a new application for a user

func (*BackendAppsManagementStore) UpdateApp

func (c *BackendAppsManagementStore) UpdateApp(payload *app.AppPayload, appID string) (*app.Apps, error)

UpdateApp updates an application by id

type ClientApp

type ClientApp struct {
	ID           string `json:"id" bson:"_id"`
	Name         string `json:"name" bson:"name"`
	Description  string `json:"description,omitempty" bson:"description"`
	Domain       string `json:"domain,omitempty" bson:"domain"`
	Owner        string `json:"owner" bson:"owner"`
	RegisteredAt int64  `json:"registeredAt" bson:"registeredAt"`
	Secret       string `json:"secret" bson:"secret"`
}

ClientApp holds the data for a registered application (client).

type DB

type DB struct {
	sync.Mutex
	// contains filtered or unexported fields
}

DB emulates a database driver using in-memory data structures.

func New

func New() *DB

New initializes a new "DB" with dummy data.

func (*DB) DeleteApp

func (db *DB) DeleteApp(appID string) error

Mock DeleteApp method

func (*DB) FindApp

func (db *DB) FindApp(ID, secret string) (*ClientApp, error)

FindApp tries to find an app with the supplied app ID and secret.

func (*DB) GetApp

func (db *DB) GetApp(appID string) (*app.Apps, error)

Mock GetApp method

func (*DB) GetMyApps

func (db *DB) GetMyApps(userID string) ([]byte, error)

Mock GetUserApps method

func (*DB) GetUserApps

func (db *DB) GetUserApps(userID string) ([]byte, error)

Mock GetUserApps method

func (*DB) RegenerateSecret

func (db *DB) RegenerateSecret(appID string) ([]byte, error)

Mock RegenerateSecret method

func (*DB) RegisterApp

func (db *DB) RegisterApp(payload *app.AppPayload, userID string) (*app.RegApps, error)

Mock RegisterApp method

func (*DB) UpdateApp

func (db *DB) UpdateApp(payload *app.AppPayload, appID string) (*app.Apps, error)

Mock UpdateApp method

Jump to

Keyboard shortcuts

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