tbrac

package
v1.0.33 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTBAC

func NewTBAC(db *gorm.DB) *tbac

NewTBAC returns a new TBAC authz checker.

func RunMigrations

func RunMigrations(db *gorm.DB) error

RunMigrations is a function that runs the migrations for the authz package.

Types

type APIKey

type APIKey struct {
	// ID is the primary key of the API key.
	ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid()"`
	// Key is the API key.
	Key string `gorm:"uniqueIndex" validate:"required,alphanum,gt=3,lt=255,lowercase"`
	// Description is the description of the API key.
	Description *string `validate:"omitempty,max=255"`
	// CreatedAt is the time the API key was created.
	CreatedAt time.Time
	// UpdatedAt is the time the API key was last updated.
	UpdatedAt time.Time
	// DeletedAt is the time the API key was deleted.
	DeletedAt gorm.DeletedAt
}

APIKey is an API key.

type APIKeyRole

type APIKeyRole struct {
	// APIKeyID is the primary key of the API key.
	KeyID uuid.UUID `gorm:"primaryKey"`
	Key   APIKey

	// RoleID is the primary key of the role.
	RoleID uuid.UUID `gorm:"primaryKey"`
	Role   Role

	// TeamID is the primary key of the team.
	TeamID uuid.UUID `gorm:"primaryKey"`
	Team   Team

	// CreatedAt is the time the API key role was created.
	CreatedAt time.Time
	// UpdatedAt is the time the API key role was last updated.
	UpdatedAt time.Time
	// DeletedAt is the time the API key role was deleted.
	DeletedAt gorm.DeletedAt
}

APIKeyRole is a user role.

type Permission

type Permission struct {
	// ID is the primary key of the permission.
	ID uint `json:"id" gorm:"primaryKey"`
	// Scope is the unique identifier of the permission.
	Scope string `json:"scope" gorm:"uniqueIndex" validate:"required,alphanum,gt=3,lt=255,lowercase"`
	// Description is the description of the permission.
	Description *string `json:"description" validate:"omitempty,max=255"`

	// Roles are the roles that have the permission.
	Roles *[]Role `gorm:"many2many:role_permissions;"`

	// CreatedAt is the time the permission was created.
	CreatedAt time.Time
	// UpdatedAt is the time the permission was last updated.
	UpdatedAt time.Time
	// DeletedAt is the time the permission was deleted.
	DeletedAt gorm.DeletedAt
}

Permission is a permission that a user can have.

func (*Permission) Validate

func (p *Permission) Validate() error

Validate validates the permission.

type Role

type Role struct {
	ID          uuid.UUID `gorm:"type:uuid;default:gen_random_uuid()"`
	Name        string    `gorm:"uniqueIndex"`
	Description string    `validate:"omitempty,max=255"`

	Permissions *[]Permission `gorm:"many2many:role_permissions;"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

Role is a role that a user can have.

func (*Role) Validate

func (r *Role) Validate() error

Validate validates the role.

type Team

type Team struct {
	// ID is the primary key of the team.
	ID uuid.UUID `json:"id" gorm:"type:uuid;default:gen_random_uuid()"`
	// Name is the name of the team.
	Name string `json:"name" validate:"required,alphanum,gt=3,lt=255"`
	// Slug is the unique identifier of the team.
	Slug string `json:"slug" gorm:"uniqueIndex" validate:"required,alphanum,gt=3,lt=255,lowercase"`
	// Description is the description of the team.
	Description *string `json:"description" validate:"omitempty,max=255"`

	// Users are the users in the team.
	Users *[]User `gorm:"many2many:user_teams;"`

	// CreatedAt is the time the team was created.
	CreatedAt time.Time
	// UpdatedAt is the time the team was last updated.
	UpdatedAt time.Time
	// DeletedAt is the time the team was deleted.
	DeletedAt gorm.DeletedAt
}

Team is a group of users.

func (*Team) Validate

func (t *Team) Validate() error

Validate validates the team.

type User

type User struct {
	Teams *[]Team `gorm:"many2many:user_teams;"`
	Roles *[]Role `gorm:"many2many:user_roles;"`

	*adapters.GothUser
}

User is a user.

func (*User) Validate

func (u *User) Validate() error

Validate validates the user.

type UserRole

type UserRole struct {
	// UserID is the primary key of the user.
	UserID uuid.UUID `gorm:"primaryKey"`
	User   User

	// TeamID is the primary key of the team.
	TeamID uuid.UUID `gorm:"primaryKey"`
	Team   Team

	// RoleID is the primary key of the role.
	RoleID uuid.UUID `gorm:"primaryKey"`
	Role   Role

	// CreatedAt is the time the user role was created.
	CreatedAt time.Time
	// UpdatedAt is the time the user role was last updated.
	UpdatedAt time.Time
	// DeletedAt is the time the user role was deleted.
	DeletedAt gorm.DeletedAt
}

UserRole is a user role.

Jump to

Keyboard shortcuts

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