models

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValidateClientValid              = 0x0
	ValidateClientNilUID             = 0x1
	ValidateClientEmptyName          = 0x2
	ValidateClientNameTooLong        = 0x4
	ValidateClientEmptyRedirectUrl   = 0x8
	ValidateClientRedirectUrlTooLong = 0x10
	ValidateClientInvalidRedirectUrl = 0x20
	ValidateClientInvalidTokenType   = 0x40
	ValidateClientEmptyKeyUri        = 0x80
	ValidateClientKeyUriTooLong      = 0x100
)
View Source
const (
	ClientTokenTypeDefault  = iota
	ClientTokenTypeFirebase = iota
)
View Source
const (
	ValidateMigrationValid            = 0x0
	ValidateMigrationInvalidTimestamp = 0x1
)
View Source
const (
	ValidateSessionValid    = 0x0
	ValidateSessionNilToken = 0x1
)
View Source
const (
	ValidateUserValid           = 0x0
	ValidateUserEmptyUsername   = 0x1
	ValidateUserUsernameTooLong = 0x2
	ValidateUserInvalidRank     = 0x8
)
View Source
const (
	ValidateUserRoleValid       = 0x0
	ValidateUserRoleEmptyRole   = 0x1
	ValidateUserRoleRoleTooLong = 0x2
)
View Source
const ClientKeyUriMaxLength = 100

ClientKeyUriMaxLength is the max length a client's key uri can be.

View Source
const ClientNameMaxLength = 30

ClientNameMaxLength is the max length a client's name can be.

View Source
const ClientRedirectUrlMaxLength = 100

ClientRedirectUrlMaxLength is the max length a client's redirect url can be.

View Source
const UserRoleRoleMaxLength = 15

UserRoleRoleMaxLength is the max length a user's username can be.

View Source
const UserUsernameMaxLength = 30

UserUsernameMaxLength is the max length a user's username can be.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	UID         uuid.UUID `firestore:"uid"`
	Name        string    `firestore:"name"`
	RedirectUrl string    `firestore:"redirect_url"`
	TokenType   int       `firestore:"token_type"`
	KeyUri      string    `firestore:"key_uri"`
}

Client represents the client model.

func CreateClient

func CreateClient(uid uuid.UUID, name string, redirectUrl string, tokenType int, keyUri string) *Client

CreateClient creates a new client model with the provided fields.

func CreateNewClient

func CreateNewClient(name string, redirectUrl string, tokenType int, keyUri string) *Client

CreateNewClient generates a new uid then creates a new client model with the uid and provided fields.

func (*Client) Validate

func (c *Client) Validate() int

Validate validates the client model has valid fields. Returns an int indicating which fields are invalid.

type ClientCRUD

type ClientCRUD interface {
	// CreateClient creates a new client and returns any errors.
	CreateClient(client *Client) error

	// GetClients fetches all the clients.
	// Returns the clients and any errors.
	GetClients() ([]*Client, error)

	// GetClientByUID fetches the client associated with the uid.
	// If no clients are found, returns nil client. Also returns any errors.
	GetClientByUID(uid uuid.UUID) (*Client, error)

	// UpdateClient updates the client.
	// Returns result of whether the client was found, and any errors.
	UpdateClient(client *Client) (bool, error)

	// DeleteClient deletes the client the with the given uid.
	// Returns result of whether the client was found, and any errors.
	DeleteClient(uid uuid.UUID) (bool, error)
}

type Migration

type Migration struct {
	Timestamp string `firestore:"timestamp"`
}

Migration represents the migration model.

func CreateMigration

func CreateMigration(timestamp string) *Migration

CreateMigration creates a new migration model with the provided fields.

func (Migration) Validate

func (m Migration) Validate() int

Validate validates the migration is a valid migration model. Returns an int indicating which fields are invalid.

type MigrationCRUD

type MigrationCRUD interface {
	migrationrunner.MigrationCRUD

	// GetMigrationByTimestamp fetches the migration with the matching timestamp.
	// If no migrations are found, returns nil migration. Also returns any errors.
	GetMigrationByTimestamp(timestamp string) (*Migration, error)
}

type Session

type Session struct {
	Token    uuid.UUID `firestore:"token"`
	Username string    `firestore:"username"`
	Rank     int       `firestore:"rank"`
}

Session represents the session model.

func CreateNewSession

func CreateNewSession(username string, rank int) *Session

CreateNewSession generates a new token then creates a new session model with the token and provided field.

func CreateSession

func CreateSession(token uuid.UUID, username string, rank int) *Session

CreateSession creates a new session model with the provided field.

func (*Session) Validate

func (s *Session) Validate() int

Validate validates the access token model has valid fields. Returns an int indicating which fields are invalid.

type SessionCRUD

type SessionCRUD interface {
	// SaveSession saves the session and returns any errors.
	SaveSession(session *Session) error

	// GetSessionByToken fetches the session with the given token.
	// If no sessions are found, returns nil session.
	// Also returns any errors.
	GetSessionByToken(token uuid.UUID) (*Session, error)

	// DeleteSession deletes the session with the given token.
	// Returns result of whether the session was found, and any errors.
	DeleteSession(token uuid.UUID) (bool, error)

	// DeleteAllOtherUserSessions deletes all of the sessions for the given username.
	// Returns any errors.
	DeleteAllUserSessions(username string) error

	// DeleteAllOtherUserSessions deletes all of the sessions for the given username except the one with the given token.
	// Returns any errors.
	DeleteAllOtherUserSessions(username string, tokem uuid.UUID) error
}

type User

type User struct {
	Username     string `firestore:"username"`
	Rank         int    `firestore:"rank"`
	PasswordHash []byte `firestore:"password_hash"`
}

User represents the user model.

func CreateUser

func CreateUser(username string, rank int, passwordHash []byte) *User

CreateUser creates a new user model with the provided fields.

func (*User) Validate

func (u *User) Validate() int

Validate validates the user model has valid fields. Returns an int indicating which fields are invalid.

type UserCRUD

type UserCRUD interface {
	// CreateUser creates a new user and returns any errors.
	CreateUser(user *User) error

	// GetUsersWithLesserRank fetches all the users with a rank less than the provided one.
	// Returns the users and any errors.
	GetUsersWithLesserRank(rank int) ([]*User, error)

	// GetUserByUsername fetches the user with the matching username.
	// If no users are found, returns nil user. Also returns any errors.
	GetUserByUsername(username string) (*User, error)

	// UpdateUser updates the user.
	// Returns result of whether the user was found, and any errors.
	UpdateUser(user *User) (bool, error)

	// UpdateUserPassword updates the user's password.
	// Returns result of whether the user was found, and any errors.
	UpdateUserPassword(username string, hash []byte) (bool, error)

	// DeleteUser deletes the user with the given username.
	// Returns result of whether the user was found, and any errors.
	DeleteUser(username string) (bool, error)
}

type UserRole

type UserRole struct {
	ClientUID uuid.UUID `firestore:"client_uid"`
	Username  string    `firestore:"username"`
	Role      string    `firestore:"role"`
}

UserRole represents the user-role model.

func CreateUserRole

func CreateUserRole(clientUID uuid.UUID, username string, role string) *UserRole

CreateUserRole creates a new user-role model with the provided fields.

func (*UserRole) Validate

func (ur *UserRole) Validate() int

Validate validates the user-role model has valid fields. Returns an int indicating which fields are invalid.

type UserRoleCRUD

type UserRoleCRUD interface {
	// CreateUserRole creates the user-role. Returns any errors.
	CreateUserRole(role *UserRole) error

	// GetUserRolesWithLesserRankByClientUID fetches the user-roles for the provided client uid and with a rank less than the provided rank.
	// Returns the user-roles and returns any errors.
	GetUserRolesWithLesserRankByClientUID(uid uuid.UUID, rank int) ([]*UserRole, error)

	// GetUserRoleByClientUIDAndUsername fetches the user-role for the provided client uid and username.
	// Returns the user-role if it exists, nil if not. Also returns any errors.
	GetUserRoleByClientUIDAndUsername(clientUID uuid.UUID, username string) (*UserRole, error)

	// UpdateUserRole updates the user-role.
	// Returns result of whether the user-role was found and any errors.
	UpdateUserRole(role *UserRole) (bool, error)

	// DeleteUserRole deletes the user-role with the given client uid and username.
	// Returns result of whether the user-role was found, and any errors.
	DeleteUserRole(clientUID uuid.UUID, username string) (bool, error)
}

Jump to

Keyboard shortcuts

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