gui

package
v0.0.0-...-3293c21 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 69 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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 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(configPath string, cfg ServerAuthConfig) error

SaveServerAuthConfig validates and persists the GUI auth config in the SQLite store.

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
}

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 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) 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
	AuthMiddleware             Middleware
	APIMiddlewares             []Middleware
	SecretStore                secrets.Store
	AuthenticationService      authentication.Service
}

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(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(configPath string) (ServerAuthConfig, error)

LoadServerAuthConfig loads and validates the GUI auth config from the SQLite store.

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) 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.

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 wires the GUI command entry points to the shared server runtime.
Package runtime wires the GUI command entry points to the shared server runtime.

Jump to

Keyboard shortcuts

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