database

package
v0.0.0-...-fbe9a17 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = time.Second * 3

DefaultTimeout is the default length of time to wait for a database operation to complete.

Variables

View Source
var (
	ErrNotFound = errors.New("Key not found")
)

Common errors

Functions

func CreateAdminClient

func CreateAdminClient(ctx context.Context, db Database) (*model.ClientInfo, error)

CreateAdminClient creates an admin client in the database.

Types

type AuthorizationDB

type AuthorizationDB interface {
	CreateSession(ctx context.Context, request *model.AuthorizationRequest) error
	GetRequestInfo(ctx context.Context, requestID string) (*model.AuthorizationRequest, error)
	UpdateRequestInfo(ctx context.Context, requestInfo *model.AuthorizationRequest) error
	LookupSessionByCode(ctx context.Context, code string) (*model.AuthorizationRequest, error)
	RegisterToken(ctx context.Context, token *jwt.Token) error
	IsTokenSeen(ctx context.Context, token *jwt.Token) (bool, error)
	GetTokenByID(ctx context.Context, tokenID string) (string, error)
}

AuthorizationDB handles interactions with the authorization database, which may be the same as other databases or not.

type BadgerDB

type BadgerDB struct {
	DB          *badger.DB
	AdminClient *model.ClientInfo
	Path        string
	InMemory    bool
}

BadgerDB holds a connection to a Badger backend.

func NewBadgerDB

func NewBadgerDB(inMemory bool, opts *config.DatabaseConfig) (*BadgerDB, error)

NewBadgerDB creates a new database with a Badger backend. Pass `true` to create an in-memory database (useful in tests, for example).

func (*BadgerDB) Close

func (db *BadgerDB) Close() error

Close handles closing all connections to the database.

func (*BadgerDB) CreateSession

func (db *BadgerDB) CreateSession(ctx context.Context, request *model.AuthorizationRequest) error

CreateSession creates a session for the given client which includes the authorization code and code verifier information (PKCE), so that it can be verified later.

func (*BadgerDB) DeleteClient

func (db *BadgerDB) DeleteClient(ctx context.Context, clientID string) error

DeleteClient deletes the client from the database.

func (*BadgerDB) DeleteScope

func (db *BadgerDB) DeleteScope(ctx context.Context, scope string) error

DeleteScope removes a scope from the database.

func (*BadgerDB) DropAll

func (db *BadgerDB) DropAll(ctx context.Context) error

func (*BadgerDB) GetClient

func (db *BadgerDB) GetClient(ctx context.Context, clientID string) (client *model.ClientInfo, err error)

GetClient returns client information for the given client ID.

func (*BadgerDB) GetDefaultAdminClient

func (db *BadgerDB) GetDefaultAdminClient(ctx context.Context) (*model.ClientInfo, error)

GetDefaultAdminClient returns the default admin client for the database.

func (*BadgerDB) GetRequestInfo

func (db *BadgerDB) GetRequestInfo(ctx context.Context, requestID string) (*model.AuthorizationRequest, error)

GetRequestInfo returns the session info associated with this ID.

func (*BadgerDB) GetScope

func (db *BadgerDB) GetScope(ctx context.Context, scopeName string) (s *model.Scope, err error)

GetScope retrieves a scope by name.

func (*BadgerDB) GetTokenByID

func (db *BadgerDB) GetTokenByID(ctx context.Context, tokenID string) (token string, err error)

GetTokenByID looks up and returns the encoded token corresponding to the provided ID.

func (*BadgerDB) GetUserByID

func (db *BadgerDB) GetUserByID(ctx context.Context, id string) (*model.User, error)

GetUserByID retrieves user's info based off an ID.

func (*BadgerDB) GetUserByUsername

func (db *BadgerDB) GetUserByUsername(ctx context.Context, username, clientID string) (user *model.User, err error)

GetUserByUsername retrieves user's info based off a username.

func (*BadgerDB) IsTokenSeen

func (db *BadgerDB) IsTokenSeen(ctx context.Context, token *jwt.Token) (seen bool, err error)

IsTokenSeen returns an error if the token has been seen before. If not, it first records the token information so that subsequent calls return true.

func (*BadgerDB) ListClients

func (db *BadgerDB) ListClients(ctx context.Context, opts ...model.ClientOption) ([]*model.ClientInfo, error)

ListClients lists all clients in the database.

func (*BadgerDB) ListClientsByPredicate

func (db *BadgerDB) ListClientsByPredicate(ctx context.Context, predicate func(*model.ClientInfo) bool) ([]*model.ClientInfo, error)

ListClientsByPredicate lists all clients in the database based off a predicate.

func (*BadgerDB) ListScopes

func (db *BadgerDB) ListScopes(ctx context.Context) ([]*model.Scope, error)

ListScopes returns all scopes in the database.

func (*BadgerDB) LookupSessionByCode

func (db *BadgerDB) LookupSessionByCode(ctx context.Context, code string) (request *model.AuthorizationRequest, err error)

LookupSessionByCode retrieves a request session's data based off the authorization code.

func (*BadgerDB) RegisterClient

func (db *BadgerDB) RegisterClient(ctx context.Context, clientInfo *model.ClientInfo, opt model.ClientOption) (*model.ClientInfo, error)

RegisterClient registers the client with the provided information.

func (*BadgerDB) RegisterScope

func (db *BadgerDB) RegisterScope(ctx context.Context, scope string) (*model.Scope, error)

RegisterScope adds a new scope to the database.

func (*BadgerDB) RegisterToken

func (db *BadgerDB) RegisterToken(ctx context.Context, token *jwt.Token) error

RegisterToken saves the given tokens to the database for later reference.

func (*BadgerDB) RegisterUser

func (db *BadgerDB) RegisterUser(ctx context.Context, user *model.User) error

RegisterUser registers a new user in the authentication database.

func (*BadgerDB) UpdateClient

func (db *BadgerDB) UpdateClient(ctx context.Context, clientUpdate model.ClientInfoUpdate) (*model.ClientInfo, error)

UpdateClient updates the client with the provided information.

func (*BadgerDB) UpdateRequestInfo

func (db *BadgerDB) UpdateRequestInfo(ctx context.Context, requestInfo *model.AuthorizationRequest) error

UpdateRequestInfo updates the information pertinent to this request.

func (*BadgerDB) VerifyUsernameAndPassword

func (db *BadgerDB) VerifyUsernameAndPassword(ctx context.Context, username, clientID, password string) (*model.User, error)

VerifyUsernameAndPassword returns an error if the username and password combo do not match what's in the DB.

type ClientDB

type ClientDB interface {
	ListClients(ctx context.Context, opt ...model.ClientOption) ([]*model.ClientInfo, error)
	GetClient(ctx context.Context, clientID string) (*model.ClientInfo, error)
	UpdateClient(ctx context.Context, client model.ClientInfoUpdate) (*model.ClientInfo, error)
	RegisterClient(ctx context.Context, clientInfo *model.ClientInfo, opt model.ClientOption) (*model.ClientInfo, error)
	DeleteClient(ctx context.Context, clientID string) error
}

ClientDB handles interactions with the client database.

type Database

type Database interface {
	ClientDB
	AuthorizationDB
	UserDB
	DiscoveryDB
	ScopeDB
	GetDefaultAdminClient(ctx context.Context) (*model.ClientInfo, error)
	Close() error
	DropAll(ctx context.Context) error
}

Database handles all interactions with the data backend.

type DgraphDatabase

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

DgraphDatabase holds connection to a Dgraph DB instance.

func NewDgraphDatabase

func NewDgraphDatabase(ctx context.Context, opts *config.DatabaseConfig) (*DgraphDatabase, error)

NewDgraphDatabase creates a new Dgraph database connection uses settings from the loaded configuration.

func (*DgraphDatabase) Close

func (db *DgraphDatabase) Close() error

Close handles closing all connections to the database.

func (*DgraphDatabase) CreateSession

func (db *DgraphDatabase) CreateSession(ctx context.Context, request *model.AuthorizationRequest) error

CreateSession creates a session for the given client which includes the authorization code and code verifier information (PKCE), so that it can be verified later.

func (*DgraphDatabase) DeleteClient

func (db *DgraphDatabase) DeleteClient(ctx context.Context, clientID string) error

DeleteClient deletes the client from the database.

func (*DgraphDatabase) DeleteScope

func (db *DgraphDatabase) DeleteScope(ctx context.Context, scope string) error

DeleteScope removes a scope from the database.

func (*DgraphDatabase) DropAll

func (db *DgraphDatabase) DropAll(ctx context.Context) error

clear drops all data from the database.

func (*DgraphDatabase) GetClient

func (db *DgraphDatabase) GetClient(ctx context.Context, clientID string) (*model.ClientInfo, error)

GetClient returns client information for the given client ID.

func (*DgraphDatabase) GetDefaultAdminClient

func (db *DgraphDatabase) GetDefaultAdminClient(ctx context.Context) (*model.ClientInfo, error)

GetDefaultAdminClient returns the current admin client. It does not create one if it does not exist already.

func (*DgraphDatabase) GetRequestInfo

func (db *DgraphDatabase) GetRequestInfo(ctx context.Context, requestID string) (*model.AuthorizationRequest, error)

GetRequestInfo returns the session info associated with this ID.

func (*DgraphDatabase) GetScope

func (db *DgraphDatabase) GetScope(ctx context.Context, scopeName string) (*model.Scope, error)

GetScope retrieves a scope by name.

func (*DgraphDatabase) GetTokenByID

func (db *DgraphDatabase) GetTokenByID(ctx context.Context, tokenID string) (string, error)

GetTokenByID looks up and returns the encoded token corresponding to the provided ID.

func (*DgraphDatabase) GetUserByID

func (db *DgraphDatabase) GetUserByID(ctx context.Context, id string) (*model.User, error)

GetUserByID retrieves user's info based off a user's ID.

func (*DgraphDatabase) GetUserByUsername

func (db *DgraphDatabase) GetUserByUsername(ctx context.Context, username, clientID string) (*model.User, error)

GetUserByUsername retrieves user's info based off a username.

func (*DgraphDatabase) IsTokenSeen

func (db *DgraphDatabase) IsTokenSeen(ctx context.Context, token *jwt.Token) (bool, error)

IsTokenSeen returns an error if the token has been seen before. If not, it first records the token information so that subsequent calls return true.

func (*DgraphDatabase) ListClients

func (db *DgraphDatabase) ListClients(ctx context.Context, opt ...model.ClientOption) ([]*model.ClientInfo, error)

ListClients lists all clients in the database.

func (*DgraphDatabase) ListScopes

func (db *DgraphDatabase) ListScopes(ctx context.Context) ([]*model.Scope, error)

ListScopes returns all scopes in the database.

func (*DgraphDatabase) LookupSessionByCode

func (db *DgraphDatabase) LookupSessionByCode(ctx context.Context, code string) (*model.AuthorizationRequest, error)

LookupSessionByCode retrieves a request session's data based off the authorization code.

func (*DgraphDatabase) RegisterClient

func (db *DgraphDatabase) RegisterClient(ctx context.Context, clientInfo *model.ClientInfo, opt model.ClientOption) (*model.ClientInfo, error)

RegisterClient registers the client with the provided information.

func (*DgraphDatabase) RegisterScope

func (db *DgraphDatabase) RegisterScope(ctx context.Context, scopeName string) (*model.Scope, error)

RegisterScope adds a new scope to the database.

func (*DgraphDatabase) RegisterToken

func (db *DgraphDatabase) RegisterToken(ctx context.Context, token *jwt.Token) error

RegisterToken saves the given tokens to the database for later reference.

func (*DgraphDatabase) RegisterUser

func (db *DgraphDatabase) RegisterUser(ctx context.Context, user *model.User) error

RegisterUser registers a new user in the authentication database.

func (*DgraphDatabase) Seed

func (db *DgraphDatabase) Seed(ctx context.Context) (*model.ClientInfo, error)

Seed initializes the database schema and creates all defaults.

func (*DgraphDatabase) UpdateClient

func (db *DgraphDatabase) UpdateClient(ctx context.Context, clientUpdate model.ClientInfoUpdate) (*model.ClientInfo, error)

UpdateClient updates the client with the provided information.

func (*DgraphDatabase) UpdateRequestInfo

func (db *DgraphDatabase) UpdateRequestInfo(ctx context.Context, requestInfo *model.AuthorizationRequest) error

UpdateRequestInfo updates the information pertinent to this request.

func (*DgraphDatabase) VerifyUsernameAndPassword

func (db *DgraphDatabase) VerifyUsernameAndPassword(ctx context.Context, username, clientID, password string) (*model.User, error)

VerifyUsernameAndPassword returns an error if the username and password combo do not match what's in the DB.

type DgraphOptions

type DgraphOptions struct {
	GraphQLEndpoint string
	GrpcEndpoint    string
	APIKey          string
	Username        string
	Password        string
	SeedDB          bool
	DropAll         bool // Whether to drop all data
}

DgraphOptions holds configuration options for the Dgraph database.

type DiscoveryDB

type DiscoveryDB interface{}

DiscoveryDB handles interactions with the discovery database, which contains metadata about this program. It should be the same as AuthorizationDB.

type ScopeDB

type ScopeDB interface {
	ListScopes(ctx context.Context) ([]*model.Scope, error)
	GetScope(ctx context.Context, scope string) (*model.Scope, error)
	RegisterScope(ctx context.Context, scope string) (*model.Scope, error)
	DeleteScope(ctx context.Context, scope string) error
}

ScopeDB handles interactions with the scope database.

type UserDB

type UserDB interface {
	RegisterUser(ctx context.Context, user *model.User) error
	GetUserByID(ctx context.Context, id string) (*model.User, error)
	GetUserByUsername(ctx context.Context, username, clientID string) (*model.User, error)
	VerifyUsernameAndPassword(ctx context.Context, username, clientID, password string) (*model.User, error)
}

UserDB handles interactions with the authentication databse, which may or may not be the same as other databases.

Jump to

Keyboard shortcuts

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