Documentation
¶
Index ¶
- Variables
- type APIKey
- type Execution
- type SkillRecord
- type Store
- func (s *Store) Close() error
- func (s *Store) CreateExecution(ctx context.Context, e *Execution) (*Execution, error)
- func (s *Store) CreateKey(ctx context.Context, tenantID, name, keyHash string) (*APIKey, error)
- func (s *Store) DB() *sql.DB
- func (s *Store) DeleteSkill(ctx context.Context, tenantID, name, version string) error
- func (s *Store) GetAPIKeyByHash(ctx context.Context, hash string) (*APIKey, error)
- func (s *Store) GetExecution(ctx context.Context, id string) (*Execution, error)
- func (s *Store) GetSkill(ctx context.Context, tenantID, name, version string) (*SkillRecord, error)
- func (s *Store) InsertExecution(ctx context.Context, e *Execution) error
- func (s *Store) ListExecutions(ctx context.Context, tenantID string, limit, offset int) ([]Execution, error)
- func (s *Store) ListKeys(ctx context.Context, tenantID string) ([]APIKey, error)
- func (s *Store) ListSkills(ctx context.Context, tenantID string) ([]SkillRecord, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) RevokeKey(ctx context.Context, keyID string) error
- func (s *Store) UpdateExecution(ctx context.Context, e *Execution) error
- func (s *Store) UpsertSkill(ctx context.Context, rec *SkillRecord) error
- func (s *Store) ValidateKey(ctx context.Context, keyHash string) (*APIKey, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a requested record does not exist.
Functions ¶
This section is empty.
Types ¶
type APIKey ¶
type APIKey struct {
ID string
KeyHash string
TenantID string
Name string
CreatedAt time.Time
RevokedAt *time.Time
}
APIKey represents a row in the sandbox.api_keys table.
type Execution ¶
type Execution struct {
ID string `json:"execution_id"`
SkillName string `json:"skill_name"`
SkillVersion string `json:"skill_version"`
TenantID string `json:"tenant_id"`
Status string `json:"status"`
Input json.RawMessage `json:"input,omitempty"`
Output json.RawMessage `json:"output,omitempty"`
Logs string `json:"logs,omitempty"`
FilesURL string `json:"files_url,omitempty"`
FilesList []string `json:"files_list,omitempty"`
DurationMs int64 `json:"duration_ms"`
Error *string `json:"error"`
CreatedAt time.Time `json:"created_at"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
}
Execution represents a row in the sandbox.executions table.
type SkillRecord ¶
type SkillRecord struct {
TenantID string `json:"tenant_id"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Lang string `json:"lang"`
UploadedAt time.Time `json:"uploaded_at"`
}
SkillRecord represents a row in the sandbox.skills metadata table.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps a PostgreSQL connection pool and provides data-access methods for the Skillbox runtime.
func New ¶
New opens a connection pool to PostgreSQL using the provided DSN, verifies connectivity, and runs all embedded migrations. It returns a ready-to-use Store or an error if any step fails.
func NewWithDB ¶
NewWithDB creates a Store that wraps the given *sql.DB without running migrations. This is intended for use in tests that provide a mock or in-memory database.
func (*Store) CreateExecution ¶
CreateExecution inserts a new execution record with status "running". The Execution is mutated in place with the server-generated ID and timestamp.
func (*Store) CreateKey ¶
CreateKey inserts a new API key record and returns the populated APIKey (including the server-generated UUID and timestamp).
func (*Store) DeleteSkill ¶
DeleteSkill removes a skill metadata record.
func (*Store) GetAPIKeyByHash ¶
GetAPIKeyByHash looks up an API key by its SHA-256 hex hash. It returns ErrNotFound if no matching key exists.
func (*Store) GetExecution ¶
GetExecution retrieves a single execution by its UUID. Returns ErrNotFound if the execution does not exist.
func (*Store) GetSkill ¶
GetSkill retrieves a single skill metadata record by tenant, name, and version.
func (*Store) InsertExecution ¶
InsertExecution creates a new execution record. This is an alias kept for compatibility with callers that set status before calling.
func (*Store) ListExecutions ¶
func (s *Store) ListExecutions(ctx context.Context, tenantID string, limit, offset int) ([]Execution, error)
ListExecutions returns executions for a tenant ordered by creation time (newest first), with pagination via limit and offset.
func (*Store) ListKeys ¶
ListKeys returns all API keys belonging to the given tenant, ordered by creation time (newest first). Revoked keys are included so the caller can display their status.
func (*Store) ListSkills ¶
ListSkills returns all skill metadata for a tenant, ordered by name then version.
func (*Store) RevokeKey ¶
RevokeKey soft-deletes an API key by setting its revoked_at timestamp. It returns an error if the key does not exist or is already revoked.
func (*Store) UpdateExecution ¶
UpdateExecution writes back mutable fields for an existing execution. Typically called once the execution has completed (or timed out).
func (*Store) UpsertSkill ¶
func (s *Store) UpsertSkill(ctx context.Context, rec *SkillRecord) error
UpsertSkill inserts or updates a skill metadata record. On conflict (same tenant, name, version) it updates the description and lang.
func (*Store) ValidateKey ¶
ValidateKey looks up an API key by its SHA-256 hash. It returns the matching APIKey if the hash exists and the key has not been revoked. A nil APIKey (with nil error) is returned when the key is not found or has been revoked.