manager

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 49 Imported by: 0

Documentation

Overview

Package manager — connectors_api_account.go: the per-connected-account read model and its one mutation.

Purpose: An account is its own thing to administer, not a sub-row of the instance page. It has operations that may differ from the instance's, a history of what it actually did, a Test runner pinned to its identity, and the two lifecycle actions (re-connect, disconnect). This file serves exactly that, so a person who may not configure the instance still has a page for the account that is theirs.

Caller: the manager SPA's AccountDetail page Dependencies: connectors.Service (accounts, op states, overrides) Main Functions:

  • apiAccountDetail() — GET the account + its resolved operations
  • apiSetAccountOpOverride() — POST one operation's inherit/on/off state

Side Effects: the POST writes the account's override map.

Package manager — connectors_api_admin.go: JSON twins of the per-row admin controls that previously lived only on the form-post templ pages (rate limit, duplicate, access policy, session config, operation toggles, and account management). Each handler reuses the same service calls + permission gates as its templ sibling in connectors.go — the only difference is JSON in/out instead of form-post + redirect, so the manager SPA can drive them without a page reload.

Package manager — oauth.go: Generic connector OAuth 2.0 flow handler.

Purpose: Implements the two-leg OAuth 2.0 flow for any connector that has Module.OAuth set to a non-nil *connector.OAuthMeta. Routes are registered under /manager/connectors/{key}/oauth/* so the Redirect URI is always /manager/connectors/{key}/oauth/callback.

Caller: Handler.connectorRoutes() (public, not behind auth middleware) Dependencies: connector.OAuthMeta, configs.Service, connectors.Service Main Functions:

  • oauthRoutes() — registers start + callback routes (public)
  • oauthStart() — builds state, redirects to provider consent page
  • oauthCallback() — validates state, exchanges code, saves token
  • oauthSaveToken() — persists xoxp/access token to connector row
  • migrateOAuthAppToInstances() — one-shot boot migration: copies shared connector_oauth:{key} credentials into every instance row that has not yet been configured.

Storage:

  • Per-instance OAuth credentials: connector row configs (client_id, client_secret)
  • Legacy shared credentials: configs owner "connector_oauth:{key}" (migrated away)
  • Pending states: Handler.oauthPending (sync.Map, 10-min TTL)

Side Effects: writes access token to connector row via connectors.Service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstalledHealth added in v1.2.9

func InstalledHealth(probe func(kind, key string) (bool, string)) source.HealthFunc

InstalledHealth is the default step-6 check: the installed binary still verifies against its manifest, plus whatever runtime probe the caller adds (service plugins: supervisor state).

func SPAMount added in v0.22.2

func SPAMount() (assetURL, base string)

SPAMount exposes the manager SPA's entry bundle URL and client-side route base so another host (e.g. the Agents shell) can render the same SPA inside its own chrome without duplicating the embed/asset wiring. Assets keep loading from the manager asset handler at spaAssetBase and the client router keeps its /manager base, so every in-SPA API call and internal navigation resolves against the live /manager/* routes. The host is just a different outer shell around the same #app div.

Types

type Handler

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

Handler wires the /manager/* routes. Manager owns job scheduling, runtime configs for jobs and tools, and the admin surface for connector rows.

func NewHandler

func NewHandler(svc *Service, configsSvc *configs.Service, connectorsSvc *connectors.Service, tagsSvc *tags.Service, usersSvc *login.Service, tools []tool.Tool) *Handler

func (*Handler) Register

func (h *Handler) Register(mux *http.ServeMux, authMidd *login.Middleware)

Register wires /manager/* to mux. All pages require auth; admin-only actions (edits, regenerate, run) add RequireAdmin on top.

func (*Handler) RegisterConfigDecorator added in v0.9.0

func (h *Handler) RegisterConfigDecorator(toolKey string, fn func([]entity.Config) []entity.Config)

RegisterConfigDecorator registers a function that is called on the config rows for toolKey just before the manager detail page is rendered. Use it to inject dynamic Options (e.g. workspace names) into specific rows.

func (*Handler) SetCustomConnectors added in v0.17.0

func (h *Handler) SetCustomConnectors(svc *customconn.Service)

SetCustomConnectors late-binds the custom-connector service. The builder routes under /manager/connectors/custom/* render only when this is non-nil; the connectors index additionally shows the "+ New connector" dropdown and the "Custom" card badges.

func (*Handler) SetPluginResolver added in v0.26.0

func (h *Handler) SetPluginResolver(r pluginIdentityResolver)

SetPluginResolver wires the connector plugin manager so the OAuth callback can resolve token owners for plugin-backed connectors. Call only with a non-nil resolver to avoid the typed-nil-interface trap.

func (*Handler) WithWebhookRoutes added in v1.2.9

func (h *Handler) WithWebhookRoutes(routes []tool.WebhookRoute) *Handler

WithWebhookRoutes records the webhook endpoints tools declared at boot. Called once from server.go after the tool router has collected them; returns h so it can be chained onto NewHandler.

type PluginSourcesHandler added in v1.2.9

type PluginSourcesHandler struct {
	Sources *source.Manager
	// Health reports runtime health of an installed key (step 6 of Test).
	Health source.HealthFunc
}

PluginSourcesHandler serves Admin → Plugins: sources (url / GitHub), the Available list they offer, zip upload, the six-step Test, Check now, and the per-plugin source status the detail pages use for the "Update available" badge. Reading is open to any logged-in user; every action is admin-only. A source's PAT is write-only — responses only say has_pat.

func (*PluginSourcesHandler) RegisterRoutes added in v1.2.9

func (h *PluginSourcesHandler) RegisterRoutes(mux *http.ServeMux, authMidd *login.Middleware)

RegisterRoutes wires /manager/api/plugin-sources and the upload endpoint.

type PluginsHandler added in v0.26.0

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

func NewPluginsHandler added in v0.26.0

func NewPluginsHandler(db *gorm.DB) *PluginsHandler

NewPluginsHandler builds the marketplace handler. db backs the enable/disable overlay; dir is the installed-plugins directory (connplugin.DefaultDir()).

func (*PluginsHandler) RegisterRoutes added in v0.26.0

func (h *PluginsHandler) RegisterRoutes(mux *http.ServeMux, authMidd *login.Middleware)

RegisterRoutes wires the marketplace endpoints under /manager/api/plugins. Listing is readable by any logged-in user (mirrors built-in connectors: everyone can browse, only admins can act). The state-changing actions — install / update / enable / disable / remove — stay admin-only.

func (*PluginsHandler) SetReloader added in v0.27.0

func (h *PluginsHandler) SetReloader(r reconciler) *PluginsHandler

SetReloader wires the hot-reload poller so state-changing actions reconcile immediately. Safe to leave unset — reload() then does nothing.

func (*PluginsHandler) SetReplaceRefresh added in v1.2.9

func (h *PluginsHandler) SetReplaceRefresh(fn func(ctx context.Context, owner string, rows ...pkgentity.Config) error) *PluginsHandler

SetReplaceRefresh wires the configs-cache refresh the replace endpoint calls after an apply, so copied values are live without a restart.

func (*PluginsHandler) SetSources added in v1.2.9

SetSources routes updates of source-installed plugins to their source.

func (*PluginsHandler) SetUninstall added in v1.2.9

func (h *PluginsHandler) SetUninstall(unload func(ctx context.Context, kind, key string), builtin func(key string) bool) *PluginsHandler

SetUninstall wires what Uninstall needs beyond deleting files: unload stops the running plugin first, builtin guards built-in keys.

type Service

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

Service manages job lifecycle: bootstrap from code-defined jobs, manual/scheduled execution, and result storage.

func NewService

func NewService(r *repo) *Service

func NewServiceFromDB

func NewServiceFromDB(db *gorm.DB) *Service

NewServiceFromDB is a convenience constructor for callers that only have a *gorm.DB (e.g. the worker process and the web server).

func (*Service) Bootstrap

func (s *Service) Bootstrap(ctx context.Context, mods []job.Module) error

Bootstrap syncs code-defined jobs with the jobs table. New jobs get a row with their default cron; existing rows keep admin-managed fields. One module registration = one row.

func (*Service) CancelJob added in v0.14.0

func (s *Service) CancelJob(ctx context.Context, key string) error

CancelJob stops a running job by key. It cancels the in-process run when this process owns one, then closes the books either way: open run rows become "cancelled" and last_status flips to idle. Called on a job whose row is stale (DB says running, nothing actually is) it repairs the row instead of failing, so Cancel is also the operator's unstick button. Errors only when the job is idle everywhere.

The context cancel is best-effort by nature: a RunFunc that ignores its context keeps executing until its timeout, but the DB no longer calls the job running, its row can't block future triggers, and any late finalize is guarded (FinishRun / SetIdleIfNoOpenRun) so it can't resurrect the cancelled state.

func (*Service) GetJob

func (s *Service) GetJob(ctx context.Context, key string) (*entity.Job, error)

func (*Service) GetRun

func (s *Service) GetRun(ctx context.Context, runID string) (*entity.JobRun, error)

func (*Service) ListEnabledJobs

func (s *Service) ListEnabledJobs(ctx context.Context) ([]entity.Job, error)

func (*Service) ListJobs

func (s *Service) ListJobs(ctx context.Context) ([]entity.Job, error)

func (*Service) ListRuns

func (s *Service) ListRuns(ctx context.Context, key string, limit int) ([]entity.JobRun, error)

func (*Service) ResetStuckForJob added in v0.14.6

func (s *Service) ResetStuckForJob(ctx context.Context, j *entity.Job) (bool, error)

ResetStuckForJob exposes the per-job stuck-run sweep so the worker tick can call it inline while iterating its enabled-jobs list. See repo.ResetStuckForJob for the conditions a run must meet to be classified as stuck.

func (*Service) RunCron

func (s *Service) RunCron(ctx context.Context, key string) (string, error)

RunCron triggers a job run initiated by the scheduler.

func (*Service) RunManual

func (s *Service) RunManual(ctx context.Context, key string, userID string) (string, error)

RunManual triggers a job run initiated by a user. Returns the run ID.

func (*Service) RunningCount added in v1.2.9

func (s *Service) RunningCount() int

RunningCount is how many job runs this process owns right now.

func (*Service) RunningKeys added in v1.2.9

func (s *Service) RunningKeys() []string

RunningKeys names the jobs currently running, so a drain log says which one is holding things up.

func (*Service) SetConfigReader

func (s *Service) SetConfigReader(c cfgReader)

SetConfigReader installs the configs-service view used to build a job.Ctx on every run. Called by wick at boot after both services have been constructed. Safe to skip in tests — Run() then sees a no-op Ctx where every Cfg(...) read returns "".

func (*Service) SetHidden added in v1.2.9

func (s *Service) SetHidden(fn func(key string) bool)

SetHidden installs the predicate for job keys replaced by another job (see internal/plugins/replace). Their rows drop out of ListJobs and ListEnabledJobs, so the scheduler never runs them next to the new job.

func (*Service) UpdateSchedule

func (s *Service) UpdateSchedule(ctx context.Context, key string, schedule string, enabled bool, maxRuns int, maxTimeoutMin int) error

Directories

Path Synopsis
templ: version: v0.3.1020
templ: version: v0.3.1020
type
templ: version: v0.3.1020
templ: version: v0.3.1020

Jump to

Keyboard shortcuts

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