gui

package
v0.0.0-...-8e695e4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 100 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gui provides the embedded HTTP server and app-layer adapters for the GUI.

Index

Constants

View Source
const DefaultSetupCodeTTL = 30 * time.Minute

DefaultSetupCodeTTL is how long a first-admin setup code stays valid.

Variables

View Source
var ErrServerAuthConfigLegacyUnreadable error = serverAuthLegacyUnreadableSentinel{}

ErrServerAuthConfigLegacyUnreadable identifies malformed or otherwise unreadable legacy auth bytes. A valid destination is not silently accepted while this source remains present; explicit reset or source repair is required.

View Source
var ErrServerAuthConfigMigrationConflict error = serverAuthMigrationConflictSentinel{}

ErrServerAuthConfigMigrationConflict identifies a legacy and destination auth state that require an explicit operator choice.

View Source
var ErrServerAuthConfigNotFound = newGUIPermanentError("gui server auth config not found", nil)

ErrServerAuthConfigNotFound indicates that the GUI auth config does not exist yet.

View Source
var ErrWorkspaceConfigNotFound = newGUIPermanentError("gui workspace config not found", nil)

ErrWorkspaceConfigNotFound indicates that the GUI workspace config does not exist yet.

Functions

func DefaultServerAuthConfigPath

func DefaultServerAuthConfigPath(divekitHome string) (string, error)

DefaultServerAuthConfigPath returns the default GUI auth config path.

func GenerateSetupCode

func GenerateSetupCode() (string, error)

GenerateSetupCode returns a random one-time setup code such as "K7QXM-4PD2R-WN9HT-E3VBC" (about 99 bits of entropy).

func ResolveManagedStatePaths

func ResolveManagedStatePaths(options HandlerOptions) ([]string, error)

ResolveManagedStatePaths returns every exact user-state path that managed startup may touch before the HTTP server begins serving requests. The caller owns these paths through coordination.ManagedOwnerRegistry before auth bootstrap or workspace initialization starts.

func ResolveServerAuthConfigPath

func ResolveServerAuthConfigPath(configPath, divekitHome string) (string, error)

ResolveServerAuthConfigPath resolves a custom or default GUI auth config path.

func ResolveWorkspaceConfigPath

func ResolveWorkspaceConfigPath(configPath, workingDir string) string

ResolveWorkspaceConfigPath resolves the GUI workspace config path.

func SaveServerAuthConfig

func SaveServerAuthConfig(ctx context.Context, configPath string, cfg ServerAuthConfig) error

SaveServerAuthConfig validates and persists the GUI auth config in the SQLite store. Direct saves receive the same short exact-path admission as migration; callers with an outer home/auth lease reuse both claims.

func SaveWorkspaceConfig

func SaveWorkspaceConfig(configPath string, cfg WorkspaceConfig) error

SaveWorkspaceConfig validates and persists the GUI workspace config.

func WithAuthInfo

func WithAuthInfo(ctx context.Context, info AuthInfo) context.Context

WithAuthInfo stores auth info in the request context.

func WithWorkspace

func WithWorkspace(ctx context.Context, workspace Workspace) context.Context

WithWorkspace stores the active workspace in the request context.

Types

type AuthInfo

type AuthInfo struct {
	Mode          ServerMode
	Authenticated bool
	Subject       string
	Username      string
	DisplayName   string
	Role          Role
	AuthMode      string
	// LoginAuthMode is the AuthMode of the credential a session was signed in
	// with. A session request reports AuthMode "session", which hides whether
	// a shared token or a personal password stands behind it.
	LoginAuthMode string
	AuthReference string
}

AuthInfo captures the resolved authentication context for a request.

func AuthInfoFromContext

func AuthInfoFromContext(ctx context.Context) AuthInfo

AuthInfoFromContext returns auth info stored in the request context.

type Authenticator

type Authenticator func(token string) (AuthInfo, bool)

Authenticator validates a bearer token and returns the resolved auth info.

func NewServerAuthConfigAuthenticator

func NewServerAuthConfigAuthenticator(config ServerAuthConfig) Authenticator

NewServerAuthConfigAuthenticator builds an authenticator backed by persisted GUI auth config.

func NewStaticBearerTokenAuthenticator

func NewStaticBearerTokenAuthenticator(opts StaticBearerTokenOptions) Authenticator

NewStaticBearerTokenAuthenticator builds an authenticator for one static bearer token.

type DistributionAccess

type DistributionAccess struct {
	WorkspaceID    string   `json:"workspace_id"`
	DistributionID string   `json:"distribution_id"`
	Visibility     string   `json:"visibility"`
	TeamIDs        []string `json:"team_ids,omitempty"`
}

DistributionAccess defines how a distribution is shared within a workspace.

type ExecutionAuthorityResolver

type ExecutionAuthorityResolver func(ctx context.Context, subject, authMode, authReference string) (Role, error)

ExecutionAuthorityResolver resolves the current non-secret authority for a queued actor. Auth references identify an auth record without persisting a password, bearer token, or token hash.

type Handler

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

Handler starts and manages the GUI server lifecycle.

func NewHandler

func NewHandler(options *HandlerOptions) (*Handler, error)

NewHandler creates a GUI handler with validated options.

func (*Handler) Execute

func (h *Handler) Execute(ctx context.Context) (err error)

Execute starts the GUI server and blocks until it is stopped.

type HandlerOptions

type HandlerOptions struct {
	Host                       string
	Port                       int
	AssetsDir                  string
	BrowserPath                string
	AuthConfigPath             string
	WorkspaceConfigPath        string
	DivekitHome                string
	OpenBrowser                bool
	WorkingDir                 string
	Mode                       ServerMode
	Authenticator              Authenticator
	WorkspaceBootstrapSubjects []string
	ResolveExecutionAuthority  ExecutionAuthorityResolver
	AuthMiddleware             Middleware
	APIMiddlewares             []Middleware
	SecretStore                secretstore.Store
	AuthenticationService      authentication.Service
	// OwnerRegistry is supplied by managed runtime startup after it has
	// claimed every state path touched by auth and workspace bootstrap.
	OwnerRegistry *coordination.ManagedOwnerRegistry
	// SetupCode, when set in authenticated mode, gates the first-admin
	// bootstrap of a server that starts without users. SetupCodeTTL bounds
	// its lifetime (default DefaultSetupCodeTTL).
	SetupCode    string
	SetupCodeTTL time.Duration
}

HandlerOptions configures the GUI server.

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware wraps an HTTP handler with additional request processing.

func NewServerAuthConfigMiddleware

func NewServerAuthConfigMiddleware(config ServerAuthConfig, realm string) Middleware

NewServerAuthConfigMiddleware creates bearer-token middleware backed by persisted GUI auth config.

func NewStaticBearerTokenMiddleware

func NewStaticBearerTokenMiddleware(opts StaticBearerTokenOptions) Middleware

NewStaticBearerTokenMiddleware creates bearer-token middleware backed by a static token.

type OriginBinding

type OriginBinding struct {
	WorkspaceID string `json:"workspace_id"`
	OriginID    string `json:"origin_id"`
}

OriginBinding assigns an origin to a workspace.

type ResourceShare

type ResourceShare struct {
	ShareID      string    `json:"share_id"`
	ResourceType string    `json:"resource_type"`
	ResourceID   string    `json:"resource_id"`
	GranteeType  string    `json:"grantee_type"`
	GranteeID    string    `json:"grantee_id"`
	Permission   string    `json:"permission"`
	GrantedBy    string    `json:"granted_by,omitempty"`
	CreatedAt    time.Time `json:"created_at,omitempty"`
}

ResourceShare grants additional subject or team access to a resource.

type Role

type Role string

Role identifies the effective GUI authorization role.

const (
	RoleAdmin  Role = "admin"
	RoleViewer Role = "viewer"
)

Supported GUI authorization roles.

type ServerAuthBootstrapOptions

type ServerAuthBootstrapOptions struct {
	DivekitHome string
	ConfigPath  string
	Subject     string
	Username    string
	DisplayName string
	Password    string
}

ServerAuthBootstrapOptions controls initial GUI auth bootstrapping.

type ServerAuthBootstrapResult

type ServerAuthBootstrapResult struct {
	ConfigPath        string
	Created           bool
	Reset             bool
	Subject           string
	Username          string
	DisplayName       string
	Role              Role
	Password          string
	PasswordGenerated bool
	Token             string
	TokenGenerated    bool
}

ServerAuthBootstrapResult describes the created bootstrap account.

func BootstrapServerAuthConfig

func BootstrapServerAuthConfig(ctx context.Context, opts ServerAuthBootstrapOptions) (*ServerAuthBootstrapResult, error)

BootstrapServerAuthConfig creates a fresh GUI auth config with an admin user.

type ServerAuthConfig

type ServerAuthConfig struct {
	SchemaVersion int                    `json:"schema_version"`
	Credentials   []ServerAuthCredential `json:"credentials,omitempty"`
	Users         []ServerAuthUser       `json:"users,omitempty"`
	CreatedAt     time.Time              `json:"created_at"`
	UpdatedAt     time.Time              `json:"updated_at"`
}

ServerAuthConfig is the persisted GUI authentication configuration.

func LoadServerAuthConfig

func LoadServerAuthConfig(ctx context.Context, configPath string) (ServerAuthConfig, error)

LoadServerAuthConfig loads and validates the GUI auth config from the SQLite store. The exact auth path is admitted here for direct callers. Managed callers already hold the same claim and reuse it through the context.

type ServerAuthCredential

type ServerAuthCredential struct {
	Subject   string `json:"subject"`
	Role      Role   `json:"role"`
	TokenHash string `json:"token_hash"`
}

ServerAuthCredential stores a bearer-token credential entry.

type ServerAuthUser

type ServerAuthUser struct {
	Username     string `json:"username"`
	DisplayName  string `json:"display_name,omitempty"`
	Subject      string `json:"subject,omitempty"`
	Role         Role   `json:"role"`
	PasswordHash string `json:"-"`
}

ServerAuthUser stores a password-based GUI user entry.

type ServerMode

type ServerMode string

ServerMode controls how the GUI authenticates and scopes access.

const (
	ServerModeLocalSingleUser ServerMode = "local-single-user"
	ServerModeAuthenticated   ServerMode = "authenticated-server"
	ServerModeUnrestricted    ServerMode = "unrestricted"
)

Supported GUI server modes.

type SessionManager

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

SessionManager stores in-memory GUI sessions.

func NewSessionManager

func NewSessionManager() *SessionManager

NewSessionManager constructs a session manager with default TTLs.

func (*SessionManager) Create

func (m *SessionManager) Create(info AuthInfo, activeWorkspaceID string) (string, error)

Create creates a session token for the provided auth info and workspace.

func (*SessionManager) Delete

func (m *SessionManager) Delete(token string)

Delete removes a single session token.

func (*SessionManager) DeleteAll

func (m *SessionManager) DeleteAll()

DeleteAll removes every active session.

func (*SessionManager) DeleteSubject

func (m *SessionManager) DeleteSubject(subject string)

DeleteSubject removes all sessions belonging to a subject.

func (*SessionManager) Lookup

func (m *SessionManager) Lookup(token string) (AuthInfo, string, bool)

Lookup resolves a session token and refreshes its idle expiry.

func (*SessionManager) SetActiveWorkspace

func (m *SessionManager) SetActiveWorkspace(token, workspaceID string) bool

SetActiveWorkspace updates the active workspace for an existing session.

type StaticBearerTokenOptions

type StaticBearerTokenOptions struct {
	Token   string
	Realm   string
	Subject string
	Role    Role
}

StaticBearerTokenOptions configures static bearer-token authentication.

type Team

type Team struct {
	TeamID      string    `json:"team_id"`
	WorkspaceID string    `json:"workspace_id"`
	Slug        string    `json:"slug"`
	DisplayName string    `json:"display_name"`
	Description string    `json:"description,omitempty"`
	CreatedAt   time.Time `json:"created_at,omitempty"`
	UpdatedAt   time.Time `json:"updated_at,omitempty"`
}

Team defines a workspace team entry.

type TeamMembership

type TeamMembership struct {
	TeamID    string    `json:"team_id"`
	Subject   string    `json:"subject"`
	Role      string    `json:"role"`
	CreatedAt time.Time `json:"created_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

TeamMembership assigns a subject to a team.

type Workspace

type Workspace struct {
	WorkspaceID string `json:"workspace_id"`
	Slug        string `json:"slug"`
	DisplayName string `json:"display_name"`
	Kind        string `json:"kind"`
	Implicit    bool   `json:"implicit"`
}

Workspace describes the workspace resolved for the current request.

func WorkspaceFromContext

func WorkspaceFromContext(ctx context.Context) Workspace

WorkspaceFromContext returns the workspace stored in the request context.

type WorkspaceConfig

type WorkspaceConfig struct {
	SchemaVersion int                   `json:"schema_version"`
	Workspaces    []Workspace           `json:"workspaces"`
	Memberships   []WorkspaceMembership `json:"memberships"`
	Origins       []OriginBinding       `json:"origins,omitempty"`
	Distributions []DistributionAccess  `json:"distributions,omitempty"`
	Shares        []ResourceShare       `json:"shares,omitempty"`
	Teams         []Team                `json:"teams,omitempty"`
	TeamMembers   []TeamMembership      `json:"team_members,omitempty"`
	CreatedAt     time.Time             `json:"created_at"`
	UpdatedAt     time.Time             `json:"updated_at"`
}

WorkspaceConfig is the persisted GUI workspace and access configuration.

func EnsureWorkspaceConfig

func EnsureWorkspaceConfig(opts WorkspaceConfigEnsureOptions) (WorkspaceConfig, error)

EnsureWorkspaceConfig loads or bootstraps the GUI workspace config.

func LoadWorkspaceConfig

func LoadWorkspaceConfig(configPath string) (WorkspaceConfig, error)

LoadWorkspaceConfig loads and validates the GUI workspace config from disk.

type WorkspaceConfigEnsureOptions

type WorkspaceConfigEnsureOptions struct {
	ConfigPath        string
	WorkingDir        string
	DefaultWorkspace  Workspace
	BootstrapSubjects []string
	DefaultMemberRole string
}

WorkspaceConfigEnsureOptions controls default workspace config bootstrapping.

type WorkspaceMembership

type WorkspaceMembership struct {
	WorkspaceID string `json:"workspace_id"`
	Subject     string `json:"subject"`
	Role        string `json:"role"`
}

WorkspaceMembership assigns a subject role inside a workspace.

Source Files

Directories

Path Synopsis
Package openapi provides primitives to interact with the openapi HTTP API.
Package openapi provides primitives to interact with the openapi HTTP API.
Package runtime starts the GUI server from explicit process options.
Package runtime starts the GUI server from explicit process options.

Jump to

Keyboard shortcuts

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