Documentation
¶
Index ¶
- Variables
- func GetCapabilities(role string) []string
- type AuditLog
- type BindMount
- type Config
- type ConfigSchemaField
- type ContainerSpec
- type DiskMount
- type EventSubscription
- type ExtraPortSpec
- type JSONRawString
- type JSONStringList
- type ManagedContainer
- func (mc *ManagedContainer) GetCmd() []string
- func (mc *ManagedContainer) GetDiskMounts() []DiskMount
- func (mc *ManagedContainer) GetEnv() map[string]string
- func (mc *ManagedContainer) SetCmd(cmd []string)
- func (mc *ManagedContainer) SetDiskMounts(mounts []DiskMount)
- func (mc *ManagedContainer) SetEnv(env map[string]string)
- type Plugin
- func (p *Plugin) APIContainerName() string
- func (p *Plugin) ClearCandidate()
- func (p *Plugin) GetCapabilities() []string
- func (p *Plugin) GetConfigSchema() (map[string]ConfigSchemaField, error)
- func (p *Plugin) GetContainerIDs() map[string]string
- func (p *Plugin) GetContainers() []ContainerSpec
- func (p *Plugin) GetDependencies() []string
- func (p *Plugin) GetDockerLabels() map[string]string
- func (p *Plugin) GetEffectiveContainers() []ContainerSpec
- func (p *Plugin) GetExtraPorts() []ExtraPortSpec
- func (p *Plugin) GetRequestedScopes() []string
- func (p *Plugin) GetSharedDisks() []SharedDiskEntry
- func (p *Plugin) GetWorkspaceSchema() *WorkspaceSchemaData
- func (p *Plugin) HasCandidate() bool
- func (p *Plugin) IsMetadataOnly() bool
- func (p *Plugin) SetCapabilities(caps []string)
- func (p *Plugin) SetConfigSchema(schema map[string]ConfigSchemaField) error
- func (p *Plugin) SetContainerIDs(ids map[string]string)
- func (p *Plugin) SetContainers(specs []ContainerSpec)
- func (p *Plugin) SetDependencies(deps []string)
- func (p *Plugin) SetDockerLabels(labels map[string]string)
- func (p *Plugin) SetExtraPorts(ports []ExtraPortSpec)
- func (p *Plugin) SetRequestedScopes(scopes []string)
- func (p *Plugin) SetSharedDisks(disks []SharedDiskEntry)
- func (p *Plugin) SetWorkspaceSchema(ws *WorkspaceSchemaData) error
- type ServiceToken
- type SharedDiskEntry
- type User
- type VisibleWhen
- type WorkspaceSchemaData
Constants ¶
This section is empty.
Variables ¶
var RoleCapabilities = map[string][]string{
"admin": {
"users:read",
"users:write",
"plugins:manage",
"plugins:search",
"system:admin",
},
"user": {
"users:read:self",
"plugins:search",
},
}
RoleCapabilities maps roles to their granted capabilities.
Functions ¶
func GetCapabilities ¶
GetCapabilities returns the capability list for a given role.
Types ¶
type AuditLog ¶
type AuditLog struct {
ID uint `json:"id" gorm:"primaryKey"`
Timestamp time.Time `json:"timestamp" gorm:"autoCreateTime;index"`
ActorType string `json:"actor_type" gorm:"not null"` // "user", "service", "system"
ActorID string `json:"actor_id"` // user ID, service token name, or "kernel"
Action string `json:"action" gorm:"not null;index"` // "auth.login", "auth.register", "plugin.install", etc.
Resource string `json:"resource"` // What was acted on: "plugin:discord-bot", "user:5", etc.
Detail string `json:"detail"` // JSON blob with extra context
IP string `json:"ip"` // Client IP
Success bool `json:"success" gorm:"default:true"`
}
type BindMount ¶
type BindMount struct {
Host string `json:"host" yaml:"host"`
Container string `json:"container" yaml:"container"`
ReadOnly bool `json:"read_only,omitempty" yaml:"read_only,omitempty"`
}
BindMount describes a host-to-container bind mount used in dev mode.
type Config ¶
type Config struct {
ID uint `json:"id" gorm:"primaryKey"`
OwnerID string `json:"owner_id" gorm:"column:owner_id;not null;index;uniqueIndex:idx_owner_key"`
Key string `json:"key" gorm:"not null;uniqueIndex:idx_owner_key"`
Value string `json:"value" gorm:"not null"`
IsSecret bool `json:"is_secret" gorm:"default:false"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ConfigSchemaField ¶
type ConfigSchemaField struct {
Type string `json:"type"` // "string", "select", "number", "boolean", "text"
Label string `json:"label"` // Human-readable label
Required bool `json:"required,omitempty"` // Whether the field must be set
Secret bool `json:"secret,omitempty"` // Whether to mask the value in UI
ReadOnly bool `json:"readonly,omitempty"` // Display-only; cannot be changed by the user
Virtual bool `json:"virtual,omitempty"` // Pass-through only; value is never persisted
Default string `json:"default,omitempty"` // Default value
Options []string `json:"options,omitempty"` // For "select" type
Dynamic bool `json:"dynamic,omitempty"` // Fetch options at runtime from plugin
HelpText string `json:"help_text,omitempty"` // Tooltip/description
VisibleWhen *VisibleWhen `json:"visible_when,omitempty"` // Show only when another field matches a value
OAuthMethod string `json:"oauth_method,omitempty"` // OAuth flow variant: "device_code" or "redirect_code"
Order int `json:"order,omitempty"` // Display order (lower = first)
}
ConfigSchemaField describes a single configuration field for a plugin.
type ContainerSpec ¶
type ContainerSpec struct {
Name string `json:"name" yaml:"name"`
Image string `json:"image" yaml:"image"`
Role string `json:"role" yaml:"role"`
Ports []ExtraPortSpec `json:"ports,omitempty" yaml:"ports,omitempty"`
DockerLabels map[string]string `json:"docker_labels,omitempty" yaml:"docker_labels,omitempty"`
DevImage string `json:"dev_image,omitempty" yaml:"dev_image,omitempty"`
DevBindMounts []BindMount `json:"dev_bind_mounts,omitempty" yaml:"dev_bind_mounts,omitempty"`
}
ContainerSpec describes a single container in a multi-container plugin pod. Role must be one of "api" (exactly one per plugin) or "sidecar".
type DiskMount ¶
type DiskMount struct {
SourcePath string `json:"source_path"` // storage-disk internal path, e.g. "/data/storage-root/workspace/ws-abc"
Target string `json:"target"` // mount path inside the container
ReadOnly bool `json:"read_only,omitempty"`
}
DiskMount describes a pre-resolved storage mount for a managed container. The owning plugin resolves disk paths via storage-disk before passing them to the kernel — the kernel only translates to host-side bind mount paths.
type EventSubscription ¶
type EventSubscription struct {
ID uint `gorm:"primaryKey"`
PluginID string `gorm:"uniqueIndex:idx_sub_plugin_event;not null"`
EventType string `gorm:"uniqueIndex:idx_sub_plugin_event;not null"`
CallbackPath string `gorm:"not null"`
CreatedAt time.Time
}
EventSubscription persists a plugin's interest in a named event type.
type ExtraPortSpec ¶
type ExtraPortSpec struct {
Name string `json:"name,omitempty"`
Internal int `json:"internal"`
External int `json:"external,omitempty"`
}
ExtraPortSpec describes an additional container port the plugin wants opened. Internal is the port inside the container (required). External is the host port to publish to (0 = let Docker pick a host port). Name is a human-readable identifier (optional).
type JSONRawString ¶
type JSONRawString json.RawMessage
JSONRawString is a raw JSON value stored as text in the DB. It serializes as the parsed JSON object/array in API responses, not as an escaped string.
func (JSONRawString) MarshalJSON ¶
func (j JSONRawString) MarshalJSON() ([]byte, error)
MarshalJSON returns the raw JSON — no double-encoding.
func (*JSONRawString) Scan ¶
func (j *JSONRawString) Scan(value interface{}) error
Scan implements sql.Scanner — reads JSON text from the DB.
func (*JSONRawString) UnmarshalJSON ¶
func (j *JSONRawString) UnmarshalJSON(data []byte) error
UnmarshalJSON stores the raw JSON bytes.
type JSONStringList ¶
type JSONStringList []string
JSONStringList is a []string that GORM stores as a JSON text column but serializes as a proper JSON array in API responses.
func (JSONStringList) MarshalJSON ¶
func (j JSONStringList) MarshalJSON() ([]byte, error)
MarshalJSON serializes as a JSON array.
func (*JSONStringList) Scan ¶
func (j *JSONStringList) Scan(value interface{}) error
Scan implements sql.Scanner — reads JSON text from the DB.
func (*JSONStringList) UnmarshalJSON ¶
func (j *JSONStringList) UnmarshalJSON(data []byte) error
UnmarshalJSON accepts either a JSON array or a JSON string containing an array.
type ManagedContainer ¶
type ManagedContainer struct {
ID string `json:"id" gorm:"primaryKey"`
PluginID string `json:"plugin_id" gorm:"not null;index"`
Name string `json:"name" gorm:"not null"`
Image string `json:"image" gorm:"not null"`
ContainerID string `json:"-"`
Status string `json:"status" gorm:"not null;default:'stopped'"`
Port int `json:"port" gorm:"not null"`
Subdomain string `json:"subdomain" gorm:"uniqueIndex"`
DiskMounts string `json:"-" gorm:"type:text"` // JSON array of DiskMount
Env string `json:"-" gorm:"type:text"`
Cmd string `json:"-" gorm:"type:text"` // JSON array of command args
DockerUser string `json:"-" gorm:"column:docker_user"`
PluginSource string `json:"plugin_source,omitempty" gorm:"column:plugin_source"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
ManagedContainer represents a container launched by a plugin and tracked by the kernel. Unlike plugins, managed containers don't run the SDK — they are raw workload containers (code-server, terminals, etc.).
func (*ManagedContainer) GetCmd ¶
func (mc *ManagedContainer) GetCmd() []string
GetCmd parses the stored JSON cmd string into a slice.
func (*ManagedContainer) GetDiskMounts ¶
func (mc *ManagedContainer) GetDiskMounts() []DiskMount
GetDiskMounts parses the stored JSON disk mounts string.
func (*ManagedContainer) GetEnv ¶
func (mc *ManagedContainer) GetEnv() map[string]string
GetEnv parses the stored JSON env string into a map.
func (*ManagedContainer) SetCmd ¶
func (mc *ManagedContainer) SetCmd(cmd []string)
SetCmd serializes the cmd slice to JSON for storage.
func (*ManagedContainer) SetDiskMounts ¶
func (mc *ManagedContainer) SetDiskMounts(mounts []DiskMount)
SetDiskMounts serializes the disk mounts slice to JSON for storage.
func (*ManagedContainer) SetEnv ¶
func (mc *ManagedContainer) SetEnv(env map[string]string)
SetEnv serializes the env map to JSON for storage.
type Plugin ¶
type Plugin struct {
ID string `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"not null"`
Version string `json:"version" gorm:"not null"`
Image string `json:"image"`
ContainerID string `json:"-"`
// ContainerIDs is a JSON map of container_name → docker container ID for
// multi-container plugins. The api role container's ID is also mirrored
// into ContainerID for backward compat.
ContainerIDs JSONRawString `json:"-" gorm:"type:json"`
// DevMode toggles use of dev_image / dev_bind_mounts for each container spec.
DevMode bool `json:"dev_mode" gorm:"default:false"`
// Containers is an explicit JSON array of ContainerSpec for multi-container
// plugins (a "pod" of containers). When non-empty it takes precedence over
// the legacy top-level Image / DockerLabels / ExtraPorts fields. When empty,
// GetEffectiveContainers() synthesizes a single-container spec from those
// legacy fields so old single-container plugins keep working unchanged.
Containers JSONRawString `json:"containers,omitempty" gorm:"type:json"`
Status string `json:"status" gorm:"not null;default:'stopped'"`
Host string `json:"host"`
GRPCPort int `json:"grpc_port"`
HTTPPort int `json:"http_port"`
EventPort int `json:"event_port,omitempty"` // deprecated: events now go to HTTPPort via /events route
Capabilities JSONStringList `json:"capabilities" gorm:"type:json"`
Dependencies JSONStringList `json:"dependencies,omitempty" gorm:"type:json"` // required capability strings
Marketplace string `json:"marketplace" gorm:"default:'local'"`
Enabled bool `json:"enabled" gorm:"default:false"`
System bool `json:"system" gorm:"default:false"` // system plugins are auto-installed and cannot be uninstalled
LastSeen time.Time `json:"last_seen"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Candidate fields — a dev or new-build container running alongside the primary.
CandidateContainerID string `json:"-"`
CandidateImage string `json:"candidate_image,omitempty"`
CandidateVersion string `json:"candidate_version,omitempty"`
CandidateHost string `json:"candidate_host,omitempty"`
CandidatePort int `json:"candidate_port,omitempty"`
CandidateEventPort int `json:"-"`
CandidateHealthy bool `json:"candidate_healthy,omitempty"`
CandidateDeployedAt time.Time `json:"candidate_deployed_at,omitempty"`
CandidateLastSeen time.Time `json:"-"`
// Previous fields — stored on promote so rollback can restore.
PreviousImage string `json:"-"`
PreviousVersion string `json:"-"`
// WorkspaceSchema defines how to launch a workspace environment.
// Only present on plugins with the workspace:environment capability.
// Stored as JSON; see WorkspaceSchemaData for the typed structure.
WorkspaceSchema JSONRawString `json:"workspace_schema,omitempty" gorm:"type:json"`
// Each entry has a disk name and target mount path. The kernel auto-creates
// the disk directory and bind-mounts it into the plugin container.
SharedDisks JSONRawString `json:"shared_disks,omitempty" gorm:"type:json"`
// DockerLabels is a JSON map of label key/value pairs the plugin wants
// applied to its container. Values may reference ${ENV_VAR} which will be
// substituted from the kernel's process env at container-create time.
DockerLabels JSONRawString `json:"docker_labels,omitempty" gorm:"type:json"`
// ExtraPorts is a JSON array of additional ports the plugin wants opened
// on its container, beyond the kernel-managed REST API port. The kernel
// publishes them on the host but does not route or health-check them.
ExtraPorts JSONRawString `json:"extra_ports,omitempty" gorm:"type:json"`
// RequestedScopes is a JSON array of authorization scopes the plugin needs.
RequestedScopes JSONStringList `json:"requested_scopes,omitempty" gorm:"type:json"`
// ConfigSchema is a JSON string mapping env var names to ConfigSchemaField objects.
// Example:
// {
// "OPENAI_API_KEY": {"type":"string","label":"API Key","required":true,"secret":true},
// "OPENAI_MODEL": {"type":"select","label":"Model","default":"gpt-4o","options":["gpt-4o","gpt-4o-mini"]}
// }
// The kernel uses this schema to (a) present config UI and (b) inject default values
// as env vars when starting the plugin container.
ConfigSchema JSONRawString `json:"config_schema" gorm:"type:json"`
}
func (*Plugin) APIContainerName ¶
APIContainerName returns the name of the container with role: api in the effective container list, or "default" when nothing matches.
func (*Plugin) ClearCandidate ¶
func (p *Plugin) ClearCandidate()
ClearCandidate resets all candidate fields.
func (*Plugin) GetCapabilities ¶
GetCapabilities returns the capabilities as a string slice.
func (*Plugin) GetConfigSchema ¶
func (p *Plugin) GetConfigSchema() (map[string]ConfigSchemaField, error)
GetConfigSchema parses the ConfigSchema into a map of field name to ConfigSchemaField.
func (*Plugin) GetContainerIDs ¶
GetContainerIDs returns the container_name → container_id map for a multi-container plugin. Empty for legacy single-container plugins.
func (*Plugin) GetContainers ¶
func (p *Plugin) GetContainers() []ContainerSpec
GetContainers returns the explicit container specs (may be empty / nil).
func (*Plugin) GetDependencies ¶
GetDependencies returns the required capabilities as a string slice.
func (*Plugin) GetDockerLabels ¶
GetDockerLabels parses the stored JSON docker labels into a flat map.
func (*Plugin) GetEffectiveContainers ¶
func (p *Plugin) GetEffectiveContainers() []ContainerSpec
GetEffectiveContainers returns the container specs the runtime should iterate over. If explicit Containers are set, they win. Otherwise a single "default" api container is synthesized from the legacy top-level fields (Image / HTTPPort / DockerLabels / ExtraPorts) so single-container plugins keep working with no manifest changes.
func (*Plugin) GetExtraPorts ¶
func (p *Plugin) GetExtraPorts() []ExtraPortSpec
GetExtraPorts parses the stored JSON extra ports list.
func (*Plugin) GetRequestedScopes ¶
GetRequestedScopes returns the requested authorization scopes as a string slice.
func (*Plugin) GetSharedDisks ¶
func (p *Plugin) GetSharedDisks() []SharedDiskEntry
GetSharedDisks parses the stored JSON shared disks.
func (*Plugin) GetWorkspaceSchema ¶
func (p *Plugin) GetWorkspaceSchema() *WorkspaceSchemaData
GetWorkspaceSchema parses the stored JSON into a typed struct.
func (*Plugin) HasCandidate ¶
HasCandidate returns true when a candidate container is deployed.
func (*Plugin) IsMetadataOnly ¶
IsMetadataOnly returns true when the plugin has no runtime image and should not be started as a container. Such plugins exist purely as discoverable metadata (e.g. workspace environment definitions).
func (*Plugin) SetCapabilities ¶
SetCapabilities stores a string slice as capabilities.
func (*Plugin) SetConfigSchema ¶
func (p *Plugin) SetConfigSchema(schema map[string]ConfigSchemaField) error
SetConfigSchema serializes a config schema map to JSON and stores it.
func (*Plugin) SetContainerIDs ¶
SetContainerIDs stores the container_name → container_id map.
func (*Plugin) SetContainers ¶
func (p *Plugin) SetContainers(specs []ContainerSpec)
SetContainers serializes container specs to JSON for storage.
func (*Plugin) SetDependencies ¶
SetDependencies stores required capability strings.
func (*Plugin) SetDockerLabels ¶
SetDockerLabels serializes a label map to JSON for storage.
func (*Plugin) SetExtraPorts ¶
func (p *Plugin) SetExtraPorts(ports []ExtraPortSpec)
SetExtraPorts serializes the extra ports list to JSON for storage.
func (*Plugin) SetRequestedScopes ¶
SetRequestedScopes stores requested authorization scopes.
func (*Plugin) SetSharedDisks ¶
func (p *Plugin) SetSharedDisks(disks []SharedDiskEntry)
SetSharedDisks serializes the shared disks to JSON for storage.
func (*Plugin) SetWorkspaceSchema ¶
func (p *Plugin) SetWorkspaceSchema(ws *WorkspaceSchemaData) error
SetWorkspaceSchema serializes the workspace schema to JSON and stores it.
type ServiceToken ¶
type ServiceToken struct {
ID uint `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"not null;uniqueIndex"`
TokenHash string `json:"-" gorm:"not null"` // SHA256 hash of the token (for revocation lookup)
Capabilities string `json:"capabilities"` // JSON array
IssuedBy uint `json:"issued_by"` // User ID of admin who created it
ExpiresAt time.Time `json:"expires_at"`
Revoked bool `json:"revoked" gorm:"default:false"`
CreatedAt time.Time `json:"created_at"`
}
type SharedDiskEntry ¶
type SharedDiskEntry struct {
}
SharedDiskEntry describes a disk mount for a plugin.
type User ¶
type User struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Email string `gorm:"uniqueIndex;not null" json:"email"`
PasswordHash string `gorm:"not null" json:"-"`
DisplayName string `json:"display_name"`
Role string `gorm:"default:user" json:"role"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type VisibleWhen ¶
VisibleWhen describes a condition under which a field should be visible.
type WorkspaceSchemaData ¶
type WorkspaceSchemaData struct {
DisplayName string `json:"display_name" yaml:"display_name"`
Description string `json:"description" yaml:"description"`
Image string `json:"image" yaml:"image"`
Port int `json:"port" yaml:"port"`
Cmd []string `json:"cmd,omitempty" yaml:"cmd,omitempty"`
EnvDefaults map[string]string `json:"env_defaults,omitempty" yaml:"env_defaults,omitempty"`
DockerUser string `json:"docker_user,omitempty" yaml:"docker_user,omitempty"`
}
WorkspaceSchemaData describes how to launch a workspace environment.