account

package
v0.0.0-...-284eadf Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package account contains the code to manage users and integrate authenthication functionalities from other identity providers.

Index

Constants

View Source
const (
	// KeycloakIDP is the name of the main Keycloak Identity Provider
	KeycloakIDP string = "kc"
)

Variables

This section is empty.

Functions

func IdentityFilterByID

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

IdentityFilterByID is a gorm filter for Identity ID.

func IdentityFilterByProfileURL

func IdentityFilterByProfileURL(profileURL string) func(db *gorm.DB) *gorm.DB

IdentityFilterByProfileURL is a gorm filter by 'profile_url'

func IdentityFilterByProviderType

func IdentityFilterByProviderType(providerType string) func(db *gorm.DB) *gorm.DB

IdentityFilterByProviderType is a gorm filter by 'provider_type'

func IdentityFilterByRegistrationCompleted

func IdentityFilterByRegistrationCompleted(registrationCompleted bool) func(db *gorm.DB) *gorm.DB

IdentityFilterByRegistrationCompleted is a gorm filter by 'registration_completed'

func IdentityFilterByUserID

func IdentityFilterByUserID(userID uuid.UUID) func(db *gorm.DB) *gorm.DB

IdentityFilterByUserID is a gorm filter for a Belongs To relationship.

func IdentityFilterByUsername

func IdentityFilterByUsername(username string) func(db *gorm.DB) *gorm.DB

IdentityFilterByUsername is a gorm filter by 'username'

func IdentityWithUser

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

IdentityWithUser is a gorm filter for preloading the User relationship.

func UserFilterByEmail

func UserFilterByEmail(email string) func(db *gorm.DB) *gorm.DB

UserFilterByEmail is a gorm filter for User ID.

func UserFilterByID

func UserFilterByID(userID uuid.UUID) func(db *gorm.DB) *gorm.DB

UserFilterByID is a gorm filter for User ID.

Types

type ContextInformation

type ContextInformation map[string]interface{}

func (ContextInformation) Equal

Equal returns true if two ContextInformation objects are equal; otherwise false is returned. TODO: (kwk) think about a better comparison for ContextInformation map.

func (*ContextInformation) Scan

func (j *ContextInformation) Scan(src interface{}) error

func (ContextInformation) Value

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

type GormIdentityRepository

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

GormIdentityRepository is the implementation of the storage interface for Identity.

func NewIdentityRepository

func NewIdentityRepository(db *gorm.DB) *GormIdentityRepository

NewIdentityRepository creates a new storage type.

func (*GormIdentityRepository) CheckExists

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

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

func (*GormIdentityRepository) Create

func (m *GormIdentityRepository) Create(ctx context.Context, model *Identity) error

Create creates a new record.

func (*GormIdentityRepository) Delete

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

Delete removes a single record.

func (*GormIdentityRepository) First

func (m *GormIdentityRepository) First(funcs ...func(*gorm.DB) *gorm.DB) (*Identity, error)

First returns the first Identity element that matches the given criteria

func (*GormIdentityRepository) IsValid

func (m *GormIdentityRepository) IsValid(ctx context.Context, id uuid.UUID) bool

IsValid returns true if the identity exists

func (*GormIdentityRepository) List

List return all user identities

func (*GormIdentityRepository) Load

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

func (*GormIdentityRepository) Lookup

func (m *GormIdentityRepository) Lookup(ctx context.Context, username, profileURL, providerType string) (*Identity, error)

Lookup looks for an existing identity with the given `profileURL` or creates a new one

func (*GormIdentityRepository) Query

func (m *GormIdentityRepository) Query(funcs ...func(*gorm.DB) *gorm.DB) ([]Identity, error)

Query expose an open ended Query model

func (*GormIdentityRepository) Save

func (m *GormIdentityRepository) Save(ctx context.Context, model *Identity) error

Save modifies a single record.

func (*GormIdentityRepository) Search

func (m *GormIdentityRepository) Search(ctx context.Context, q string, start int, limit int) ([]Identity, int, error)

Search searches for Identites where FullName like %q% or users.email like %q% or users.username like %q%

func (*GormIdentityRepository) TableName

func (m *GormIdentityRepository) TableName() string

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

type GormUserRepository

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

GormUserRepository is the implementation of the storage interface for User.

func (*GormUserRepository) CheckExists

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

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

func (*GormUserRepository) Create

func (m *GormUserRepository) Create(ctx context.Context, u *User) error

Create creates a new record.

func (*GormUserRepository) Delete

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

Delete removes a single record.

func (*GormUserRepository) List

func (m *GormUserRepository) List(ctx context.Context) ([]User, error)

List return all users

func (*GormUserRepository) Load

func (m *GormUserRepository) Load(ctx context.Context, id uuid.UUID) (*User, error)

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

func (*GormUserRepository) Query

func (m *GormUserRepository) Query(funcs ...func(*gorm.DB) *gorm.DB) ([]User, error)

Query expose an open ended Query model

func (*GormUserRepository) Save

func (m *GormUserRepository) Save(ctx context.Context, model *User) error

Save modifies a single record

func (*GormUserRepository) TableName

func (m *GormUserRepository) TableName() string

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

type Identity

type Identity struct {
	gormsupport.Lifecycle
	// This is the ID PK field. For identities provided by Keycloak this ID equals to the Keycloak. For other types of IDP (github, oso, etc) this ID is generated automaticaly
	ID uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key"`
	// The username of the Identity
	Username string
	// Whether username has been updated.
	RegistrationCompleted bool `gorm:"column:registration_completed"`
	// ProviderType The type of provider, such as "keycloak", "github", "oso", etc
	ProviderType string `gorm:"column:provider_type"`
	// the URL of the profile on the remote work item service
	ProfileURL *string `gorm:"column:profile_url"`
	// Link to User
	UserID NullUUID `sql:"type:uuid"`
	User   User
}

Identity describes a federated identity provided by Identity Provider (IDP) such as Keycloak, GitHub, OSO, etc. One User account can have many Identities

func (Identity) GetETagData

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

GetETagData returns the field values to use to generate the ETag

func (Identity) GetLastModified

func (m Identity) GetLastModified() time.Time

GetLastModified returns the last modification time

func (Identity) TableName

func (m Identity) TableName() string

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

type IdentityRepository

type IdentityRepository interface {
	repository.Exister
	Load(ctx context.Context, id uuid.UUID) (*Identity, error)
	Create(ctx context.Context, identity *Identity) error
	Lookup(ctx context.Context, username, profileURL, providerType string) (*Identity, error)
	Save(ctx context.Context, identity *Identity) error
	Delete(ctx context.Context, id uuid.UUID) error
	Query(funcs ...func(*gorm.DB) *gorm.DB) ([]Identity, error)
	List(ctx context.Context) ([]Identity, error)
	IsValid(context.Context, uuid.UUID) bool
	Search(ctx context.Context, q string, start int, limit int) ([]Identity, int, error)
}

IdentityRepository represents the storage interface.

type NullUUID

type NullUUID struct {
	UUID  uuid.UUID
	Valid bool
}

NullUUID can be used with the standard sql package to represent a UUID value that can be NULL in the database

func (*NullUUID) Scan

func (u *NullUUID) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (NullUUID) Value

func (u NullUUID) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type User

type User struct {
	gormsupport.Lifecycle
	ID                 uuid.UUID          `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key"` // This is the ID PK field
	Email              string             `sql:"unique_index"`                                            // This is the unique email field
	FullName           string             // The fullname of the User
	ImageURL           string             // The image URL for the User
	Bio                string             // The bio of the User
	URL                string             // The URL of the User
	Company            string             // The (optional) Company of the User
	Identities         []Identity         // has many Identities from different IDPs
	ContextInformation ContextInformation `sql:"type:jsonb"` // context information of the user activity
}

User describes a User account. A few identities can be assosiated with one user account

func (User) GetETagData

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

GetETagData returns the field values to use to generate the ETag

func (User) GetLastModified

func (m User) GetLastModified() time.Time

GetLastModified returns the last modification time

func (User) TableName

func (m User) TableName() string

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

type UserRepository

type UserRepository interface {
	repository.Exister
	Load(ctx context.Context, ID uuid.UUID) (*User, error)
	Create(ctx context.Context, u *User) error
	Save(ctx context.Context, u *User) error
	List(ctx context.Context) ([]User, error)
	Delete(ctx context.Context, ID uuid.UUID) error
	Query(funcs ...func(*gorm.DB) *gorm.DB) ([]User, error)
}

UserRepository represents the storage interface.

func NewUserRepository

func NewUserRepository(db *gorm.DB) UserRepository

NewUserRepository creates a new storage type.

Jump to

Keyboard shortcuts

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