Documentation
¶
Index ¶
- Variables
- type Auth
- type Groups
- func (s *Groups) AttachUser(ctx context.Context, params model.UserGroupParams) error
- func (s *Groups) Create(ctx context.Context, record *model.Group) error
- func (s *Groups) Delete(ctx context.Context, name string) error
- func (s *Groups) DropUser(ctx context.Context, params model.UserGroupParams) error
- func (s *Groups) List(ctx context.Context, params model.ListParams) ([]*model.Group, int64, error)
- func (s *Groups) ListUsers(ctx context.Context, params model.UserGroupParams) ([]*model.UserGroup, int64, error)
- func (s *Groups) PermitUser(ctx context.Context, params model.UserGroupParams) error
- func (s *Groups) Show(ctx context.Context, name string) (*model.Group, error)
- func (s *Groups) Update(ctx context.Context, record *model.Group) error
- type Store
- func (s *Store) Admin(username, password, email string) error
- func (s *Store) Close() (bool, error)
- func (s *Store) Handle() *bun.DB
- func (s *Store) Info() map[string]interface{}
- func (s *Store) Migrate(ctx context.Context) (*migrate.MigrationGroup, error)
- func (s *Store) Migrator(ctx context.Context) (*migrate.Migrator, error)
- func (s *Store) Open() (bool, error)
- func (s *Store) Ping() (bool, error)
- func (s *Store) Prepare() error
- func (s *Store) Rollback(ctx context.Context) (*migrate.MigrationGroup, error)
- func (s *Store) SearchQuery(q *bun.SelectQuery, _ string) *bun.SelectQuery
- func (s *Store) WithPrincipal(principal *model.User) *Store
- type Users
- func (s *Users) AttachGroup(ctx context.Context, params model.UserGroupParams) error
- func (s *Users) Create(ctx context.Context, record *model.User) error
- func (s *Users) Delete(ctx context.Context, name string) error
- func (s *Users) DropGroup(ctx context.Context, params model.UserGroupParams) error
- func (s *Users) List(ctx context.Context, params model.ListParams) ([]*model.User, int64, error)
- func (s *Users) ListGroups(ctx context.Context, params model.UserGroupParams) ([]*model.UserGroup, int64, error)
- func (s *Users) PermitGroup(ctx context.Context, params model.UserGroupParams) error
- func (s *Users) Show(ctx context.Context, name string) (*model.User, error)
- func (s *Users) Update(ctx context.Context, record *model.User) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrWrongCredentials is returned when credentials are wrong. ErrWrongCredentials = errors.New("wrong credentials provided") // ErrAlreadyAssigned defines the error if relation is already assigned. ErrAlreadyAssigned = errors.New("user pack already exists") // ErrNotAssigned defines the error if relation is not assigned. ErrNotAssigned = errors.New("user pack is not defined") // ErrGroupNotFound is returned when a user was not found. ErrGroupNotFound = errors.New("group not found") // ErrUserNotFound is returned when a user was not found. ErrUserNotFound = errors.New("user not found") )
View Source
var ( // ErrUnknownDriver defines a named error for unknown store drivers. ErrUnknownDriver = fmt.Errorf("unknown database driver") )
View Source
var ( // Migrations define all database migrations. Migrations = []*gormigrate.Migration{ { ID: "0001_create_users_table", Migrate: func(tx *gorm.DB) error { type User struct { ID string `gorm:"primaryKey;length:20"` Scim string `gorm:"length:255"` Username string `gorm:"unique;length:255"` Hashword string `gorm:"length:255"` Email string `gorm:"length:255"` Fullname string `gorm:"length:255"` Active bool `gorm:"default:false"` Admin bool `gorm:"default:false"` CreatedAt time.Time UpdatedAt time.Time } return tx.Migrator().CreateTable(&User{}) }, Rollback: func(tx *gorm.DB) error { return tx.Migrator().DropTable("users") }, }, { ID: "0002_create_user_auths_table", Migrate: func(tx *gorm.DB) error { type UserAuth struct { ID string `gorm:"primaryKey;length:20"` UserID string `gorm:"length:20"` Provider string `gorm:"length:255"` Ref string `gorm:"length:255"` CreatedAt time.Time UpdatedAt time.Time } return tx.Migrator().CreateTable(&UserAuth{}) }, Rollback: func(tx *gorm.DB) error { return tx.Migrator().DropTable("user_auths") }, }, { ID: "0003_create_user_auths_users_constraint", Migrate: func(tx *gorm.DB) error { type UserAuth struct { UserID string `gorm:"length:20"` } type User struct { ID string `gorm:"primaryKey"` Auths []*UserAuth `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` } return tx.Migrator().CreateConstraint(&User{}, "Auths") }, Rollback: func(tx *gorm.DB) error { type UserAuth struct { UserID string `gorm:"length:20"` } type User struct { ID string `gorm:"primaryKey"` Auths []*UserAuth `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` } return tx.Migrator().DropConstraint(&User{}, "Auths") }, }, { ID: "0004_create_groups_table", Migrate: func(tx *gorm.DB) error { type Group struct { ID string `gorm:"primaryKey;length:20"` Scim string `gorm:"length:255"` Slug string `gorm:"unique;length:255"` Name string `gorm:"unique;length:255"` CreatedAt time.Time UpdatedAt time.Time } return tx.Migrator().CreateTable(&Group{}) }, Rollback: func(tx *gorm.DB) error { return tx.Migrator().DropTable("groups") }, }, { ID: "0005_create_user_groups_table", Migrate: func(tx *gorm.DB) error { type UserGroup struct { UserID string `gorm:"primaryKey;autoIncrement:false;length:20"` GroupID string `gorm:"primaryKey;autoIncrement:false;length:20"` Perm string `gorm:"length:64"` CreatedAt time.Time UpdatedAt time.Time } return tx.Migrator().CreateTable(&UserGroup{}) }, Rollback: func(tx *gorm.DB) error { return tx.Migrator().DropTable("user_groups") }, }, { ID: "0006_create_user_groups_groups_constraint", Migrate: func(tx *gorm.DB) error { type UserGroup struct { UserID string `gorm:"primaryKey;autoIncrement:false;length:20"` GroupID string `gorm:"primaryKey;autoIncrement:false;length:20"` } type Group struct { ID string `gorm:"primaryKey"` Users []*UserGroup `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` } return tx.Migrator().CreateConstraint(&Group{}, "Users") }, Rollback: func(tx *gorm.DB) error { type UserGroup struct { UserID string `gorm:"primaryKey;autoIncrement:false;length:20"` GroupID string `gorm:"primaryKey;autoIncrement:false;length:20"` } type Group struct { ID string `gorm:"primaryKey"` Users []*UserGroup `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` } return tx.Migrator().DropConstraint(&Group{}, "Users") }, }, { ID: "0007_create_user_groups_users_constraint", Migrate: func(tx *gorm.DB) error { type UserGroup struct { UserID string `gorm:"primaryKey;autoIncrement:false;length:20"` GroupID string `gorm:"primaryKey;autoIncrement:false;length:20"` } type User struct { ID string `gorm:"primaryKey"` Groups []*UserGroup `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` } return tx.Migrator().CreateConstraint(&User{}, "Groups") }, Rollback: func(tx *gorm.DB) error { type UserGroup struct { UserID string `gorm:"primaryKey;autoIncrement:false;length:20"` GroupID string `gorm:"primaryKey;autoIncrement:false;length:20"` } type User struct { ID string `gorm:"primaryKey"` Groups []*UserGroup `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` } return tx.Migrator().DropConstraint(&User{}, "Groups") }, }, } )
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth provides all database operations related to auth.
type Groups ¶
type Groups struct {
// contains filtered or unexported fields
}
Groups provides all database operations related to groups.
func (*Groups) AttachUser ¶
AttachUser implements the attachment of a group to an user.
func (*Groups) ListUsers ¶
func (s *Groups) ListUsers(ctx context.Context, params model.UserGroupParams) ([]*model.UserGroup, int64, error)
ListUsers implements the listing of all users for a group.
func (*Groups) PermitUser ¶
PermitUser implements the permission update for a user on a group.
type Store ¶
type Store struct { Auth *Auth Groups *Groups Users *Users // contains filtered or unexported fields }
Store provides the general database abstraction layer.
func (*Store) SearchQuery ¶
func (s *Store) SearchQuery(q *bun.SelectQuery, _ string) *bun.SelectQuery
SearchQuery builds a query for search terms.
type Users ¶
type Users struct {
// contains filtered or unexported fields
}
Users provides all database operations related to users.
func (*Users) AttachGroup ¶
AttachGroup implements the attachment of an user to a group.
func (*Users) ListGroups ¶
func (s *Users) ListGroups(ctx context.Context, params model.UserGroupParams) ([]*model.UserGroup, int64, error)
ListGroups implements the listing of all groups for an user.
func (*Users) PermitGroup ¶
PermitGroup implements the permission update for a group on an user.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.