model

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientPrincipal

func ClientPrincipal(identifier string) string

func UserPrincipal

func UserPrincipal(identifier string) string

Types

type Action

type Action struct {
	ID        string    `json:"id" gorm:"primarykey"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (Action) TableName

func (Action) TableName() string

type Attribute

type Attribute struct {
	ID    int    `json:"-" gorm:"primarykey"`
	Key   string `json:"key" gorm:"column:key_name"`
	Value string `json:"value"`
}

func (Attribute) TableName

func (Attribute) TableName() string

type Attributes

type Attributes []*Attribute

func (Attributes) GetAttribute

func (a Attributes) GetAttribute(key string) string

type Audit

type Audit struct {
	ID            int64     `json:"id" gorm:"primarykey;autoIncrement"`
	Date          time.Time `json:"date"`
	Principal     string    `json:"principal"`
	ResourceKind  string    `json:"resource_kind"`
	ResourceValue string    `json:"resource_value"`
	Action        string    `json:"action"`
	IsAllowed     bool      `json:"is_allowed"`
	PolicyID      string    `json:"policy_id"`
}

func (Audit) TableName

func (Audit) TableName() string

type Client

type Client struct {
	ID        string    `json:"client_id" gorm:"primarykey"`
	Secret    string    `json:"client_secret" gorm:"type:varchar(512)"`
	Name      string    `json:"name"`
	Domain    string    `json:"domain" gorm:"type:varchar(512)"`
	Data      string    `json:"data,omitempty" gorm:"type:text"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (Client) TableName

func (Client) TableName() string

type CompiledPolicy

type CompiledPolicy struct {
	PolicyID      string    `json:"policy_id" gorm:"index"`
	PrincipalID   string    `json:"principal_id" gorm:"index"`
	ResourceKind  string    `json:"resource_kind" gorm:"index"`
	ResourceValue string    `json:"resource_value" gorm:"index"`
	ActionID      string    `json:"action_id" gorm:"index"`
	Version       int64     `json:"version" gorm:"index"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

func (CompiledPolicy) TableName

func (CompiledPolicy) TableName() string

type Models

type Models interface {
	Action | Audit | Attribute | Client | CompiledPolicy | Policy | Principal | Resource | Role | Stats | Token | User
}

Models is a constraint interface that allows only authz library models.

type Policy

type Policy struct {
	ID             string                       `json:"id" gorm:"primarykey"`
	Resources      []*Resource                  `json:"resources,omitempty" gorm:"many2many:authz_policies_resources;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	Actions        []*Action                    `json:"actions,omitempty" gorm:"many2many:authz_policies_actions;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	AttributeRules datatypes.JSONType[[]string] `json:"attribute_rules,omitempty" swaggertype:"object"`
	CreatedAt      time.Time                    `json:"created_at"`
	UpdatedAt      time.Time                    `json:"updated_at"`

	Roles []*Role `json:"-" gorm:"many2many:authz_roles_policies"`
}

func (Policy) TableName

func (Policy) TableName() string

type Principal

type Principal struct {
	ID         string     `json:"id" gorm:"primarykey"`
	Roles      []*Role    `json:"roles,omitempty" gorm:"many2many:authz_principals_roles;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	Attributes Attributes `json:"attributes,omitempty" gorm:"many2many:authz_principals_attributes;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	IsLocked   bool       `json:"is_locked" gorm:"is_locked"`
	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
}

func (Principal) TableName

func (Principal) TableName() string

type Resource

type Resource struct {
	ID         string     `json:"id" gorm:"primarykey"`
	Kind       string     `json:"kind" gorm:"kind"`
	Value      string     `json:"value" gorm:"value"`
	Attributes Attributes `json:"attributes,omitempty" gorm:"many2many:authz_resources_attributes;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	IsLocked   bool       `json:"is_locked" gorm:"is_locked"`
	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
}

func (Resource) TableName

func (Resource) TableName() string

type Role

type Role struct {
	ID        string    `json:"id" gorm:"primarykey"`
	Policies  []*Policy `json:"policies,omitempty" gorm:"many2many:authz_roles_policies;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	Principals []*Principal `json:"-" gorm:"many2many:authz_principals_roles;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

func (Role) TableName

func (Role) TableName() string

type Stats

type Stats struct {
	ID                  string    `json:"id" gorm:"primarykey"`
	Date                time.Time `json:"date" gorm:"date"`
	ChecksAllowedNumber int64     `json:"checks_allowed_number" gorm:"checks_allowed_number"`
	ChecksDeniedNumber  int64     `json:"checks_denied_number" gorm:"checks_denied_number"`
}

func (Stats) TableName

func (Stats) TableName() string

type Token

type Token struct {
	ID        uint   `gorm:"primarykey"`
	Code      string `gorm:"type:varchar(512)"`
	Access    string `gorm:"type:varchar(512)"`
	Refresh   string `gorm:"type:varchar(512)"`
	Data      string `gorm:"type:text"`
	ExpiredAt int64
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (Token) TableName

func (Token) TableName() string

type User

type User struct {
	Username     string    `json:"username" gorm:"primarykey"`
	PasswordHash string    `json:"-" gorm:"password_hash"`
	Password     string    `json:"password,omitempty" gorm:"-"` // Only used to display generated password after creation
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

func (User) TableName

func (User) TableName() string

Jump to

Keyboard shortcuts

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