models

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GrantTypeClientCredentials = "client_credentials"
	GrantTypeAuthorizationCode = "authorization_code"
	GrantTypeRefreshToken      = "refresh_token"
	CredentialTypeOAuth        = "oauth"
	CredentialTypeText         = "text"
)
View Source
const AdminRole = "admin"

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	ID           int64          `json:"id" db:"id"`
	Name         string         `json:"name" db:"name"`
	Description  string         `json:"description" db:"description"`
	Active       bool           `json:"active" db:"active"`
	EnvVariables sql.NullString `json:"envVariables" db:"env_variables"`
	CreatedAt    time.Time      `json:"createdAt" db:"created_at"`
}

func (*Block) GetEnvVars

func (w *Block) GetEnvVars() map[string]string

type Credential

type Credential struct {
	ID            int64          `db:"id"`
	Type          string         `db:"type"`
	Name          string         `db:"name"`
	OauthUrl      sql.NullString `db:"oauth_url"`
	OauthTokenUrl sql.NullString `db:"oauth_token_url"`
	GrantType     string         `db:"grant_type"`
	Scope         sql.NullString `db:"scope"`
	Value         sql.NullString `db:"value"`
	ClientID      sql.NullString `db:"client_id"`
	ClientSecret  sql.NullString `db:"client_secret"`
	Token         sql.NullString `db:"token"`
	RefreshToken  sql.NullString `db:"refresh_token"`
	Expiry        sql.NullString `db:"expiry"`
	UpdatedAt     time.Time      `db:"updated_at"`
}

type CredentialFormData

type CredentialFormData struct {
	Name         string `form:"name"`
	Type         string `form:"type"`
	Value        string `form:"value"`
	OauthUrl     string `form:"oauth_url"`
	TokenUrl     string `form:"token_url"`
	Scope        string `form:"scope"`
	ClientID     string `form:"client_id"`
	ClientSecret string `form:"client_secret"`
	Token        string `form:"token"`
	RefreshToken string `form:"refresh_token"`
	Expiry       string `form:"expiry"`
}

type DueTasksTaskDetail

type DueTasksTaskDetail struct {
	PeriodicTaskDetail
	Block Block `json:"block" db:"block"`
}

type Event

type Event struct {
	ID             int            `json:"id" db:"id"`
	Status         string         `json:"status" db:"status"`
	CreatedAt      time.Time      `json:"created_at" db:"created_at"`
	EventType      string         `json:"event_type" db:"event_type"`
	Args           sql.NullString `json:"args" db:"args"`
	Logs           sql.NullString `json:"logs" db:"logs"`
	WebhookID      sql.NullInt64  `json:"webhook_id" db:"webhook_id"`
	PeriodicTaskID sql.NullInt64  `json:"periodic_task_id" db:"periodic_task_id"`
	BlockID        int64          `json:"block_id" db:"block_id"`
}

type File

type File struct {
	ID        int64     `json:"id" db:"id"`
	ProgramID int       `json:"programId" db:"program_id"`
	CreatedAt time.Time `json:"createdAt" db:"created_at"`
	Filename  string    `json:"filename" db:"filename"`
	Content   string    `json:"content" db:"content"`
}

type JSONRawString

type JSONRawString map[string]any

Custom type to handle JSON unmarshalling

func (*JSONRawString) Scan

func (j *JSONRawString) Scan(value interface{}) error

Implement the sql.Scanner interface for JSONRawString

func (JSONRawString) Value

func (j JSONRawString) Value() (driver.Value, error)

Implement the driver.Valuer interface for JSONRawString

type Page

type Page struct {
	ID          int64          `json:"id" db:"id"`
	Path        string         `json:"path" db:"path"`
	Name        sql.NullString `json:"name" db:"name"`
	Description sql.NullString `json:"description" db:"description"`
	Active      bool           `json:"active" db:"active"`
	Protected   bool           `json:"protected" db:"protected"`
	BlockID     int            `json:"blockId" db:"block_id"`
	CanvasState JSONRawString  `json:"canvas_state" db:"canvas_state"`
	HTMLOutput  sql.NullString `json:"htmlOutput" db:"html_output"`
	CreatedAt   time.Time      `json:"createdAt" db:"created_at"`
	UpdatedAt   time.Time      `json:"updatedAt" db:"updated_at"`
}

type PageData

type PageData struct {
	Path        string         `json:"path"`
	Title       string         `json:"title"`
	Description string         `json:"description"`
	Active      bool           `json:"active"`
	Protected   bool           `json:"protected"`
	Metadata    map[string]any `json:"metadata"`
	CanvasItems any            `json:"canvasItems"`
	HtmlOutput  any            `json:"htmlOutput"`
}

type PageWithMeta

type PageWithMeta struct {
	Page
	WebhookPathsRaw string   `db:"paths"` // raw comma-separated string
	WebhookPaths    []string `db:"-"`
}

type PeriodicTask

type PeriodicTask struct {
	ID               int64          `json:"id" db:"id"`
	Name             sql.NullString `json:"name" db:"name"`
	Description      sql.NullString `json:"description" db:"description"`
	Active           bool           `json:"active" db:"active"`
	EnvVariables     sql.NullString `json:"envVariables" db:"env_variables"`
	BlockID          int64          `json:"blockId" db:"block_id"`
	ProgramID        int64          `json:"programId" db:"program_id"`
	Timezone         string         `json:"timezone" db:"timezone"`
	Cron             string         `json:"cron" db:"cron"`
	NextRunAt        time.Time      `json:"nextRunAt" db:"next_run_at"`
	OnFailScript     sql.NullString `json:"onFailScript" db:"on_fail_script"`
	OnFailScriptType sql.NullString `json:"onFailScriptType" db:"on_fail_script_type"`
	OnFailEnabled    bool           `json:"onFailEnabled" db:"on_fail_enabled"`
	CreatedAt        time.Time      `json:"createdAt" db:"created_at"`
	UpdatedAt        time.Time      `json:"updatedAt" db:"updated_at"`
}

func (*PeriodicTask) GetEnvVars

func (w *PeriodicTask) GetEnvVars() map[string]string

type PeriodicTaskDetail

type PeriodicTaskDetail struct {
	PeriodicTask PeriodicTask `json:"periodicTask" db:"periodic_task"`
	Program      Program      `json:"program" db:"program"`
	File         File         `json:"file" db:"file"`
	Block        Block        `json:"block" db:"block"`
}

db tag is needed for matching in same cases

type PeriodicTaskFormData

type PeriodicTaskFormData struct {
	Name             string `form:"name"`
	Description      string `form:"description"`
	Env              string `form:"env"`
	Active           bool   `form:"active" `
	FileContent      string `form:"editor" `
	Cron             string `form:"cron" validate:"cron"`
	Code             string `form:"editor"`
	ProgramType      string `form:"programType"`
	OnFailScript     string `form:"onFailScript"`
	OnFailScriptType string `form:"onFailScriptType"`
	OnFailEnabled    bool   `form:"onFailEnabled"`
}

type Program

type Program struct {
	ID          int64     `json:"id" db:"id"`
	Name        string    `json:"name" db:"name"`
	ProgramType string    `json:"programType" db:"type"`
	CreatedAt   time.Time `json:"createdAt" db:"created_at"`
}

type Setting

type Setting struct {
	ID    int    `json:"id" db:"id"`
	Name  string `json:"name" db:"name"`
	Value string `json:"value" db:"value"`
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewModel

func NewModel(db *database.DbCon) *Store

func (*Store) CreateAdminUserIfNoUserExists

func (s *Store) CreateAdminUserIfNoUserExists() (*User, error)

func (*Store) DeleteBlockById

func (s *Store) DeleteBlockById(id int64) error

func (*Store) DeleteCredential

func (s *Store) DeleteCredential(id int64) error

func (*Store) DeletePageById

func (s *Store) DeletePageById(id int64) error

func (*Store) DeletePeriodicTaskById

func (s *Store) DeletePeriodicTaskById(id int64) error

func (*Store) DeleteUser

func (s *Store) DeleteUser(userID int64) error

func (*Store) DeleteWebhookById

func (s *Store) DeleteWebhookById(id int64) error

func (*Store) FetchCredentialByID

func (s *Store) FetchCredentialByID(id int64) (*Credential, error)

func (*Store) FetchCredentialByName

func (s *Store) FetchCredentialByName(name string) (*Credential, error)

func (*Store) FetchEventByBlockID

func (s *Store) FetchEventByBlockID(blockID int64, limit int, page int) (*[]Event, error)

func (*Store) FetchEventByID

func (s *Store) FetchEventByID(id int64) (*Event, error)

func (*Store) FetchEventByTypeAndID

func (s *Store) FetchEventByTypeAndID(eventType string, id int64, idColumn string, limit int, page int) (*[]Event, error)

func (*Store) FetchEvents

func (s *Store) FetchEvents(eventType string, id int64, idColumn string, limit int, page int) (*[]Event, error)

func (*Store) GetAndLockDuePeriodicTasks

func (s *Store) GetAndLockDuePeriodicTasks() ([]DueTasksTaskDetail, error)

func (*Store) GetConfigByKey

func (s *Store) GetConfigByKey(key string) (string, error)

func (*Store) GetUserByID

func (s *Store) GetUserByID(id int64) (*User, error)

func (*Store) GetUserByUsername

func (s *Store) GetUserByUsername(username string) (*User, error)

func (*Store) InsertBlock

func (s *Store) InsertBlock(block Block) (sql.Result, error)

func (*Store) InsertBlockWithAutoName

func (s *Store) InsertBlockWithAutoName(description string, active bool) (int64, error)

InsertBlockWithAutoName inserts a new block with an auto-generated name based on the max id in the blocks table.

func (*Store) InsertCredential

func (s *Store) InsertCredential(credential *Credential) error

func (*Store) InsertEvent

func (s *Store) InsertEvent(event Event) (sql.Result, error)

func (*Store) InsertPageWithAutoName

func (s *Store) InsertPageWithAutoName(blockID int64) (int64, error)

func (*Store) InsertPeriodicTaskWithAutoName

func (s *Store) InsertPeriodicTaskWithAutoName(blockID int64) (int64, error)

func (*Store) InsertSetting

func (s *Store) InsertSetting(key, value string)

func (*Store) InsertUser

func (s *Store) InsertUser(user *User) error

func (*Store) InsertUserOLD

func (s *Store) InsertUserOLD(user *User) error

func (*Store) InsertWebhookWithAutoName

func (s *Store) InsertWebhookWithAutoName(blockID int64) (int64, error)

func (*Store) ListBlocks

func (s *Store) ListBlocks() ([]Block, error)

func (*Store) ListCredentials

func (s *Store) ListCredentials() (*[]Credential, error)

func (*Store) ListCredentialsForEnv

func (s *Store) ListCredentialsForEnv() (map[string]string, error)

func (*Store) ListExpiredCredentials

func (s *Store) ListExpiredCredentials() ([]Credential, error)

func (*Store) ListPagesByBlockID

func (s *Store) ListPagesByBlockID(blockID int64) ([]Page, error)

ListPagesByBlockID retrieves pages associated with a given block ID.

func (*Store) ListPeriodicTasksByBlockID

func (s *Store) ListPeriodicTasksByBlockID(blockID int64) ([]PeriodicTask, error)

ListPeriodicTasksByBlockID retrieves periodic runs associated with a given block ID.

func (*Store) ListUsers

func (s *Store) ListUsers() ([]User, error)

func (*Store) ListWebhooksByBlockID

func (s *Store) ListWebhooksByBlockID(blockID int64) ([]Webhook, error)

func (*Store) RecordTaskFailure

func (s *Store) RecordTaskFailure(id int64) error

func (*Store) RecordTaskSuccess

func (s *Store) RecordTaskSuccess(id int64) error

func (*Store) RefreshTokens

func (s *Store) RefreshTokens() error

func (*Store) RemoveEventsOlderThanAWeek

func (s *Store) RemoveEventsOlderThanAWeek() (sql.Result, error)

func (*Store) SaveToken

func (s *Store) SaveToken(id int64, token *oauth2.Token) error

func (*Store) SearchBlocks

func (s *Store) SearchBlocks(query string) ([]Block, error)

func (*Store) SearchCredentials

func (s *Store) SearchCredentials(query string) ([]Credential, error)

func (*Store) SearchPages

func (s *Store) SearchPages(blockID int64, query string) ([]Page, error)

func (*Store) SearchPeriodicTasks

func (s *Store) SearchPeriodicTasks(blockID int64, query string) ([]PeriodicTask, error)

func (*Store) SearchUsers

func (s *Store) SearchUsers(query string) ([]User, error)

func (*Store) SearchWebhooks

func (s *Store) SearchWebhooks(blockID int64, query string) ([]Webhook, error)

func (*Store) SelectBlockById

func (s *Store) SelectBlockById(id int64) (*Block, error)

func (*Store) SelectPageById

func (s *Store) SelectPageById(id int64) (*PageWithMeta, error)

func (*Store) SelectPageByPath

func (s *Store) SelectPageByPath(path string) (*Page, error)

func (*Store) SelectPeriodicTaskDetailsById

func (s *Store) SelectPeriodicTaskDetailsById(id int64) (*PeriodicTaskDetail, error)

func (*Store) SelectWebhookById

func (s *Store) SelectWebhookById(id int64) (*Webhook, error)

func (*Store) SelectWebhookByPath

func (s *Store) SelectWebhookByPath(path string, verb string) (*WebHookDetail, error)

func (*Store) SelectWebhookDetailsById

func (s *Store) SelectWebhookDetailsById(id int64) (*WebhookDetail, error)

func (*Store) UnlockPeriodicTask

func (s *Store) UnlockPeriodicTask(id int64) error

func (*Store) UnlockStalePeriodicTasks

func (s *Store) UnlockStalePeriodicTasks() error

func (*Store) UpdateBlock

func (s *Store) UpdateBlock(id int64, block Block) error

func (*Store) UpdateConfigByKey

func (s *Store) UpdateConfigByKey(key, value string)

func (*Store) UpdateCredential

func (s *Store) UpdateCredential(credential *Credential) error

func (*Store) UpdateFileContentByWebhookID

func (s *Store) UpdateFileContentByWebhookID(webhookID int64, formData WebhookFormData) error

func (*Store) UpdateName

func (s *Store) UpdateName(table string, id int64, newName string) (string, error)

make it shorter

func (*Store) UpdatePageByID

func (s *Store) UpdatePageByID(id int64, pageData PageData) error

func (*Store) UpdatePeriodicTaskByFrom

func (s *Store) UpdatePeriodicTaskByFrom(periodicTaskID int64, formData PeriodicTaskFormData) error

func (*Store) UpdatePeriodicTaskNextRunAt

func (s *Store) UpdatePeriodicTaskNextRunAt(id int64, nextRunAt time.Time) error

func (*Store) UpdateUser

func (s *Store) UpdateUser(user *User) error

func (*Store) UpdateWebhookPath

func (s *Store) UpdateWebhookPath(id int64, newPath string) (string, error)

func (*Store) UserExists

func (s *Store) UserExists() (bool, error)

func (*Store) VerifyPassword

func (s *Store) VerifyPassword(storedHash string, password string) bool

type User

type User struct {
	ID           int64          `json:"id" db:"id"`
	Username     string         `json:"username" db:"username"`
	PasswordHash string         `json:"passwordHash" db:"password_hash"`
	Email        sql.NullString `json:"email" db:"email"`
	Settings     sql.NullString `json:"settings" db:"settings"`
	Role         string         `json:"role" db:"role"`
	CreatedAt    time.Time      `json:"createdAt" db:"created_at"`
	UpdatedAt    time.Time      `json:"updatedAt" db:"updated_at"`
}

type WebHookDetail

type WebHookDetail struct {
	Webhook Webhook `json:"webhook" db:"webhook"`
	File    File    `json:"file" db:"file"`
	Block   Block   `json:"block" db:"block"`
	Program Program `json:"program" db:"program"`
}

type Webhook

type Webhook struct {
	ID               int64          `json:"id" db:"id"`
	Name             sql.NullString `json:"name" db:"name"`
	Description      sql.NullString `json:"description" db:"description"`
	Active           bool           `json:"active" db:"active"`
	EnvVariables     sql.NullString `json:"envVariables" db:"env_variables"`
	BlockID          int            `json:"blockId" db:"block_id"`
	Path             string         `json:"path" db:"path"`
	FullPath         string         `json:"fullPath" db:"-"`
	Cors             sql.NullString `json:"cors" db:"cors"`
	HttpMethod       string         `json:"httpMethod" db:"http_method"`
	ResponseHeaders  sql.NullString `json:"responseHeaders" db:"response_headers"`
	ExitHttpPair     sql.NullString `json:"exitHttpPair" db:"exit_http_pair"`
	AuthConfig       sql.NullString `json:"authConfig" db:"auth_config"`
	OnFailScript     sql.NullString `json:"onFailScript" db:"on_fail_script"`
	OnFailScriptType sql.NullString `json:"onFailScriptType" db:"on_fail_script_type"`
	OnFailEnabled    bool           `json:"onFailEnabled" db:"on_fail_enabled"`
	CreatedAt        time.Time      `json:"createdAt" db:"created_at"`
	ProgramID        int            `json:"programId" db:"program_id"`
}

func (*Webhook) GetAuthConfig

func (w *Webhook) GetAuthConfig() *WebhookAuthConfig

func (*Webhook) GetCors

func (w *Webhook) GetCors() []string

func (*Webhook) GetEnvVars

func (w *Webhook) GetEnvVars() map[string]string

func (*Webhook) GetExitHttpPair

func (w *Webhook) GetExitHttpPair() map[int]int

func (*Webhook) GetResponseHeaders

func (w *Webhook) GetResponseHeaders() map[string]string

type WebhookAuthConfig

type WebhookAuthConfig struct {
	Enabled bool     `json:"enabled"`
	Tokens  []string `json:"tokens"`
}

type WebhookDetail

type WebhookDetail struct {
	Webhook Webhook `json:"webhook"`
	Block   Block   `json:"block"`
	Program Program `json:"program"`
	File    File    `json:"file"`
}

type WebhookFormData

type WebhookFormData struct {
	ExitCodes         []string `form:"exitCode[]" binding:"dive"`
	HTTPResponseCodes []string `form:"httpResponseCode[]" binding:"dive"`
	ResponseHeaders   string   `form:"responseHeaders"`
	Name              string   `form:"name"`
	ProgramType       string   `form:"programType"`
	Description       string   `form:"description"`
	Env               string   `form:"env"`
	Active            bool     `form:"active" `
	FileContent       string   `form:"editor" `
	HttpVerb          string   `form:"httpVerb" `
	Cors              string   `form:"cors" `
	Code              string   `form:"editor"`
	AuthConfig        string   `form:"authConfig"`
	OnFailScript      string   `form:"onFailScript"`
	OnFailScriptType  string   `form:"onFailScriptType"`
	OnFailEnabled     bool     `form:"onFailEnabled"`
}

Jump to

Keyboard shortcuts

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