Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateTokenPreview(plainToken string) string
- type ActionType
- type AdminPermission
- type Agent
- type AgentList
- type DraftChangeType
- type Namespace
- type NamespaceList
- type Page
- type PageDraft
- type PageDraftList
- type PageList
- type Project
- type ProjectList
- type Redirect
- type RedirectDraft
- type RedirectDraftList
- type RedirectList
- type ResourcePermission
- type ResourceType
- type Role
- type RoleList
- type RoleType
- type SectionType
- type SubjectPermissions
- type Token
- type TokenList
- type User
- type UserList
- type UserRole
Constants ¶
View Source
const ( AdminSectionUsers SectionType = "users" AdminSectionRoles SectionType = "roles" AdminSectionProjects SectionType = "projects" AdminSectionNamespaces SectionType = "namespaces" AdminSectionTokens SectionType = "tokens" AdminSectionAll SectionType = "*" ActionRead ActionType = "read" ActionWrite ActionType = "write" ActionAll ActionType = "*" ResourceTypeRedirect ResourceType = "redirect" ResourceTypePage ResourceType = "page" ResourceTypeAgent ResourceType = "agent" ResourceTypeAll ResourceType = "*" ResourceTypeAny ResourceType = "any" )
View Source
const ( TokenPrefix = "flecto_" TokenNameMaxLength = 300 TokenPreviewChars = 4 // Number of characters to show at start and end of preview )
View Source
const (
ColumnNamespaceCode = "namespace_code"
)
View Source
const (
ColumnProjectCode = "project_code"
)
Variables ¶
View Source
var AgentSortableColumns = map[string]string{
"name": "name",
"status": "status",
"type": "type",
"createAt": "created_at",
"updatedAt": "updated_at",
"lastHitAt": "last_hit_at",
}
View Source
var NamespaceSortableColumns = map[string]string{ "id": "id", "namespace_code": ColumnNamespaceCode, "name": "name", "createdAt": "created_at", "updatedAt": "updated_at", }
View Source
var PageSortableColumns = map[string]string{
"path": "path",
"contentType": "content_type",
"type": "type",
"updatedAt": "updated_at",
}
View Source
var ProjectSortableColumns = map[string]string{ "id": "id", "namespace_code": ColumnNamespaceCode, "code": ColumnProjectCode, "name": "name", "createdAt": "created_at", "updatedAt": "updated_at", }
View Source
var RedirectSortableColumns = map[string]string{
"source": "source",
"target": "target",
"type": "type",
"status": "status",
"updatedAt": "updated_at",
}
View Source
var RoleSortableColumns = map[string]string{
"id": "id",
"code": "code",
"type": "type",
"createdAt": "created_at",
"updatedAt": "updated_at",
}
View Source
var TokenSortableColumns = map[string]string{
"id": "id",
"name": "name",
"createdAt": "created_at",
"updatedAt": "updated_at",
"expiresAt": "expires_at",
}
View Source
var UserSortableColumns = map[string]string{
"id": "id",
"username": "username",
"lastname": "lastname",
"firstname": "firstname",
"createdAt": "created_at",
"updatedAt": "updated_at",
}
View Source
var ValidRoleNameRegex = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
Functions ¶
func GenerateTokenPreview ¶
GenerateTokenPreview creates a preview string like "flecto_abcd...wxyz" from the full token
Types ¶
type ActionType ¶
type ActionType string
type AdminPermission ¶
type AdminPermission struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
Section SectionType `json:"section" gorm:"size:100;not null;index:idx_admin_perm_section"`
Action ActionType `json:"action" gorm:"size:50;not null"`
RoleID int64
Role Role `json:"role,omitempty"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
}
func (AdminPermission) TableName ¶
func (AdminPermission) TableName() string
type Agent ¶
type Agent struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
NamespaceCode string `json:"-" gorm:"size:50;index:idx_agents_namespace_project"`
ProjectCode string `json:"-" gorm:"size:50;index:idx_agents_namespace_project"`
Project *Project `json:"project" gorm:"foreignKey:NamespaceCode,ProjectCode;references:NamespaceCode,ProjectCode;"`
commonTypes.Agent
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
UpdatedAt time.Time `json:"updatedAt" gorm:"type:timestamp"`
LastHitAt time.Time `json:"lastHitAt" gorm:"type:timestamp"`
}
type AgentList ¶
type AgentList = commonTypes.PaginatedResult[Agent]
type DraftChangeType ¶
type DraftChangeType string
const ( DraftChangeTypeCreate DraftChangeType = "CREATE" DraftChangeTypeUpdate DraftChangeType = "UPDATE" DraftChangeTypeDelete DraftChangeType = "DELETE" DraftChangeTypePublished DraftChangeType = "PUBLISHED" )
type Namespace ¶
type Namespace struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
NamespaceCode string `json:"namespace_code" gorm:"size:50;uniqueIndex:idx_namespace_namespace_code;" validate:"required,code"`
Name string `json:"name" validate:"required"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
UpdatedAt time.Time `json:"updatedAt" gorm:"type:timestamp"`
}
type NamespaceList ¶
type NamespaceList = types.PaginatedResult[Namespace]
type Page ¶
type Page struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
NamespaceCode string `json:"-" gorm:"size:50;index:idx_pages_namespace_project"`
ProjectCode string `json:"-" gorm:"size:50;index:idx_pages_namespace_project"`
Project *Project `json:"project" gorm:"foreignKey:NamespaceCode,ProjectCode;references:NamespaceCode,ProjectCode;"`
IsPublished *bool `json:"is_published" gorm:"default:false;not null"`
PublishedAt time.Time `json:"publishedAt" gorm:"type:timestamp"`
ContentSize int64 `json:"contentSize" gorm:"default:0;not null"`
*commonTypes.Page
PageDraft *PageDraft `json:"draft" gorm:"foreignKey:OldPageID;references:ID"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
UpdatedAt time.Time `json:"updatedAt" gorm:"type:timestamp"`
}
type PageDraft ¶
type PageDraft struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
NamespaceCode string `json:"-" gorm:"size:50;index:idx_page_drafts_namespace_project"`
ProjectCode string `json:"-" gorm:"size:50;index:idx_page_drafts_namespace_project"`
Project *Project `json:"project" gorm:"foreignKey:NamespaceCode,ProjectCode;references:NamespaceCode,ProjectCode;"`
ChangeType DraftChangeType `json:"changeType" gorm:"size:50;" validate:"required"`
OldPageID *int64 `json:"-" gorm:"index:idx_page_drafts_old_page_id"`
OldPage *Page `json:"oldPage" gorm:"foreignKey:OldPageID;"`
ContentSize int64 `json:"contentSize" gorm:"default:0;not null"`
NewPage *commonTypes.Page `gorm:"embedded;embeddedPrefix:new_"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
UpdatedAt time.Time `json:"updatedAt" gorm:"type:timestamp"`
}
type PageDraftList ¶
type PageDraftList = commonTypes.PaginatedResult[PageDraft]
type PageList ¶
type PageList = commonTypes.PaginatedResult[Page]
type Project ¶
type Project struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
ProjectCode string `json:"code" gorm:"size:50;uniqueIndex:idx_project_namespace" validate:"required,code"`
NamespaceCode string `json:"-" gorm:"size:50;uniqueIndex:idx_project_namespace;index:idx_namespace"`
Namespace *Namespace `json:"namespace" gorm:"foreignKey:NamespaceCode;references:NamespaceCode;"`
Name string `json:"name" validate:"required"`
Version int `json:"version" gorm:"default:1"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
UpdatedAt time.Time `json:"UpdatedAt" gorm:"type:timestamp"`
PublishedAt time.Time `json:"publishedAt" gorm:"type:timestamp"`
}
type ProjectList ¶
type ProjectList = types.PaginatedResult[Project]
type Redirect ¶
type Redirect struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
NamespaceCode string `json:"-" gorm:"size:50;index:idx_redirects_namespace_project"`
ProjectCode string `json:"-" gorm:"size:50;index:idx_redirects_namespace_project"`
Project *Project `json:"project" gorm:"foreignKey:NamespaceCode,ProjectCode;references:NamespaceCode,ProjectCode;"`
IsPublished *bool `json:"is_published" gorm:"default:false;not null"`
PublishedAt time.Time `json:"publishedAt" gorm:"type:timestamp"`
*commonTypes.Redirect
RedirectDraft *RedirectDraft `json:"draft" gorm:"foreignKey:OldRedirectID;references:ID"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
UpdatedAt time.Time `json:"updatedAt" gorm:"type:timestamp"`
}
type RedirectDraft ¶
type RedirectDraft struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
NamespaceCode string `json:"-" gorm:"size:50;index:idx_redirect_drafts_namespace_project"`
ProjectCode string `json:"-" gorm:"size:50;index:idx_redirect_drafts_namespace_project"`
Project *Project `json:"project" gorm:"foreignKey:NamespaceCode,ProjectCode;references:NamespaceCode,ProjectCode;"`
ChangeType DraftChangeType `json:"changeType" gorm:"size:50;" validate:"required"`
OldRedirectID *int64 `json:"-" gorm:"index:idx_redirect_drafts_old_redirect_id"`
OldRedirect *Redirect `json:"oldRedirect" gorm:"foreignKey:OldRedirectID;"`
NewRedirect *commonTypes.Redirect `gorm:"embedded;embeddedPrefix:new_"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
UpdatedAt time.Time `json:"updatedAt" gorm:"type:timestamp"`
}
type RedirectDraftList ¶
type RedirectDraftList = commonTypes.PaginatedResult[RedirectDraft]
type RedirectList ¶
type RedirectList = commonTypes.PaginatedResult[Redirect]
type ResourcePermission ¶
type ResourcePermission struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
Namespace string `json:"namespace" gorm:"size:50;not null;index:idx_res_perm_namespace"`
Project string `json:"project" gorm:"size:50;index:idx_res_perm_project"`
Resource ResourceType `json:"resource" gorm:"size:50;not null"`
Action ActionType `json:"action" gorm:"size:50;not null"`
RoleID int64
Role Role `json:"role,omitempty"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
}
func (ResourcePermission) TableName ¶
func (ResourcePermission) TableName() string
type ResourceType ¶
type ResourceType string
type Role ¶
type Role struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
Code string `json:"code" gorm:"uniqueIndex:idx_role_code_type;size:100;not null" validate:"required,code"`
Type RoleType `json:"type" gorm:"uniqueIndex:idx_role_code_type;size:100;not null"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
UpdatedAt time.Time `json:"updatedAt" gorm:"type:timestamp"`
Users []User `json:"users,omitempty" gorm:"many2many:user_roles;"`
Resources []ResourcePermission `json:"resources,omitempty" gorm:"foreignKey:RoleID;constraint:OnDelete:CASCADE;"`
Admin []AdminPermission `json:"admin,omitempty" gorm:"foreignKey:RoleID;constraint:OnDelete:CASCADE;"`
}
type RoleList ¶
type RoleList = types.PaginatedResult[Role]
type SectionType ¶
type SectionType string
type SubjectPermissions ¶
type SubjectPermissions struct {
Resources []ResourcePermission `json:"resources,omitempty"`
Admin []AdminPermission `json:"admin,omitempty"`
}
func (*SubjectPermissions) Append ¶
func (s *SubjectPermissions) Append(permission *SubjectPermissions)
type Token ¶
type Token struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
Name string `json:"name" gorm:"uniqueIndex;size:300;not null" validate:"required,max=300"`
TokenHash string `json:"-" gorm:"uniqueIndex;size:64;not null"`
TokenPreview string `json:"tokenPreview" gorm:"size:30;not null"` // e.g., "flecto_abcd...wxyz"
ExpiresAt *time.Time `json:"expiresAt" gorm:"type:timestamp"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
UpdatedAt time.Time `json:"updatedAt" gorm:"type:timestamp"`
}
func (*Token) GetRoleCode ¶
GetRoleCode returns the role code for this token's personal role
type TokenList ¶
type TokenList = types.PaginatedResult[Token]
type User ¶
type User struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
Username string `json:"username" gorm:"unique;size:100;not null" validate:"required,username"`
Password string `json:"-" gorm:"size:255"`
Lastname string `json:"lastname" validate:"required"`
Firstname string `json:"firstname" validate:"required"`
Active *bool `json:"active" gorm:"default:true;not null"`
RefreshTokenHash string `json:"-" gorm:"size:255"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
UpdatedAt time.Time `json:"updatedAt" gorm:"type:timestamp"`
}
func (*User) HasPassword ¶
HasPassword returns true if the user can use basic auth
type UserList ¶
type UserList = types.PaginatedResult[User]
type UserRole ¶
type UserRole struct {
UserID int64 `json:"userId" gorm:"primaryKey"`
RoleID int64 `json:"roleId" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamp"`
User User `json:"user" gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;"`
Role Role `json:"role" gorm:"foreignKey:RoleID;constraint:OnDelete:CASCADE;"`
}
Click to show internal directories.
Click to hide internal directories.