Documentation
¶
Index ¶
- func DeleteFunctionCode(functionsDir, functionName string) error
- func FunctionExists(functionsDir, functionName string) (bool, error)
- func LoadFunctionCode(functionsDir, functionName string) (string, error)
- func SaveFunctionCode(functionsDir, functionName, code string) error
- func ValidateFunctionCode(code string) error
- func ValidateFunctionName(name string) error
- func ValidateFunctionPath(functionsDir, functionName string) (string, error)
- type DenoRuntime
- type EdgeFunction
- type EdgeFunctionExecution
- type ExecutionRequest
- type ExecutionResult
- type FunctionConfig
- type FunctionFileInfo
- type Handler
- func (h *Handler) CreateFunction(c *fiber.Ctx) error
- func (h *Handler) DeleteFunction(c *fiber.Ctx) error
- func (h *Handler) GetExecutions(c *fiber.Ctx) error
- func (h *Handler) GetFunction(c *fiber.Ctx) error
- func (h *Handler) InvokeFunction(c *fiber.Ctx) error
- func (h *Handler) ListFunctions(c *fiber.Ctx) error
- func (h *Handler) RegisterAdminRoutes(app *fiber.App)
- func (h *Handler) RegisterRoutes(app *fiber.App, authService *auth.Service, apiKeyService *auth.APIKeyService, ...)
- func (h *Handler) ReloadFunctions(c *fiber.Ctx) error
- func (h *Handler) SetScheduler(scheduler *Scheduler)
- func (h *Handler) UpdateFunction(c *fiber.Ctx) error
- type Permissions
- type Scheduler
- func (s *Scheduler) GetScheduleInfo(functionName string) (string, bool)
- func (s *Scheduler) GetScheduledFunctions() []string
- func (s *Scheduler) RescheduleFunction(fn EdgeFunction) error
- func (s *Scheduler) ScheduleFunction(fn EdgeFunction) error
- func (s *Scheduler) Start() error
- func (s *Scheduler) Stop()
- func (s *Scheduler) UnscheduleFunction(functionName string)
- type Storage
- func (s *Storage) CreateFunction(ctx context.Context, fn *EdgeFunction) error
- func (s *Storage) DeleteFunction(ctx context.Context, name string) error
- func (s *Storage) GetExecutions(ctx context.Context, functionName string, limit int) ([]EdgeFunctionExecution, error)
- func (s *Storage) GetFunction(ctx context.Context, name string) (*EdgeFunction, error)
- func (s *Storage) ListFunctions(ctx context.Context) ([]EdgeFunction, error)
- func (s *Storage) LogExecution(ctx context.Context, exec *EdgeFunctionExecution) error
- func (s *Storage) UpdateFunction(ctx context.Context, name string, updates map[string]interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteFunctionCode ¶
DeleteFunctionCode removes a function file from the filesystem
func FunctionExists ¶
FunctionExists checks if a function file exists in the filesystem
func LoadFunctionCode ¶
LoadFunctionCode loads function code from the filesystem
func SaveFunctionCode ¶
SaveFunctionCode saves function code to the filesystem
func ValidateFunctionCode ¶
ValidateFunctionCode performs basic validation on function code
func ValidateFunctionName ¶
ValidateFunctionName validates that a function name is safe and meets requirements
func ValidateFunctionPath ¶
ValidateFunctionPath validates that a constructed function path is safe This provides defense-in-depth by ensuring the final path is within the functions directory
Types ¶
type DenoRuntime ¶
type DenoRuntime struct {
// contains filtered or unexported fields
}
DenoRuntime manages execution of Deno-based edge functions
func NewDenoRuntime ¶
func NewDenoRuntime() *DenoRuntime
NewDenoRuntime creates a new Deno runtime manager
func (*DenoRuntime) Execute ¶
func (r *DenoRuntime) Execute(ctx context.Context, code string, req ExecutionRequest, permissions Permissions) (*ExecutionResult, error)
Execute runs a Deno function with the given code and request context
type EdgeFunction ¶
type EdgeFunction struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description *string `json:"description"`
Code string `json:"code"`
Version int `json:"version"`
CronSchedule *string `json:"cron_schedule"`
Enabled bool `json:"enabled"`
TimeoutSeconds int `json:"timeout_seconds"`
MemoryLimitMB int `json:"memory_limit_mb"`
AllowNet bool `json:"allow_net"`
AllowEnv bool `json:"allow_env"`
AllowRead bool `json:"allow_read"`
AllowWrite bool `json:"allow_write"`
AllowUnauthenticated bool `json:"allow_unauthenticated"` // NEW: Allow invocation without authentication
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy *uuid.UUID `json:"created_by"`
}
EdgeFunction represents a stored edge function
type EdgeFunctionExecution ¶
type EdgeFunctionExecution struct {
ID uuid.UUID `json:"id"`
FunctionID uuid.UUID `json:"function_id"`
TriggerType string `json:"trigger_type"`
TriggerPayload *string `json:"trigger_payload"`
Status string `json:"status"`
StatusCode *int `json:"status_code"`
DurationMs *int `json:"duration_ms"`
Result *string `json:"result"`
Logs *string `json:"logs"`
ErrorMessage *string `json:"error_message"`
ErrorStack *string `json:"error_stack"`
ExecutedAt time.Time `json:"executed_at"`
CompletedAt *time.Time `json:"completed_at"`
}
EdgeFunctionExecution represents a function execution log
type ExecutionRequest ¶
type ExecutionRequest struct {
Method string `json:"method"`
URL string `json:"url"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
UserID string `json:"user_id,omitempty"`
}
ExecutionRequest represents a function invocation request
type ExecutionResult ¶
type ExecutionResult struct {
Status int `json:"status"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
Logs string `json:"logs"`
Error string `json:"error,omitempty"`
DurationMs int64 `json:"duration_ms"`
}
ExecutionResult represents the output of a function execution
type FunctionConfig ¶
type FunctionConfig struct {
AllowUnauthenticated bool
}
FunctionConfig contains configuration parsed from function code comments
func ParseFunctionConfig ¶
func ParseFunctionConfig(code string) FunctionConfig
ParseFunctionConfig parses special @fluxbase directives from function code comments Supported directives:
- // @fluxbase:allow-unauthenticated - Allows function invocation without authentication
type FunctionFileInfo ¶
type FunctionFileInfo struct {
Name string // Function name (without .ts extension)
Path string // Full path to the file
Size int64 // File size in bytes
ModifiedTime int64 // Unix timestamp of last modification
}
FunctionFileInfo contains information about a function file
func ListFunctionFiles ¶
func ListFunctionFiles(functionsDir string) ([]FunctionFileInfo, error)
ListFunctionFiles scans the functions directory and returns all function files
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages HTTP endpoints for edge functions
func NewHandler ¶
NewHandler creates a new edge functions handler
func (*Handler) CreateFunction ¶
CreateFunction creates a new edge function
func (*Handler) DeleteFunction ¶
DeleteFunction deletes a function
func (*Handler) GetExecutions ¶
GetExecutions returns execution history
func (*Handler) GetFunction ¶
GetFunction gets a single function by name
func (*Handler) InvokeFunction ¶
InvokeFunction invokes an edge function
func (*Handler) ListFunctions ¶
ListFunctions lists all edge functions
func (*Handler) RegisterAdminRoutes ¶
RegisterAdminRoutes registers admin-only routes for functions management These routes should be called with UnifiedAuthMiddleware and RequireRole("admin", "dashboard_admin")
func (*Handler) RegisterRoutes ¶
func (h *Handler) RegisterRoutes(app *fiber.App, authService *auth.Service, apiKeyService *auth.APIKeyService, db *pgxpool.Pool, jwtManager *auth.JWTManager)
RegisterRoutes registers all edge function routes with authentication
func (*Handler) ReloadFunctions ¶
ReloadFunctions scans the functions directory and syncs with database Admin-only endpoint - requires authentication and admin role
func (*Handler) SetScheduler ¶
SetScheduler sets the scheduler for this handler
type Permissions ¶
Permissions represents Deno security permissions
func DefaultPermissions ¶
func DefaultPermissions() Permissions
DefaultPermissions returns safe default permissions
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages scheduled execution of edge functions via cron
func NewScheduler ¶
NewScheduler creates a new scheduler for edge functions
func (*Scheduler) GetScheduleInfo ¶
GetScheduleInfo returns schedule information for a function
func (*Scheduler) GetScheduledFunctions ¶
GetScheduledFunctions returns a list of all currently scheduled functions
func (*Scheduler) RescheduleFunction ¶
func (s *Scheduler) RescheduleFunction(fn EdgeFunction) error
RescheduleFunction updates a function's schedule (helper method)
func (*Scheduler) ScheduleFunction ¶
func (s *Scheduler) ScheduleFunction(fn EdgeFunction) error
ScheduleFunction adds or updates a function's cron schedule
func (*Scheduler) UnscheduleFunction ¶
UnscheduleFunction removes a function's cron schedule
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage manages edge function persistence
func NewStorage ¶
NewStorage creates a new storage manager
func (*Storage) CreateFunction ¶
func (s *Storage) CreateFunction(ctx context.Context, fn *EdgeFunction) error
CreateFunction creates a new edge function
func (*Storage) DeleteFunction ¶
DeleteFunction deletes a function by name
func (*Storage) GetExecutions ¶
func (s *Storage) GetExecutions(ctx context.Context, functionName string, limit int) ([]EdgeFunctionExecution, error)
GetExecutions returns execution history for a function
func (*Storage) GetFunction ¶
GetFunction retrieves a function by name
func (*Storage) ListFunctions ¶
func (s *Storage) ListFunctions(ctx context.Context) ([]EdgeFunction, error)
ListFunctions returns all functions
func (*Storage) LogExecution ¶
func (s *Storage) LogExecution(ctx context.Context, exec *EdgeFunctionExecution) error
LogExecution logs a function execution