models

package
v0.0.0-...-9de2c1c Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package models is a generated GoMock package.

Package models is a generated GoMock package.

Package models is a generated GoMock package.

Package models is a generated GoMock package.

Package models is a generated GoMock package.

Package models is a generated GoMock package.

Package models is a generated GoMock package.

Index

Constants

View Source
const (
	Before Direction = -1
	After  Direction = 1

	Beginning snowflake.ID = 0
	End       snowflake.ID = math.MaxInt64
)
View Source
const (
	ObjectEntity = "object" // Default Kind of an Entity.
)

Variables

View Source
var ErrNoTTL = errors.New("a TTL is required, but not given")

Functions

func IsNotFound

func IsNotFound(err error) bool

func WithStores

func WithStores(ctx context.Context, stores Stores) context.Context

WithStores associates a Stores object with a context.

Types

type AccessToken

type AccessToken struct {
	Token    string `json:"token"`
	ClientID string `json:"client_id"`
	Scope    string `json:"scope"`
	AuthorizationUserData
}

AccessToken stores an active access token in Redis. See also: RefreshToken.

type AccessTokenStore

type AccessTokenStore interface {
	Set(token *AccessToken, ttl time.Duration) error
	Get(token string) (*AccessToken, error)
	Delete(token string) error
}

func NewAccessTokenStore

func NewAccessTokenStore(keyspace string, r *redis.Client) AccessTokenStore

type Authorization

type Authorization struct {
	Code        string `json:"code"`
	ClientID    string `json:"client_id"`
	Scope       string `json:"scope"`
	RedirectURI string `json:"redirect_uri"`
	State       string `json:"state"`
	AuthorizationUserData
}

Authorization stores server-side state for an authorization. It's stored temporarily, before being traded for an AccessToken and a RefreshToken and subsequently deleted.

type AuthorizationStore

type AuthorizationStore interface {
	Set(auth *Authorization, ttl time.Duration) error
	Get(code string) (*Authorization, error)
	Delete(code string) error
}

AuthorizationStore stores Authorizations (in Redis).

func NewAuthorizationStore

func NewAuthorizationStore(keyspace string, r *redis.Client) AuthorizationStore

type AuthorizationUserData

type AuthorizationUserData struct {
	UserID snowflake.ID `json:"user_id"`
}

type Client

type Client struct {
	ID          snowflake.ID `json:"id"`
	RedirectURI string       `json:"redirect_uri"`
	Secret      string       `json:"-"`
	ClientUserData
}

Client is an OAuth2 client application. Implements the osin.Client interface for the oauth package.

func NewClient

func NewClient(ud ClientUserData, redirectURI string) (*Client, error)

func (Client) GetId

func (c Client) GetId() string

func (Client) GetRedirectUri

func (c Client) GetRedirectUri() string

func (Client) GetSecret

func (c Client) GetSecret() string

func (Client) GetUserData

func (c Client) GetUserData() interface{}

type ClientStore

type ClientStore interface {
	// Create creates a new client.
	Create(cl *Client) error

	// Get returns a client by ID, or an error if it doesn't exist.
	Get(id snowflake.ID) (*Client, error)
}

ClientStore abstracts data access to Clients.

func NewClientStore

func NewClientStore(db *gorm.DB) ClientStore

NewClientStore returns a ClientStore that accesses the given DB.

type ClientUserData

type ClientUserData struct {
	Name        string        `json:"name"`
	Description string        `json:"description"`
	OwnerID     *snowflake.ID `json:"owner_id"`
}

ClientUserData contains additional fields for a client to be included as UserData.

type Direction

type Direction int

type Entity

type Entity struct {
	// Snowflake ID, separate from the public one, used for foreign key consistency.
	ID snowflake.ID `json:"_id"`

	// Raw JSON data. You probably want to use Obj instead.
	Data JSONB `json:"_data"`

	// "Kind" of an entity, normally ObjectEntity.
	// Kinds determine what special server side behavior applies.
	Kind EntityKind `json:"_kind"`

	// Concrete Object representation of this Entity.
	// Modifications to this Object will be written back (and synched to Data) by EntityStore.Save().
	Obj *ld.Object `json:"_obj" gorm:"-"`
}

An Entity represents a raw, database-form Entity. This is a lower-level API and you probably actually want the higher-level entities package.

func NewEntity

func NewEntity(kind EntityKind, data []byte) (*Entity, error)

func NewEntityFrom

func NewEntityFrom(kind EntityKind, e ld.Entity) *Entity

func (*Entity) SyncDataToObject

func (e *Entity) SyncDataToObject() error

Overwrites Object with Data. Called automatically by EntityStore.Get*() and NewEntity().

func (*Entity) SyncObjectToData

func (e *Entity) SyncObjectToData() error

Overwrites Data with Object. Called automatically by EntityStore.Save().

type EntityKind

type EntityKind string

Kind of an Entity.

type EntityStore

type EntityStore interface {
	// GetBySnowflake returns an Entity by its snowflake, eg. "353894652568535040".
	GetBySnowflake(id snowflake.ID) (*Entity, error)

	// GetByID returns an Entity by its ID, eg. "https://example.com/@johnsmith.
	GetByID(id string) (*Entity, error)

	// Save stores an Entity using an upsert. Updates Data if the object has been modified.
	Save(e *Entity) error
}

EntityStore stores Entities in their raw database form.

func NewEntityStore

func NewEntityStore(db *gorm.DB) EntityStore

type JSONB

type JSONB []byte

JSONB type based on the jinzhu/gorm one, which serialises JSON *as strings*, mostly to produce more useful logging than the nonsense byte arrays produce.

func (JSONB) MarshalJSON

func (j JSONB) MarshalJSON() ([]byte, error)

func (*JSONB) Scan

func (j *JSONB) Scan(v interface{}) error

func (JSONB) String

func (j JSONB) String() string

func (*JSONB) UnmarshalJSON

func (j *JSONB) UnmarshalJSON(data []byte) error

func (JSONB) Value

func (j JSONB) Value() (driver.Value, error)

type MockAccessTokenStore

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

MockAccessTokenStore is a mock of AccessTokenStore interface

func NewMockAccessTokenStore

func NewMockAccessTokenStore(ctrl *gomock.Controller) *MockAccessTokenStore

NewMockAccessTokenStore creates a new mock instance

func (*MockAccessTokenStore) Delete

func (m *MockAccessTokenStore) Delete(token string) error

Delete mocks base method

func (*MockAccessTokenStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockAccessTokenStore) Get

func (m *MockAccessTokenStore) Get(token string) (*AccessToken, error)

Get mocks base method

func (*MockAccessTokenStore) Set

func (m *MockAccessTokenStore) Set(token *AccessToken, ttl time.Duration) error

Set mocks base method

type MockAccessTokenStoreMockRecorder

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

MockAccessTokenStoreMockRecorder is the mock recorder for MockAccessTokenStore

func (*MockAccessTokenStoreMockRecorder) Delete

func (mr *MockAccessTokenStoreMockRecorder) Delete(token interface{}) *gomock.Call

Delete indicates an expected call of Delete

func (*MockAccessTokenStoreMockRecorder) Get

func (mr *MockAccessTokenStoreMockRecorder) Get(token interface{}) *gomock.Call

Get indicates an expected call of Get

func (*MockAccessTokenStoreMockRecorder) Set

func (mr *MockAccessTokenStoreMockRecorder) Set(token, ttl interface{}) *gomock.Call

Set indicates an expected call of Set

type MockAuthorizationStore

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

MockAuthorizationStore is a mock of AuthorizationStore interface

func NewMockAuthorizationStore

func NewMockAuthorizationStore(ctrl *gomock.Controller) *MockAuthorizationStore

NewMockAuthorizationStore creates a new mock instance

func (*MockAuthorizationStore) Delete

func (m *MockAuthorizationStore) Delete(code string) error

Delete mocks base method

func (*MockAuthorizationStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockAuthorizationStore) Get

Get mocks base method

func (*MockAuthorizationStore) Set

Set mocks base method

type MockAuthorizationStoreMockRecorder

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

MockAuthorizationStoreMockRecorder is the mock recorder for MockAuthorizationStore

func (*MockAuthorizationStoreMockRecorder) Delete

func (mr *MockAuthorizationStoreMockRecorder) Delete(code interface{}) *gomock.Call

Delete indicates an expected call of Delete

func (*MockAuthorizationStoreMockRecorder) Get

func (mr *MockAuthorizationStoreMockRecorder) Get(code interface{}) *gomock.Call

Get indicates an expected call of Get

func (*MockAuthorizationStoreMockRecorder) Set

func (mr *MockAuthorizationStoreMockRecorder) Set(auth, ttl interface{}) *gomock.Call

Set indicates an expected call of Set

type MockClientStore

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

MockClientStore is a mock of ClientStore interface

func NewMockClientStore

func NewMockClientStore(ctrl *gomock.Controller) *MockClientStore

NewMockClientStore creates a new mock instance

func (*MockClientStore) Create

func (m *MockClientStore) Create(cl *Client) error

Create mocks base method

func (*MockClientStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockClientStore) Get

func (m *MockClientStore) Get(id snowflake.ID) (*Client, error)

Get mocks base method

type MockClientStoreMockRecorder

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

MockClientStoreMockRecorder is the mock recorder for MockClientStore

func (*MockClientStoreMockRecorder) Create

func (mr *MockClientStoreMockRecorder) Create(cl interface{}) *gomock.Call

Create indicates an expected call of Create

func (*MockClientStoreMockRecorder) Get

func (mr *MockClientStoreMockRecorder) Get(id interface{}) *gomock.Call

Get indicates an expected call of Get

type MockEntityStore

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

MockEntityStore is a mock of EntityStore interface

func NewMockEntityStore

func NewMockEntityStore(ctrl *gomock.Controller) *MockEntityStore

NewMockEntityStore creates a new mock instance

func (*MockEntityStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockEntityStore) GetByID

func (m *MockEntityStore) GetByID(id string) (*Entity, error)

GetByID mocks base method

func (*MockEntityStore) GetBySnowflake

func (m *MockEntityStore) GetBySnowflake(id snowflake.ID) (*Entity, error)

GetBySnowflake mocks base method

func (*MockEntityStore) Save

func (m *MockEntityStore) Save(e *Entity) error

Save mocks base method

type MockEntityStoreMockRecorder

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

MockEntityStoreMockRecorder is the mock recorder for MockEntityStore

func (*MockEntityStoreMockRecorder) GetByID

func (mr *MockEntityStoreMockRecorder) GetByID(id interface{}) *gomock.Call

GetByID indicates an expected call of GetByID

func (*MockEntityStoreMockRecorder) GetBySnowflake

func (mr *MockEntityStoreMockRecorder) GetBySnowflake(id interface{}) *gomock.Call

GetBySnowflake indicates an expected call of GetBySnowflake

func (*MockEntityStoreMockRecorder) Save

func (mr *MockEntityStoreMockRecorder) Save(e interface{}) *gomock.Call

Save indicates an expected call of Save

type MockRefreshTokenStore

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

MockRefreshTokenStore is a mock of RefreshTokenStore interface

func NewMockRefreshTokenStore

func NewMockRefreshTokenStore(ctrl *gomock.Controller) *MockRefreshTokenStore

NewMockRefreshTokenStore creates a new mock instance

func (*MockRefreshTokenStore) Delete

func (m *MockRefreshTokenStore) Delete(token string) error

Delete mocks base method

func (*MockRefreshTokenStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockRefreshTokenStore) Get

func (m *MockRefreshTokenStore) Get(token string) (*RefreshToken, error)

Get mocks base method

func (*MockRefreshTokenStore) Set

func (m *MockRefreshTokenStore) Set(token *RefreshToken) error

Set mocks base method

type MockRefreshTokenStoreMockRecorder

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

MockRefreshTokenStoreMockRecorder is the mock recorder for MockRefreshTokenStore

func (*MockRefreshTokenStoreMockRecorder) Delete

func (mr *MockRefreshTokenStoreMockRecorder) Delete(token interface{}) *gomock.Call

Delete indicates an expected call of Delete

func (*MockRefreshTokenStoreMockRecorder) Get

func (mr *MockRefreshTokenStoreMockRecorder) Get(token interface{}) *gomock.Call

Get indicates an expected call of Get

func (*MockRefreshTokenStoreMockRecorder) Set

func (mr *MockRefreshTokenStoreMockRecorder) Set(token interface{}) *gomock.Call

Set indicates an expected call of Set

type MockStores

type MockStores struct {
	EntityStore        *MockEntityStore
	UserStore          *MockUserStore
	ClientStore        *MockClientStore
	AuthorizationStore *MockAuthorizationStore
	AccessTokenStore   *MockAccessTokenStore
	RefreshTokenStore  *MockRefreshTokenStore
	StreamItemStore    *MockStreamItemStore
	// contains filtered or unexported fields
}

Unlike the other stores, we're not autogenerating the mock for Stores, because it's more useful to have a Store that creates Mock<*>Store instances that we can run tests on than to have to go mockStore.EXPECT().Clients().Returns(myExistingMockClientStore) etc. before every real EXPECT(). That would also break in obnoxious ways if tested functions change the way they reuse stores, which should not be part of the API contract in the slightest.

func NewMockStores

func NewMockStores(ctrl *gomock.Controller) *MockStores

func (*MockStores) AccessTokens

func (s *MockStores) AccessTokens() AccessTokenStore

func (*MockStores) Authorizations

func (s *MockStores) Authorizations() AuthorizationStore

func (*MockStores) Clients

func (s *MockStores) Clients() ClientStore

func (*MockStores) Entities

func (s *MockStores) Entities() EntityStore

func (*MockStores) RefreshTokens

func (s *MockStores) RefreshTokens() RefreshTokenStore

func (*MockStores) StreamItems

func (s *MockStores) StreamItems() StreamItemStore

func (*MockStores) Users

func (s *MockStores) Users() UserStore

type MockStreamItemStore

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

MockStreamItemStore is a mock of StreamItemStore interface

func NewMockStreamItemStore

func NewMockStreamItemStore(ctrl *gomock.Controller) *MockStreamItemStore

NewMockStreamItemStore creates a new mock instance

func (*MockStreamItemStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockStreamItemStore) GetItem

func (m *MockStreamItemStore) GetItem(itemID snowflake.ID) (*StreamItem, error)

GetItem mocks base method

func (*MockStreamItemStore) GetItemByEntityID

func (m *MockStreamItemStore) GetItemByEntityID(streamID, entityID snowflake.ID) (*StreamItem, error)

GetItemByEntityID mocks base method

func (*MockStreamItemStore) GetItems

func (m *MockStreamItemStore) GetItems(streamID, startID snowflake.ID, direction Direction, count uint) ([]StreamItem, error)

GetItems mocks base method

func (*MockStreamItemStore) TryInsertItem

func (m *MockStreamItemStore) TryInsertItem(stream, entityId snowflake.ID) (*StreamItem, bool, error)

TryInsertItem mocks base method

type MockStreamItemStoreMockRecorder

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

MockStreamItemStoreMockRecorder is the mock recorder for MockStreamItemStore

func (*MockStreamItemStoreMockRecorder) GetItem

func (mr *MockStreamItemStoreMockRecorder) GetItem(itemID interface{}) *gomock.Call

GetItem indicates an expected call of GetItem

func (*MockStreamItemStoreMockRecorder) GetItemByEntityID

func (mr *MockStreamItemStoreMockRecorder) GetItemByEntityID(streamID, entityID interface{}) *gomock.Call

GetItemByEntityID indicates an expected call of GetItemByEntityID

func (*MockStreamItemStoreMockRecorder) GetItems

func (mr *MockStreamItemStoreMockRecorder) GetItems(streamID, startID, direction, count interface{}) *gomock.Call

GetItems indicates an expected call of GetItems

func (*MockStreamItemStoreMockRecorder) TryInsertItem

func (mr *MockStreamItemStoreMockRecorder) TryInsertItem(stream, entityId interface{}) *gomock.Call

TryInsertItem indicates an expected call of TryInsertItem

type MockUserStore

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

MockUserStore is a mock of UserStore interface

func NewMockUserStore

func NewMockUserStore(ctrl *gomock.Controller) *MockUserStore

NewMockUserStore creates a new mock instance

func (*MockUserStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockUserStore) GetByEmail

func (m *MockUserStore) GetByEmail(email string) (*User, error)

GetByEmail mocks base method

func (*MockUserStore) GetByEntityID

func (m *MockUserStore) GetByEntityID(id snowflake.ID) (*User, error)

GetByEntityID mocks base method

func (*MockUserStore) GetBySnowflake

func (m *MockUserStore) GetBySnowflake(id snowflake.ID) (*User, error)

GetBySnowflake mocks base method

func (*MockUserStore) Save

func (m *MockUserStore) Save(u *User) error

Save mocks base method

type MockUserStoreMockRecorder

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

MockUserStoreMockRecorder is the mock recorder for MockUserStore

func (*MockUserStoreMockRecorder) GetByEmail

func (mr *MockUserStoreMockRecorder) GetByEmail(email interface{}) *gomock.Call

GetByEmail indicates an expected call of GetByEmail

func (*MockUserStoreMockRecorder) GetByEntityID

func (mr *MockUserStoreMockRecorder) GetByEntityID(id interface{}) *gomock.Call

GetByEntityID indicates an expected call of GetByEntityID

func (*MockUserStoreMockRecorder) GetBySnowflake

func (mr *MockUserStoreMockRecorder) GetBySnowflake(id interface{}) *gomock.Call

GetBySnowflake indicates an expected call of GetBySnowflake

func (*MockUserStoreMockRecorder) Save

func (mr *MockUserStoreMockRecorder) Save(u interface{}) *gomock.Call

Save indicates an expected call of Save

type NotFoundError

type NotFoundError string

func (NotFoundError) Error

func (err NotFoundError) Error() string

type RefreshToken

type RefreshToken struct {
	Token    string `json:"token"`
	ClientID string `json:"client_id"`
	Scope    string `json:"scope"`
	AuthorizationUserData
}

RefreshToken stores a persistent refresh token in Redis. See also: AccessToken.

type RefreshTokenStore

type RefreshTokenStore interface {
	Set(token *RefreshToken) error
	Get(token string) (*RefreshToken, error)
	Delete(token string) error
}

func NewRefreshTokenStore

func NewRefreshTokenStore(keyspace string, r *redis.Client) RefreshTokenStore

type Stores

type Stores interface {
	Entities() EntityStore
	Users() UserStore
	Clients() ClientStore
	Authorizations() AuthorizationStore
	AccessTokens() AccessTokenStore
	RefreshTokens() RefreshTokenStore
	StreamItems() StreamItemStore
}

Stores is an interface that returns other Stores. There are too many of them at this point to keep them all around individually. I wasn't allowed to name this the StoreStore :(

func GetStores

func GetStores(ctx context.Context) Stores

GetStores returns the Stores object associated with the context.

func NewStores

func NewStores(db *gorm.DB, r *redis.Client, keyspace string) Stores

type StreamItem

type StreamItem struct {
	ItemID   snowflake.ID `json:"item_id"`
	StreamID snowflake.ID `json:"stream_id"`
	EntityID snowflake.ID `json:"entity_id"`
}

StreamItem represents a single item in a string

type StreamItemStore

type StreamItemStore interface {
	// GetItems returns count items from the specified stream, starting
	// after/before the specified item, in the specified direction. Pass "Beginning"/"End" to
	// start at the beginning or end of the stream
	GetItems(streamID snowflake.ID, startID snowflake.ID, direction Direction, count uint) ([]StreamItem, error)

	// GetItem returns a specific stream item
	GetItem(itemID snowflake.ID) (*StreamItem, error)

	// GetItemByEntityId returns a specific stream item by stream and entry ID
	GetItemByEntityID(streamID snowflake.ID, entityID snowflake.ID) (*StreamItem, error)

	// TryInsertItem attempts to insert the specified entity ID into the stream.
	// Returns:
	//   * If the entry was inserted
	//   * The stream item (regardless)
	TryInsertItem(stream snowflake.ID, entityId snowflake.ID) (*StreamItem, bool, error)
}

func NewStreamItemStore

func NewStreamItemStore(db *gorm.DB) StreamItemStore

type User

type User struct {
	ID           snowflake.ID `json:"id"`
	EntityID     snowflake.ID `json:"entity_id"`
	Email        string       `json:"email"`
	PasswordHash string       `json:"-"`
}

A User stores authentication data for a local user. This is separate from profile information, which is stored as an Entity. This should never be sent to clients, and only used internally. To get the public ID, etc., please look up the related Entity.

func NewUser

func NewUser(profileID snowflake.ID, email, password string) (*User, error)

func (*User) CheckPassword

func (u *User) CheckPassword(password string) (bool, error)

CheckPassword compares the given password to the stored hash. Returns whether the comparison succeeded, and any errors produced. Please note that if an error is produced here, you should NOT RELAY IT VERBATIM TO THE USER; log it, check the bool and return a generic "unauthorized" response if it's false.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword updates the user's PasswordHash by bcrypt'ing the password.

type UserStore

type UserStore interface {
	GetBySnowflake(id snowflake.ID) (*User, error)
	GetByEntityID(id snowflake.ID) (*User, error)
	GetByEmail(email string) (*User, error)
	Save(u *User) error
}

func NewUserStore

func NewUserStore(db *gorm.DB) UserStore

Jump to

Keyboard shortcuts

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