service

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound indicates the requested resource was not found.

Functions

This section is empty.

Types

type AdminService added in v0.10.3

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

AdminService contains business logic for admin operations.

func NewAdminService added in v0.10.3

func NewAdminService(db *gorm.DB, rbacProvider rbac.Provider) *AdminService

NewAdminService creates a new AdminService.

func (*AdminService) CreateUser added in v0.10.3

func (s *AdminService) CreateUser(req CreateUserRequest, adminUserID uuid.UUID) (*models.User, error)

CreateUser creates a new user, optionally granting admin, and writes an audit log.

func (*AdminService) DeleteUser added in v0.10.3

func (s *AdminService) DeleteUser(userID uuid.UUID, adminUserID uuid.UUID) error

DeleteUser deletes a user and writes an audit log. Cannot delete self.

func (*AdminService) GetDashboardStats added in v0.10.3

func (s *AdminService) GetDashboardStats() (*DashboardStats, error)

GetDashboardStats returns admin dashboard statistics.

func (*AdminService) GetUser added in v0.10.3

func (s *AdminService) GetUser(userID uuid.UUID) (*UserWithAdmin, error)

GetUser returns a user by ID with admin status.

func (*AdminService) GrantPermission added in v0.10.3

func (s *AdminService) GrantPermission(userID, workspaceID uuid.UUID, roleID uint, adminUserID uuid.UUID) (*models.Permission, error)

GrantPermission creates a permission record and grants RBAC access.

func (*AdminService) ListAuditLogs added in v0.10.3

func (s *AdminService) ListAuditLogs(userIDFilter, actionFilter string) ([]models.AuditLog, error)

ListAuditLogs returns audit logs with optional filters.

func (*AdminService) ListPermissions added in v0.10.3

func (s *AdminService) ListPermissions() ([]models.Permission, error)

ListPermissions returns all permissions with preloaded relations.

func (*AdminService) ListRoles added in v0.10.3

func (s *AdminService) ListRoles() ([]models.Role, error)

ListRoles returns all roles.

func (*AdminService) ListUsers added in v0.10.3

func (s *AdminService) ListUsers() ([]UserWithAdmin, error)

ListUsers returns all users with their admin status.

func (*AdminService) RevokePermission added in v0.10.3

func (s *AdminService) RevokePermission(permissionID string, adminUserID uuid.UUID) error

RevokePermission revokes a permission by ID and removes RBAC access.

func (*AdminService) ToggleAdmin added in v0.10.3

func (s *AdminService) ToggleAdmin(userID uuid.UUID, adminUserID uuid.UUID) (*UserWithAdmin, error)

ToggleAdmin toggles admin status for a user and writes an audit log.

type CollaboratorResult added in v0.10.3

type CollaboratorResult struct {
	UserID   uuid.UUID `json:"user_id"`
	Username string    `json:"username"`
	Email    string    `json:"email,omitempty"`
	Role     string    `json:"role"`
	IsOwner  bool      `json:"is_owner"`
}

CollaboratorResult is the result type for ListCollaborators.

type ConflictError

type ConflictError struct {
	Message string
}

ConflictError represents a conflict condition (HTTP 409).

func (*ConflictError) Error

func (e *ConflictError) Error() string

type CreateRegistryReq added in v0.10.3

type CreateRegistryReq struct {
	Name      string
	URL       string
	Username  string
	Password  string
	APIToken  string
	IsDefault bool
	Namespace string
	CreatedBy uuid.UUID
}

CreateRegistryRequest holds parameters for creating a registry.

type CreateRequest

type CreateRequest struct {
	Name             string
	PackageManager   string
	PixiToml         string
	Source           string
	Path             string
	ImportStagingDir string // absolute path to a pre-extracted bundle directory; worker hands it to the executor as SeedDir
}

CreateRequest holds parameters for creating a workspace.

type CreateUserRequest added in v0.10.3

type CreateUserRequest struct {
	Username string
	Email    string
	Password string
	IsAdmin  bool
}

CreateUserRequest holds parameters for creating a user.

type DashboardStats added in v0.10.3

type DashboardStats struct {
	TotalDiskUsageBytes     int64  `json:"total_disk_usage_bytes"`
	TotalDiskUsageFormatted string `json:"total_disk_usage_formatted"`
}

DashboardStats holds admin dashboard statistics.

type ForbiddenError added in v0.10.3

type ForbiddenError struct {
	Message string
}

ForbiddenError represents a forbidden condition (HTTP 403).

func (*ForbiddenError) Error added in v0.10.3

func (e *ForbiddenError) Error() string

type ImportFromRegistryRequest added in v0.10.5

type ImportFromRegistryRequest struct {
	Repository string
	Tag        string
	Name       string
}

ImportFromRegistryRequest selects the OCI bundle to import.

type JobService added in v0.10.3

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

JobService contains business logic for job operations.

func NewJobService added in v0.10.3

func NewJobService(db *gorm.DB) *JobService

NewJobService creates a new JobService.

func (*JobService) FlushLogs added in v0.10.3

func (s *JobService) FlushLogs(jobID uuid.UUID, logs string) error

FlushLogs persists the current log content for a job.

func (*JobService) GetJob added in v0.10.3

func (s *JobService) GetJob(jobID string, userID uuid.UUID) (*models.Job, error)

GetJob returns a single job by ID, verifying the user owns the workspace.

func (*JobService) GetJobForStreaming added in v0.10.3

func (s *JobService) GetJobForStreaming(jobID uuid.UUID, userID uuid.UUID) (*models.Job, error)

GetJobForStreaming returns a job by ID with ownership check, for SSE streaming. Returns the job regardless of status (caller decides what to do with completed jobs).

func (*JobService) ListJobs added in v0.10.3

func (s *JobService) ListJobs(userID uuid.UUID) ([]models.Job, error)

ListJobs returns all jobs for workspaces owned by the given user.

func (*JobService) LoadVersion added in v0.10.3

func (s *JobService) LoadVersion(versionID uuid.UUID) (*models.WorkspaceVersion, error)

LoadVersion loads a workspace version by ID.

func (*JobService) LoadWorkspace added in v0.10.3

func (s *JobService) LoadWorkspace(workspaceID uuid.UUID) (*models.Workspace, error)

LoadWorkspace loads a workspace by ID.

func (*JobService) MarkCompleted added in v0.10.3

func (s *JobService) MarkCompleted(job *models.Job, logs string)

MarkCompleted sets a job's status to completed with final logs.

func (*JobService) MarkFailed added in v0.10.3

func (s *JobService) MarkFailed(job *models.Job, logs string, errMsg string)

MarkFailed sets a job's status to failed with error and final logs.

func (*JobService) MarkPanicked added in v0.10.3

func (s *JobService) MarkPanicked(job *models.Job, panicMsg string)

MarkPanicked sets a job as failed after a panic recovery.

func (*JobService) MarkRunning added in v0.10.3

func (s *JobService) MarkRunning(job *models.Job)

MarkRunning sets a job's status to running with a start timestamp.

type PublicationResult added in v0.10.3

type PublicationResult struct {
	ID                uuid.UUID `json:"id"`
	VersionNumber     int       `json:"version_number"`
	RegistryName      string    `json:"registry_name"`
	RegistryURL       string    `json:"registry_url"`
	RegistryNamespace string    `json:"registry_namespace"`
	Repository        string    `json:"repository"`
	Tag               string    `json:"tag"`
	Digest            string    `json:"digest"`
	IsPublic          bool      `json:"is_public"`
	PublishedBy       string    `json:"published_by"`
	PublishedAt       string    `json:"published_at"`
}

PublicationResult is the denormalized publication info ready for JSON.

type PublishDefaultsResult added in v0.10.3

type PublishDefaultsResult struct {
	RegistryID   uuid.UUID `json:"registry_id"`
	RegistryName string    `json:"registry_name"`
	Namespace    string    `json:"namespace"`
	Repository   string    `json:"repository"`
	Tag          string    `json:"tag"`
}

PublishDefaultsResult holds precomputed defaults for the publish dialog.

type PublishWorkspaceRequest added in v0.10.3

type PublishWorkspaceRequest struct {
	RegistryID uuid.UUID
	Repository string
	Tag        string
}

PublishWorkspaceRequest holds parameters for publishing to an OCI registry.

type PushRequest

type PushRequest struct {
	Tag      string
	PixiToml string
	PixiLock string
	Force    bool
}

PushRequest holds parameters for pushing a new version.

type PushResult

type PushResult struct {
	VersionNumber int
	Tags          []string
	ContentHash   string
	Deduplicated  bool
	Tag           string // kept for backwards compatibility
}

PushResult is returned after a successful push.

type RegistryResult added in v0.10.3

type RegistryResult struct {
	ID          uuid.UUID `json:"id"`
	Name        string    `json:"name"`
	URL         string    `json:"url"`
	Username    string    `json:"username"`
	HasAPIToken bool      `json:"has_api_token"`
	IsDefault   bool      `json:"is_default"`
	Namespace   string    `json:"namespace"`
	CreatedAt   string    `json:"created_at"`
}

RegistryResult is the response type for registry operations.

type RegistryService added in v0.10.3

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

RegistryService contains business logic for OCI registry operations.

func NewRegistryService added in v0.10.3

func NewRegistryService(db *gorm.DB, encKey []byte) *RegistryService

NewRegistryService creates a new RegistryService.

func (*RegistryService) CreateRegistry added in v0.10.3

func (s *RegistryService) CreateRegistry(req CreateRegistryReq) (*RegistryResult, error)

CreateRegistry creates a new registry with encrypted credentials.

func (*RegistryService) DeleteRegistry added in v0.10.3

func (s *RegistryService) DeleteRegistry(id string) error

DeleteRegistry deletes a registry by ID.

func (*RegistryService) FallbackRepositories added in v0.10.3

func (s *RegistryService) FallbackRepositories(registryID string) []string

FallbackRepositories returns distinct repository names from publication records for a registry.

func (*RegistryService) GetRegistry added in v0.10.3

func (s *RegistryService) GetRegistry(id string) (*RegistryResult, error)

GetRegistry returns a single registry by ID with admin-level detail.

func (*RegistryService) GetRegistryWithCredentials added in v0.10.3

func (s *RegistryService) GetRegistryWithCredentials(id string) (*RegistryWithCredentials, error)

GetRegistryWithCredentials returns a registry with decrypted credentials for OCI operations.

func (*RegistryService) ListPublicRegistries added in v0.10.3

func (s *RegistryService) ListPublicRegistries() ([]RegistryResult, error)

ListPublicRegistries returns registries with public-safe info (no credentials).

func (*RegistryService) ListRegistries added in v0.10.3

func (s *RegistryService) ListRegistries() ([]RegistryResult, error)

ListRegistries returns all registries with admin-level detail (includes username, token status).

func (*RegistryService) UpdateRegistry added in v0.10.3

func (s *RegistryService) UpdateRegistry(id string, req UpdateRegistryReq) (*RegistryResult, error)

UpdateRegistry updates an existing registry.

type RegistryWithCredentials added in v0.10.3

type RegistryWithCredentials struct {
	Registry models.OCIRegistry
	Password string
	APIToken string
}

RegistryWithCredentials holds a registry and its decrypted credentials for OCI operations.

type UpdateRegistryReq added in v0.10.3

type UpdateRegistryReq struct {
	Name      *string
	URL       *string
	Username  *string
	Password  *string
	APIToken  *string
	IsDefault *bool
	Namespace *string
}

UpdateRegistryReq holds parameters for updating a registry.

type UserWithAdmin added in v0.10.3

type UserWithAdmin struct {
	models.User
	IsAdmin bool `json:"is_admin"`
}

UserWithAdmin wraps a user with their admin status.

type ValidationError

type ValidationError struct {
	Message string
}

ValidationError represents a bad-request condition (HTTP 400).

func (*ValidationError) Error

func (e *ValidationError) Error() string

type WorkspaceResponse added in v0.10.3

type WorkspaceResponse struct {
	models.Workspace
	SizeFormatted string `json:"size_formatted"`
}

WorkspaceResponse wraps a workspace with computed fields.

func NewWorkspaceResponse added in v0.10.3

func NewWorkspaceResponse(ws models.Workspace) WorkspaceResponse

NewWorkspaceResponse creates a WorkspaceResponse with formatted size.

type WorkspaceService

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

WorkspaceService contains the business logic for workspace operations.

func New

func New(db *gorm.DB, q queue.Queue, exec executor.Executor, isLocal bool, encKey []byte, rbacProvider rbac.Provider) *WorkspaceService

New creates a new WorkspaceService.

func (*WorkspaceService) Create

func (s *WorkspaceService) Create(ctx context.Context, req CreateRequest, userID uuid.UUID) (*models.Workspace, error)

Create validates and creates a new workspace, queues the creation job, grants RBAC owner access, and writes an audit log entry.

func (*WorkspaceService) CreateVersionSnapshot added in v0.10.3

func (s *WorkspaceService) CreateVersionSnapshot(ctx context.Context, ws *models.Workspace, jobID uuid.UUID, userID uuid.UUID, description string) error

CreateVersionSnapshot creates a version snapshot after a successful operation. Called by the worker after install, remove, create, and rollback operations.

func (*WorkspaceService) Delete

func (s *WorkspaceService) Delete(ctx context.Context, wsID string, userID uuid.UUID) error

Delete queues a deletion job for the workspace and writes an audit log.

func (*WorkspaceService) DeleteAllPackages added in v0.10.3

func (s *WorkspaceService) DeleteAllPackages(wsID uuid.UUID)

DeleteAllPackages removes all packages for a workspace from the DB.

func (*WorkspaceService) DeletePackagesByName added in v0.10.3

func (s *WorkspaceService) DeletePackagesByName(wsID uuid.UUID, packages []string)

DeletePackagesByName removes specific packages from the DB.

func (*WorkspaceService) Get

Get returns a single workspace by ID.

func (*WorkspaceService) GetPixiToml

func (s *WorkspaceService) GetPixiToml(wsID string) (string, error)

GetPixiToml reads the pixi.toml content from the workspace's filesystem.

func (*WorkspaceService) GetPublishDefaults added in v0.10.3

func (s *WorkspaceService) GetPublishDefaults(wsID string) (*PublishDefaultsResult, error)

GetPublishDefaults returns default values for the publish dialog.

func (*WorkspaceService) GetVersion

func (s *WorkspaceService) GetVersion(wsID string, versionNum string) (*models.WorkspaceVersion, error)

GetVersion returns a specific version by workspace ID and version number.

func (*WorkspaceService) GetVersionFile

func (s *WorkspaceService) GetVersionFile(wsID string, versionNum string, field string) (string, error)

GetVersionFile returns the content of a specific file field from a version. field must be "lock" or "manifest".

func (*WorkspaceService) GetWorkspacePath added in v0.10.3

func (s *WorkspaceService) GetWorkspacePath(ws *models.Workspace) string

GetWorkspacePath returns the filesystem path for a workspace.

func (*WorkspaceService) ImportFromRegistry added in v0.10.5

func (s *WorkspaceService) ImportFromRegistry(ctx context.Context, registryID string, req ImportFromRegistryRequest, userID uuid.UUID) (*models.Workspace, error)

ImportFromRegistry pulls an OCI bundle from a registered registry and creates a new workspace populated from it.

Flow is identical for both modes: resolve the registry, stage every fetched artifact under the executor's import-staging root, then enqueue a workspace-create job that points the worker at the staging dir (CreateWorkspaceOptions.SeedDir). The mode difference is purely how many bytes get staged:

  • local mode: oci.ExtractBundle streams pixi.toml + pixi.lock + every asset layer to disk. The worker seeds the workspace from the full bundle, so asset files and the published lockfile both round-trip.
  • team mode: oci.PullBundle fetches only the two core layers; the handler writes them to the staging dir as plain files. Asset layers are listed in the manifest but not fetched. pixi.lock is still preserved on disk for the worker to use, fixing a latent bug where team-mode imports re-solved from pixi.toml alone.

Network errors surface synchronously so the caller knows the import did not start. On any failure after the staging dir is created, the staging dir is removed before returning.

func (*WorkspaceService) InstallPackages added in v0.10.3

func (s *WorkspaceService) InstallPackages(ctx context.Context, wsID string, packages []string, userID uuid.UUID) (*models.Job, error)

InstallPackages creates and enqueues an install-packages job.

func (*WorkspaceService) IsLocal added in v0.10.5

func (s *WorkspaceService) IsLocal() bool

IsLocal reports whether the service is running in local/desktop mode.

func (*WorkspaceService) List

func (s *WorkspaceService) List(userID uuid.UUID) ([]WorkspaceResponse, error)

List returns workspaces visible to the given user. In local mode all workspaces are returned (no ownership filtering).

func (*WorkspaceService) ListCollaborators added in v0.10.3

func (s *WorkspaceService) ListCollaborators(wsID string) ([]CollaboratorResult, error)

ListCollaborators returns all users with access to a workspace (owner + shared users).

func (*WorkspaceService) ListPackages added in v0.10.3

func (s *WorkspaceService) ListPackages(wsID string) ([]models.Package, error)

ListPackages returns packages for a workspace, auto-syncing from disk for local workspaces with no DB records.

func (*WorkspaceService) ListPublications added in v0.10.3

func (s *WorkspaceService) ListPublications(wsID string) ([]PublicationResult, error)

ListPublications returns all publications for a workspace.

func (*WorkspaceService) ListTags

func (s *WorkspaceService) ListTags(wsID string) ([]models.WorkspaceTag, error)

ListTags returns tags for a workspace, ordered by creation time descending.

func (*WorkspaceService) ListVersions

func (s *WorkspaceService) ListVersions(wsID string) ([]models.WorkspaceVersion, error)

ListVersions returns versions for a workspace (excluding large file contents).

func (*WorkspaceService) PublishWorkspace added in v0.10.3

func (s *WorkspaceService) PublishWorkspace(ctx context.Context, wsID string, req PublishWorkspaceRequest, userID uuid.UUID) (*PublicationResult, error)

PublishWorkspace publishes a workspace's pixi.toml and pixi.lock to an OCI registry.

func (*WorkspaceService) PushVersion

func (s *WorkspaceService) PushVersion(ctx context.Context, wsID string, req PushRequest, userID uuid.UUID) (*PushResult, error)

PushVersion creates a new workspace version (or deduplicates), writes files, handles tags (content hash, latest, optional user tag), and records audit logs.

func (*WorkspaceService) RemovePackage added in v0.10.3

func (s *WorkspaceService) RemovePackage(ctx context.Context, wsID string, packageName string, userID uuid.UUID) (*models.Job, error)

RemovePackage creates and enqueues a remove-package job.

func (*WorkspaceService) RollbackToVersion added in v0.10.3

func (s *WorkspaceService) RollbackToVersion(ctx context.Context, wsID string, versionNumber int, userID uuid.UUID) (*models.Job, error)

RollbackToVersion creates and enqueues a rollback job.

func (*WorkspaceService) SaveInstalledPackages added in v0.10.3

func (s *WorkspaceService) SaveInstalledPackages(wsID uuid.UUID, packages []string)

SaveInstalledPackages records newly installed packages in the DB.

func (*WorkspaceService) SavePixiToml

func (s *WorkspaceService) SavePixiToml(wsID string, content string) error

SavePixiToml writes pixi.toml content to the workspace's filesystem.

func (*WorkspaceService) SetWorkspacePath added in v0.10.3

func (s *WorkspaceService) SetWorkspacePath(wsID uuid.UUID, path string) error

SetWorkspacePath updates the workspace path in the database.

func (*WorkspaceService) SetWorkspaceStatus added in v0.10.3

func (s *WorkspaceService) SetWorkspaceStatus(wsID uuid.UUID, status models.WorkspaceStatus) error

SetWorkspaceStatus updates the workspace status in the database.

func (*WorkspaceService) ShareWorkspace added in v0.10.3

func (s *WorkspaceService) ShareWorkspace(wsID string, ownerID uuid.UUID, targetUserID uuid.UUID, role string) (*models.Permission, error)

ShareWorkspace grants a user access to a workspace. Only the owner can share.

func (*WorkspaceService) SoftDeleteWorkspace added in v0.10.3

func (s *WorkspaceService) SoftDeleteWorkspace(wsID uuid.UUID) error

SoftDeleteWorkspace soft-deletes a workspace.

func (*WorkspaceService) SolveWorkspace added in v0.10.4

func (s *WorkspaceService) SolveWorkspace(ctx context.Context, wsID string, userID uuid.UUID) (*models.Job, error)

SolveWorkspace creates and enqueues a solve job (pixi install from current pixi.toml).

func (*WorkspaceService) SyncPackagesFromWorkspace added in v0.10.3

func (s *WorkspaceService) SyncPackagesFromWorkspace(ctx context.Context, ws *models.Workspace) error

SyncPackagesFromWorkspace lists packages from the workspace on disk and saves them to the DB. Called by the worker after install/remove/create/rollback operations.

func (*WorkspaceService) UnshareWorkspace added in v0.10.3

func (s *WorkspaceService) UnshareWorkspace(wsID string, ownerID uuid.UUID, targetUserID uuid.UUID) error

UnshareWorkspace revokes a user's access to a workspace. Only the owner can unshare.

func (*WorkspaceService) UpdatePublication added in v0.10.3

func (s *WorkspaceService) UpdatePublication(ctx context.Context, wsID string, pubID string, isPublic bool) (*PublicationResult, error)

UpdatePublication updates a publication's visibility.

func (*WorkspaceService) UpdateWorkspaceSize added in v0.10.3

func (s *WorkspaceService) UpdateWorkspaceSize(ws *models.Workspace)

UpdateWorkspaceSize calculates and updates the workspace size in the database.

Jump to

Keyboard shortcuts

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