Documentation ¶
Index ¶
- type AuthSubject
- type DB
- func (db *DB) AddAuthSubjectTx(ctx context.Context, tx *sql.Tx, a *AuthSubject) error
- func (db *DB) Delete(ctx context.Context, id string) error
- func (db *DB) DeleteAuthSubjectTx(ctx context.Context, tx *sql.Tx, a *AuthSubject) error
- func (db *DB) DeleteManyTx(ctx context.Context, tx *sql.Tx, ids []string) error
- func (db *DB) FindAll(ctx context.Context) ([]User, error)
- func (db *DB) FindAllAuthSubjectsForUser(ctx context.Context, userID string) ([]AuthSubject, error)
- func (db *DB) FindMany(ctx context.Context, ids []string) ([]User, error)
- func (db *DB) FindOne(ctx context.Context, id string) (*User, error)
- func (db *DB) FindOneTx(ctx context.Context, tx *sql.Tx, id string, forUpdate bool) (*User, error)
- func (db *DB) FindSomeAuthSubjectsForProvider(ctx context.Context, limit int, afterSubjectID, providerID string) ([]AuthSubject, error)
- func (db *DB) Insert(ctx context.Context, u *User) (*User, error)
- func (db *DB) InsertTx(ctx context.Context, tx *sql.Tx, u *User) (*User, error)
- func (db *DB) Search(ctx context.Context, opts *SearchOptions) ([]User, error)
- func (db *DB) Update(ctx context.Context, u *User) error
- func (db *DB) UpdateTx(ctx context.Context, tx *sql.Tx, u *User) error
- type SearchCursor
- type SearchOptions
- type Store
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthSubject ¶
type AuthSubject struct { // ProviderID is the ID for the provider of the user. ProviderID string // SubjectID is the ID for the subject of the user. SubjectID string // UserID is the ID of the user. UserID string }
An AuthSubject contains information about the auth provider and subject ID for a particular user.
func (AuthSubject) Normalize ¶
func (a AuthSubject) Normalize() (*AuthSubject, error)
Normalize will validate and produce a normalized AuthSubject struct.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB implements the Store against a *sql.DB backend.
func NewDB ¶
NewDB will create a DB backend from a sql.DB. An error will be returned if statements fail to prepare.
func (*DB) AddAuthSubjectTx ¶
AddAuthSubjectTx implements the Store interface. It is used to add an auth subject to a given user.
func (*DB) DeleteAuthSubjectTx ¶
DeleteAuthSubjectTx implements the Store interface. It is used to remove an auth subject for a given user.
func (*DB) DeleteManyTx ¶
func (*DB) FindAllAuthSubjectsForUser ¶
FindAllAuthSubjectsForUser implements the Store interface. It finds all auth subjects associated with a given userID.
func (*DB) FindSomeAuthSubjectsForProvider ¶
func (db *DB) FindSomeAuthSubjectsForProvider(ctx context.Context, limit int, afterSubjectID, providerID string) ([]AuthSubject, error)
FindSomeAuthSubjectsForProvider implements the Store interface. It finds all auth subjects associated with a given userID.
func (*DB) Insert ¶
Insert implements the Store interface by inserting the new User into the database.
func (*DB) InsertTx ¶
InsertTx implements the Store interface by inserting the new User into the database. The insert statement is first wrapped in tx.
type SearchCursor ¶
type SearchCursor struct {
Name string `json:"n,omitempty"`
}
SearchCursor is used to indicate a position in a paginated list.
type SearchOptions ¶
type SearchOptions struct { Search string `json:"s,omitempty"` After SearchCursor `json:"a,omitempty"` // Omit specifies a list of user IDs to exclude from the results. Omit []string `json:"o,omitempty"` Limit int `json:"-"` // CMValue is matched against the user's contact method phone number. CMValue string `json:"v,omitempty"` // CMType is matched against the user's contact method type. CMType contactmethod.Type `json:"t,omitempty"` }
SearchOptions allow filtering and paginating the list of users.
type Store ¶
type Store interface { Insert(context.Context, *User) (*User, error) InsertTx(context.Context, *sql.Tx, *User) (*User, error) Update(context.Context, *User) error UpdateTx(context.Context, *sql.Tx, *User) error Delete(context.Context, string) error DeleteManyTx(context.Context, *sql.Tx, []string) error FindOne(context.Context, string) (*User, error) FindOneTx(ctx context.Context, tx *sql.Tx, id string, forUpdate bool) (*User, error) FindAll(context.Context) ([]User, error) FindMany(context.Context, []string) ([]User, error) Search(context.Context, *SearchOptions) ([]User, error) AddAuthSubjectTx(ctx context.Context, tx *sql.Tx, a *AuthSubject) error DeleteAuthSubjectTx(ctx context.Context, tx *sql.Tx, a *AuthSubject) error FindAllAuthSubjectsForUser(ctx context.Context, userID string) ([]AuthSubject, error) FindSomeAuthSubjectsForProvider(ctx context.Context, limit int, afterSubjectID, providerID string) ([]AuthSubject, error) }
Store allows the lookup and management of Users.
type User ¶
type User struct { // ID is the unique identifier for the user ID string `json:"id"` // Name is the full name of the user Name string `json:"name"` // Email is the primary contact email for the user. It is used for account-related communications Email string `json:"email"` // AvatarURL is an absolute address for an image to be used as the avatar. AvatarURL string `json:"avatar_url"` // AlertStatusCMID defines a contact method ID for alert status updates. AlertStatusCMID string `json:"alert_status_log_contact_method_id"` // The Role of the user Role permission.Role `json:"role" store:"readonly"` }
A User is the base information of a user of the system. Authentication details are stored separately based on the auth provider.
func (User) Normalize ¶
Normalize will produce a normalized/validated User struct. Will only do the validate if email is not empty
func (User) ResolveAvatarURL ¶
ResolveAvatarURL will resolve the user avatar URL, using the email if none is set.