repository

package
v0.0.0-...-2d73068 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package repository provides the APIs for making 'token' related database interactions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExternalTokenFilterByIdentityID

func ExternalTokenFilterByIdentityID(identityID uuid.UUID) func(db *gorm.DB) *gorm.DB

ExternalTokenFilterByIdentityID is a gorm filter for a Belongs To relationship.

func ExternalTokenFilterByProviderID

func ExternalTokenFilterByProviderID(providerID uuid.UUID) func(db *gorm.DB) *gorm.DB

ExternalTokenFilterByProviderID is a gorm filter by 'external_provider_type'

func ExternalTokenWithIdentity

func ExternalTokenWithIdentity() func(db *gorm.DB) *gorm.DB

ExternalTokenWithIdentity is a gorm filter for preloading the identity relationship.

Types

type ExternalToken

type ExternalToken struct {
	gormsupport.LifecycleHardDelete
	ID         uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key"` // This is the ID PK field
	ProviderID uuid.UUID
	Token      string
	Scope      string
	Username   string
	IdentityID uuid.UUID `sql:"type:uuid"` // use NullUUID ?
	Identity   account.Identity
}

ExternalToken describes a single ExternalToken

func (ExternalToken) GetETagData

func (m ExternalToken) GetETagData() []interface{}

GetETagData returns the field values to use to generate the ETag

func (ExternalToken) GetLastModified

func (m ExternalToken) GetLastModified() time.Time

GetLastModified returns the last modification time

func (ExternalToken) TableName

func (m ExternalToken) TableName() string

TableName overrides the table name settings in Gorm to force a specific table name in the database.

type ExternalTokenRepository

type ExternalTokenRepository interface {
	repository.Exister
	Load(ctx context.Context, id uuid.UUID) (*ExternalToken, error)
	Create(ctx context.Context, ExternalToken *ExternalToken) error
	Save(ctx context.Context, ExternalToken *ExternalToken) error
	Delete(ctx context.Context, id uuid.UUID) error
	DeleteByIdentityID(ctx context.Context, identityID uuid.UUID) error
	LoadByProviderIDAndIdentityID(ctx context.Context, providerID uuid.UUID, identityID uuid.UUID) ([]ExternalToken, error)
	Query(funcs ...func(*gorm.DB) *gorm.DB) ([]ExternalToken, error)
}

ExternalTokenRepository represents the storage interface.

type GormExternalTokenRepository

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

GormExternalTokenRepository is the implementation of the storage interface for ExternalToken.

func NewExternalTokenRepository

func NewExternalTokenRepository(db *gorm.DB) *GormExternalTokenRepository

NewExternalTokenRepository creates a new storage type.

func (*GormExternalTokenRepository) CheckExists

func (m *GormExternalTokenRepository) CheckExists(ctx context.Context, id string) error

CheckExists returns nil if the given ID exists otherwise returns an error

func (*GormExternalTokenRepository) Create

Create creates a new record.

func (*GormExternalTokenRepository) Delete

Delete removes a single record. This is a hard delete!

func (*GormExternalTokenRepository) DeleteByIdentityID

func (m *GormExternalTokenRepository) DeleteByIdentityID(ctx context.Context, identityID uuid.UUID) error

DeleteByIdentityID removes all records associated with a given identity ID

func (*GormExternalTokenRepository) Load

Load returns a single ExternalToken as a Database Model This is more for use internally, and probably not what you want in your controllers

func (*GormExternalTokenRepository) LoadByProviderIDAndIdentityID

func (m *GormExternalTokenRepository) LoadByProviderIDAndIdentityID(ctx context.Context, providerID uuid.UUID, identityID uuid.UUID) ([]ExternalToken, error)

LoadByProviderIDAndIdentityID loads tokens by IdentityID and ProviderID

func (*GormExternalTokenRepository) Query

func (m *GormExternalTokenRepository) Query(funcs ...func(*gorm.DB) *gorm.DB) ([]ExternalToken, error)

Query expose an open ended Query model

func (*GormExternalTokenRepository) Save

Save modifies a single record.

func (*GormExternalTokenRepository) TableName

func (m *GormExternalTokenRepository) TableName() string

TableName overrides the table name settings in Gorm to force a specific table name in the database.

type GormTokenRepository

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

GormTokenRepository is the implementation of the storage interface for Token.

func (*GormTokenRepository) CheckExists

func (m *GormTokenRepository) CheckExists(ctx context.Context, id uuid.UUID) (bool, error)

CheckExists returns true if the given ID exists otherwise returns an error

func (*GormTokenRepository) CleanupExpiredTokens

func (m *GormTokenRepository) CleanupExpiredTokens(ctx context.Context, retentionHours int) error

func (*GormTokenRepository) Create

func (m *GormTokenRepository) Create(ctx context.Context, token *Token) error

Create creates a new record.

func (*GormTokenRepository) CreatePrivilege

func (m *GormTokenRepository) CreatePrivilege(ctx context.Context, privilege *TokenPrivilege) error

func (*GormTokenRepository) Delete

func (m *GormTokenRepository) Delete(ctx context.Context, id uuid.UUID) error

Delete removes a single record.

func (*GormTokenRepository) ListForIdentity

func (m *GormTokenRepository) ListForIdentity(ctx context.Context, identityID uuid.UUID) ([]Token, error)

func (*GormTokenRepository) ListPrivileges

func (m *GormTokenRepository) ListPrivileges(ctx context.Context, tokenID uuid.UUID) ([]permission.PrivilegeCache, error)

func (*GormTokenRepository) Load

func (m *GormTokenRepository) Load(ctx context.Context, id uuid.UUID) (*Token, error)

Load returns a single Token as a Database Model

func (*GormTokenRepository) Save

func (m *GormTokenRepository) Save(ctx context.Context, token *Token) error

Save modifies a single record.

func (*GormTokenRepository) SetStatusFlagsForIdentity

func (m *GormTokenRepository) SetStatusFlagsForIdentity(ctx context.Context, identityID uuid.UUID, status int) error

func (*GormTokenRepository) TableName

func (m *GormTokenRepository) TableName() string

func (*GormTokenRepository) TokenPrivilegeTableName

func (m *GormTokenRepository) TokenPrivilegeTableName() string

type Token

type Token struct {
	gormsupport.Lifecycle

	// This is the primary key value
	TokenID uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key;column:token_id"`

	IdentityID uuid.UUID

	Status int

	TokenType string

	// The timestamp when the token will expire
	ExpiryTime time.Time
}

Token represents a single instance of an oauth token

func (*Token) HasStatus

func (m *Token) HasStatus(status int) bool

func (*Token) SetStatus

func (m *Token) SetStatus(status int, value bool)

func (Token) TableName

func (m Token) TableName() string

TableName overrides the table name settings in Gorm to force a specific table name in the database.

func (*Token) Valid

func (m *Token) Valid() bool

type TokenPrivilege

type TokenPrivilege struct {
	TokenID          uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key;column:token_id"`
	PrivilegeCacheID uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key;column:privilege_cache_id"`
}

TokenPrivilege is a simple many-to-many table used to link privileges to tokens

func (TokenPrivilege) TableName

func (m TokenPrivilege) TableName() string

type TokenRepository

type TokenRepository interface {
	CheckExists(ctx context.Context, id uuid.UUID) (bool, error)
	Load(ctx context.Context, id uuid.UUID) (*Token, error)
	Create(ctx context.Context, token *Token) error
	Save(ctx context.Context, token *Token) error
	Delete(ctx context.Context, id uuid.UUID) error
	ListForIdentity(ctx context.Context, id uuid.UUID) ([]Token, error)
	CreatePrivilege(ctx context.Context, privilege *TokenPrivilege) error
	ListPrivileges(ctx context.Context, tokenID uuid.UUID) ([]permission.PrivilegeCache, error)
	SetStatusFlagsForIdentity(ctx context.Context, identityID uuid.UUID, status int) error
	CleanupExpiredTokens(ctx context.Context, retentionHours int) error
}

TokenRepository represents the storage interface.

func NewTokenRepository

func NewTokenRepository(db *gorm.DB) TokenRepository

NewTokenRepository creates a new storage type.

Jump to

Keyboard shortcuts

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