data

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConflict       = errors.New("conflict")
	ErrNotFound       = errors.New("not found")
	ErrInvalidRequest = errors.New("invalid request")

	True  = true
	False = false
)

Functions

func CompareSlices

func CompareSlices(a, b []string) bool

func CtxUserName added in v0.7.11

func CtxUserName(ctx context.Context) string

func WithContextUserName added in v0.7.11

func WithContextUserName(ctx context.Context, userName string) context.Context

Types

type Alias

type Alias struct {
	Name string `json:"name" badgerhold:"unique"`
	ID   string `json:"id"   badgerhold:"index"`
}

type CheckConfig added in v0.8.14

type CheckConfig struct {
	// DefaultHosts for checkHost function. If resource hosts is empty, it will use this host.
	DefaultHosts []string `cfg:"default_hosts"`
	// NoHostCheck disable host checking on permission hosts.
	NoHostCheck bool `cfg:"no_host_check"`
}

type CheckRequest

type CheckRequest struct {
	ID    string `json:"id"`
	Alias string `json:"alias"`

	Host   string `json:"host"`
	Path   string `json:"path"`
	Method string `json:"method"`
}

type CheckRequestUser

type CheckRequestUser struct {
	Host   string `json:"host"`
	Path   string `json:"path"`
	Method string `json:"method"`
}

type CheckResponse

type CheckResponse struct {
	Allowed bool `json:"allowed"`
}

type Dashboard

type Dashboard struct {
	Roles []RoleExtended `json:"roles"`

	TotalRoles           uint64 `json:"total_roles"`
	TotalPermissions     uint64 `json:"total_permissions"`
	TotalUsers           uint64 `json:"total_users"`
	TotalServiceAccounts uint64 `json:"total_service_accounts"`
}

type GetLMapRequest

type GetLMapRequest struct {
	Name string `json:"name"`

	RoleIDs []string `json:"role_ids"`

	Limit  int64 `json:"limit"`
	Offset int64 `json:"offset"`
}

type GetPermissionRequest

type GetPermissionRequest struct {
	ID   string `json:"id"`
	Name string `json:"name"`

	Path        string `json:"path"`
	Method      string `json:"method"`
	Description string `json:"description"`

	Limit  int64 `json:"limit"`
	Offset int64 `json:"offset"`

	Data map[string]string `json:"data"`

	AddRoles bool `json:"add_roles"`
}

type GetRoleRequest

type GetRoleRequest struct {
	ID   string `json:"id"`
	Name string `json:"name"`

	PermissionIDs []string `json:"permission_ids"`
	RoleIDs       []string `json:"role_ids"`

	Path        string   `json:"path"`
	Method      string   `json:"method"`
	Description string   `json:"description"`
	Permissions []string `json:"permissions"`

	Limit  int64 `json:"limit"`
	Offset int64 `json:"offset"`

	AddPermissions bool `json:"add_permissions"`
	AddRoles       bool `json:"add_roles"`
	AddTotalUsers  bool `json:"add_total_users"`
}

type GetUserRequest

type GetUserRequest struct {
	ID    string `json:"id"`
	Alias string `json:"alias"`

	RoleIDs []string `json:"role_ids"`

	UID      string `json:"uid"`
	Name     string `json:"name"`
	Email    string `json:"email"`
	RoleType string `json:"role_type"`

	Path        string   `json:"path"`
	Method      string   `json:"method"`
	Permissions []string `json:"permissions"`

	ServiceAccount *bool `json:"service_account"`
	Disabled       *bool `json:"disabled"`
	LocalUser      *bool `json:"local_user"`

	Limit  int64 `json:"limit"`
	Offset int64 `json:"offset"`

	AddRoles       bool `json:"add_role"`
	AddPermissions bool `json:"add_permissions"`
	AddData        bool `json:"add_data"`
	AddScopeRoles  bool `json:"add_scope_roles"`

	Sanitize bool `json:"sanitize"`
}

type IDName

type IDName struct {
	ID        string      `json:"id"`
	Name      string      `json:"name"`
	ExpiresAt *types.Time `json:"expires_at,omitempty"` // Optional field for temporary roles
	Inherited bool        `json:"inherited,omitempty"`  // Indicates if the role/permission is inherited
}

type LMap

type LMap struct {
	Name    string   `json:"name"     badgerhold:"unique"`
	RoleIDs []string `json:"role_ids"`

	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	UpdatedBy string `json:"updated_by"`
}

type LMapCheckCreate

type LMapCheckCreate struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

type LMapPatch

type LMapPatch struct {
	RoleIDs *[]string `json:"role_ids"`
}

type Message

type Message struct {
	Text string `json:"text,omitempty"`
	Err  string `json:"error,omitempty"`
}

type Meta

type Meta struct {
	Offset         int64  `json:"offset,omitempty"`
	Limit          int64  `json:"limit,omitempty"`
	TotalItemCount uint64 `json:"total_item_count,omitempty"`
}

type MixID added in v0.8.15

type MixID struct {
	IsTmp     bool
	ID        string
	StartsAt  types.Time
	ExpiresAt types.Time
}

type NameRequest added in v0.7.11

type NameRequest struct {
	Name string `json:"name"`
}

type Permission

type Permission struct {
	ID          string              `json:"id"          badgerhold:"unique"`
	Name        string              `json:"name"        badgerhold:"index"`
	Resources   []Resource          `json:"resources"`
	Description string              `json:"description"`
	Data        map[string]any      `json:"data"`
	Scope       map[string][]string `json:"scope"`

	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	UpdatedBy string `json:"updated_by"`
}

Permission is a struct that represents a permission table in the database.

type PermissionExtended added in v0.8.14

type PermissionExtended struct {
	*Permission

	Roles []IDName `json:"roles,omitempty"`
}

type PermissionIDs

type PermissionIDs struct {
	PermissionIDs []string `json:"permission_ids"`
}

type PermissionPatch

type PermissionPatch struct {
	Name        *string             `json:"name"`
	Resources   *[]Resource         `json:"resources"`
	Description *string             `json:"description"`
	Data        map[string]any      `json:"data"`
	Scope       map[string][]string `json:"scope"`
}

type Resource

type Resource struct {
	Hosts []string `json:"hosts"`
	// Deprecated: use Paths instead of Path
	Path     string     `json:"path"`
	Paths    []string   `json:"paths"`
	Methods  []string   `json:"methods"`
	Excluded []Resource `json:"excluded"`
}

type Response

type Response[T any] struct {
	Message *Message `json:"message,omitempty"`
	Meta    *Meta    `json:"meta,omitempty"`
	Payload T        `json:"payload"`
}

type ResponseCreate

type ResponseCreate struct {
	ID string `json:"id"`
}

type ResponseCreateBulk

type ResponseCreateBulk struct {
	IDs []string `json:"ids"`
}

type ResponseMessage

type ResponseMessage struct {
	Message *Message `json:"message,omitempty"`
}

func NewResponseMessage

func NewResponseMessage(text string) ResponseMessage

type ResponseVersion

type ResponseVersion struct {
	Version uint64 `json:"version"`
}

type Role

type Role struct {
	ID            string         `json:"id"             badgerhold:"unique"`
	Name          string         `json:"name"           badgerhold:"index"`
	PermissionIDs []string       `json:"permission_ids"`
	RoleIDs       []string       `json:"role_ids"`
	Data          map[string]any `json:"data"`
	Description   string         `json:"description"`

	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	UpdatedBy string `json:"updated_by"`
}

Role is a struct that represents a role table in the database.

type RoleExtended

type RoleExtended struct {
	*Role

	Roles       []IDName `json:"roles,omitempty"`
	Permissions []IDName `json:"permissions,omitempty"`
	TotalUsers  uint64   `json:"total_users"`
}

type RoleIDs

type RoleIDs struct {
	RoleIDs []string `json:"role_ids"`
}

type RolePatch

type RolePatch struct {
	Name          *string         `json:"name"`
	PermissionIDs *[]string       `json:"permission_ids"`
	RoleIDs       *[]string       `json:"role_ids"`
	Data          *map[string]any `json:"data"`
	Description   *string         `json:"description"`
}

type RoleRelation

type RoleRelation struct {
	Roles       *[]string `json:"roles"`
	Permissions *[]string `json:"permissions"`
}

type TmpID added in v0.8.15

type TmpID struct {
	ID        string     `json:"id"`
	StartsAt  types.Time `json:"starts_at"`
	ExpiresAt types.Time `json:"expires_at"`
}

type Token added in v0.7.11

type Token struct {
	ID          string `json:"id"          badgerhold:"unique"`
	Name        string `json:"name"        badgerhold:"index"`
	Token       string `json:"token"       badgerhold:"index"`
	Description string `json:"description"`
	ExpiresAt   string `json:"expires_at"`

	PermissionIDs []string `json:"permission_ids"`
	RoleIDs       []string `json:"role_ids"`

	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	UpdatedBy string `json:"updated_by"`
}

Token is a struct that represents a token table in the database.

type User

type User struct {
	ID             string         `json:"id"              badgerhold:"unique"`
	Alias          []string       `json:"alias"`
	RoleIDs        []string       `json:"role_ids"`
	SyncRoleIDs    []string       `json:"sync_role_ids"`
	Details        map[string]any `json:"details"`
	Disabled       bool           `json:"-"`
	ServiceAccount bool           `json:"service_account"`
	Local          bool           `json:"local"`
	PermissionIDs  []string       `json:"permission_ids"`

	TmpRoleIDs       []TmpID `json:"tmp_role_ids"`
	TmpPermissionIDs []TmpID `json:"tmp_permission_ids"`

	AllRolePermanentIDs []string `json:"-"`
	AllRoleTmpIDs       []MixID  `json:"-"`
	AllPermTmpIDs       []MixID  `json:"-"`

	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	UpdatedBy string `json:"updated_by"`
}

User is a struct that represents a user table in the database.

type UserAccess added in v0.8.15

type UserAccess struct {
	RoleIDs       []string    `json:"role_ids"`
	PermissionIDs []string    `json:"permission_ids"`
	StartsAt      types.Time  `json:"starts_at"`  // RFC3339 time format, e.g., "2024-12-31T23:59:59Z"
	ExpiresAt     *types.Time `json:"expires_at"` // RFC3339 time format, e.g., "2024-12-31T23:59:59Z"
	ExpiresIn     *string     `json:"expires_in"` // Duration string, e.g., "24h", "7d", etc.
}

func (*UserAccess) Expires added in v0.8.15

func (u *UserAccess) Expires() (*types.Time, error)

Expires returns the expiration time.

type UserCreate

type UserCreate struct {
	User

	IsActive bool `json:"is_active"`
}

type UserExtended

type UserExtended struct {
	*User

	IsActive    bool                `json:"is_active"`
	Roles       []IDName            `json:"roles,omitempty"`
	Permissions []IDName            `json:"permissions,omitempty"`
	Data        []any               `json:"data,omitempty"`
	Scope       map[string][]string `json:"scope,omitempty"`
}

type UserInfo

type UserInfo struct {
	Details     map[string]any `json:"details"`
	Roles       []string       `json:"roles,omitempty"`
	Permissions []string       `json:"permissions,omitempty"`
	Data        []any          `json:"data,omitempty"`
	IsActive    bool           `json:"is_active"`
}

type UserPatch

type UserPatch struct {
	Alias         *[]string       `json:"alias"`
	RoleIDs       *[]string       `json:"role_ids"`
	SyncRoleIDs   *[]string       `json:"sync_role_ids"`
	PermissionIDs *[]string       `json:"permission_ids"`
	Details       *map[string]any `json:"details"`
	IsActive      *bool           `json:"is_active"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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