api

package
v0.0.0-...-dac86b4 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRouter

func NewRouter(stores Stores, cfg Config) http.Handler

NewRouter creates an http.Handler with all API v1 routes registered.

func NewRouterWithIAM

func NewRouterWithIAM(stores Stores, cfg Config, iamResolver *iam.IAMResolver) http.Handler

NewRouterWithIAM creates an http.Handler with all API v1 routes and optional IAM resolver.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) uuid.UUID

RequestIDFromContext extracts the request ID from context.

func RoleAtLeast

func RoleAtLeast(role, minRole store.Role) bool

RoleAtLeast returns true if role has at least the given minimum role level.

func SetRequestID

func SetRequestID(ctx context.Context, id uuid.UUID) context.Context

SetRequestID returns a new context with the request ID attached.

func SetUserContext

func SetUserContext(ctx context.Context, u *store.User) context.Context

SetUserContext returns a new context with the user attached.

func UserFromContext

func UserFromContext(ctx context.Context) *store.User

UserFromContext extracts the authenticated user from context, or nil.

func WriteError

func WriteError(w http.ResponseWriter, status int, message string)

WriteError writes a JSON error response.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data any)

WriteJSON writes a JSON response with the given status code.

func WritePaginated

func WritePaginated(w http.ResponseWriter, items any, total, page, pageSize int)

WritePaginated writes a paginated JSON response.

Types

type AuditHandler

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

AuditHandler handles audit log query endpoints.

func NewAuditHandler

func NewAuditHandler(audit store.AuditStore, permissions *PermissionService) *AuditHandler

NewAuditHandler creates a new AuditHandler.

func (*AuditHandler) Query

func (h *AuditHandler) Query(w http.ResponseWriter, r *http.Request)

Query handles GET /api/v1/companies/{id}/audit.

type AuthHandler

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

AuthHandler handles authentication endpoints.

func NewAuthHandler

func NewAuthHandler(users store.UserStore, sessions store.SessionStore, secret []byte, issuer string, accessTTL, refreshTTL time.Duration) *AuthHandler

NewAuthHandler creates a new AuthHandler.

func (*AuthHandler) Login

func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request)

Login handles POST /api/v1/auth/login.

func (*AuthHandler) Logout

func (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request)

Logout handles POST /api/v1/auth/logout.

func (*AuthHandler) Me

Me handles GET /api/v1/auth/me.

func (*AuthHandler) Refresh

func (h *AuthHandler) Refresh(w http.ResponseWriter, r *http.Request)

Refresh handles POST /api/v1/auth/refresh.

func (*AuthHandler) Register

func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request)

Register handles POST /api/v1/auth/register.

func (*AuthHandler) UpdateMe

func (h *AuthHandler) UpdateMe(w http.ResponseWriter, r *http.Request)

UpdateMe handles PUT /api/v1/auth/me.

type CompanyHandler

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

CompanyHandler handles company CRUD endpoints.

func NewCompanyHandler

func NewCompanyHandler(companies store.CompanyStore, memberships store.MembershipStore, permissions *PermissionService) *CompanyHandler

NewCompanyHandler creates a new CompanyHandler.

func (*CompanyHandler) AddMember

func (h *CompanyHandler) AddMember(w http.ResponseWriter, r *http.Request)

AddMember handles POST /api/v1/companies/{id}/members.

func (*CompanyHandler) Create

func (h *CompanyHandler) Create(w http.ResponseWriter, r *http.Request)

Create handles POST /api/v1/companies.

func (*CompanyHandler) Delete

func (h *CompanyHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /api/v1/companies/{id}.

func (*CompanyHandler) Get

Get handles GET /api/v1/companies/{id}.

func (*CompanyHandler) List

List handles GET /api/v1/companies.

func (*CompanyHandler) ListMembers

func (h *CompanyHandler) ListMembers(w http.ResponseWriter, r *http.Request)

ListMembers handles GET /api/v1/companies/{id}/members.

func (*CompanyHandler) RemoveMember

func (h *CompanyHandler) RemoveMember(w http.ResponseWriter, r *http.Request)

RemoveMember handles DELETE /api/v1/companies/{id}/members/{uid}.

func (*CompanyHandler) Update

func (h *CompanyHandler) Update(w http.ResponseWriter, r *http.Request)

Update handles PUT /api/v1/companies/{id}.

func (*CompanyHandler) UpdateMember

func (h *CompanyHandler) UpdateMember(w http.ResponseWriter, r *http.Request)

UpdateMember handles PUT /api/v1/companies/{id}/members/{uid}.

type Config

type Config struct {
	JWTSecret  string
	JWTIssuer  string
	AccessTTL  time.Duration
	RefreshTTL time.Duration

	// OAuth providers keyed by provider name (e.g. "google", "okta").
	OAuthProviders map[string]*OAuthProviderConfig
}

Config holds configuration for the API layer.

type DashboardHandler

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

DashboardHandler handles system and per-workflow dashboard endpoints.

func NewDashboardHandler

func NewDashboardHandler(
	executions store.ExecutionStore,
	logs store.LogStore,
	workflows store.WorkflowStore,
	projects store.ProjectStore,
	permissions *PermissionService,
) *DashboardHandler

NewDashboardHandler creates a new DashboardHandler.

func (*DashboardHandler) System

func (h *DashboardHandler) System(w http.ResponseWriter, r *http.Request)

System handles GET /api/v1/dashboard.

func (*DashboardHandler) Workflow

func (h *DashboardHandler) Workflow(w http.ResponseWriter, r *http.Request)

Workflow handles GET /api/v1/workflows/{id}/dashboard.

type EventsHandler

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

EventsHandler handles event inspection and streaming endpoints.

func NewEventsHandler

func NewEventsHandler(executions store.ExecutionStore, logs store.LogStore, permissions *PermissionService) *EventsHandler

NewEventsHandler creates a new EventsHandler.

func (*EventsHandler) List

func (h *EventsHandler) List(w http.ResponseWriter, r *http.Request)

List handles GET /api/v1/workflows/{id}/events - lists recent execution events.

func (*EventsHandler) Stream

func (h *EventsHandler) Stream(w http.ResponseWriter, r *http.Request)

Stream handles GET /api/v1/workflows/{id}/events/stream (SSE).

type ExecutionHandler

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

ExecutionHandler handles execution tracking endpoints.

func NewExecutionHandler

func NewExecutionHandler(executions store.ExecutionStore, workflows store.WorkflowStore, permissions *PermissionService) *ExecutionHandler

NewExecutionHandler creates a new ExecutionHandler.

func (*ExecutionHandler) Cancel

func (h *ExecutionHandler) Cancel(w http.ResponseWriter, r *http.Request)

Cancel handles POST /api/v1/executions/{id}/cancel.

func (*ExecutionHandler) Get

Get handles GET /api/v1/executions/{id}.

func (*ExecutionHandler) List

List handles GET /api/v1/workflows/{id}/executions.

func (*ExecutionHandler) Steps

Steps handles GET /api/v1/executions/{id}/steps.

func (*ExecutionHandler) Trigger

func (h *ExecutionHandler) Trigger(w http.ResponseWriter, r *http.Request)

Trigger handles POST /api/v1/workflows/{id}/trigger.

type IAMHandler

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

IAMHandler handles IAM provider and role mapping endpoints.

func NewIAMHandler

func NewIAMHandler(iamStore store.IAMStore, resolver *iam.IAMResolver, permissions *PermissionService) *IAMHandler

NewIAMHandler creates a new IAMHandler.

func (*IAMHandler) CreateMapping

func (h *IAMHandler) CreateMapping(w http.ResponseWriter, r *http.Request)

CreateMapping handles POST /api/v1/iam/providers/{id}/mappings.

func (*IAMHandler) CreateProvider

func (h *IAMHandler) CreateProvider(w http.ResponseWriter, r *http.Request)

CreateProvider handles POST /api/v1/companies/{id}/iam/providers.

func (*IAMHandler) DeleteMapping

func (h *IAMHandler) DeleteMapping(w http.ResponseWriter, r *http.Request)

DeleteMapping handles DELETE /api/v1/iam/mappings/{id}.

func (*IAMHandler) DeleteProvider

func (h *IAMHandler) DeleteProvider(w http.ResponseWriter, r *http.Request)

DeleteProvider handles DELETE /api/v1/iam/providers/{id}.

func (*IAMHandler) GetProvider

func (h *IAMHandler) GetProvider(w http.ResponseWriter, r *http.Request)

GetProvider handles GET /api/v1/iam/providers/{id}.

func (*IAMHandler) ListMappings

func (h *IAMHandler) ListMappings(w http.ResponseWriter, r *http.Request)

ListMappings handles GET /api/v1/iam/providers/{id}/mappings.

func (*IAMHandler) ListProviders

func (h *IAMHandler) ListProviders(w http.ResponseWriter, r *http.Request)

ListProviders handles GET /api/v1/companies/{id}/iam/providers.

func (*IAMHandler) TestConnection

func (h *IAMHandler) TestConnection(w http.ResponseWriter, r *http.Request)

TestConnection handles POST /api/v1/iam/providers/{id}/test.

func (*IAMHandler) UpdateProvider

func (h *IAMHandler) UpdateProvider(w http.ResponseWriter, r *http.Request)

UpdateProvider handles PUT /api/v1/iam/providers/{id}.

type LinkHandler

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

LinkHandler handles cross-workflow link endpoints.

func NewLinkHandler

func NewLinkHandler(links store.CrossWorkflowLinkStore, workflows store.WorkflowStore) *LinkHandler

NewLinkHandler creates a new LinkHandler.

func (*LinkHandler) Create

func (h *LinkHandler) Create(w http.ResponseWriter, r *http.Request)

Create handles POST /api/v1/workflows/{id}/links.

func (*LinkHandler) Delete

func (h *LinkHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /api/v1/workflows/{id}/links/{linkId}.

func (*LinkHandler) List

func (h *LinkHandler) List(w http.ResponseWriter, r *http.Request)

List handles GET /api/v1/workflows/{id}/links.

type LogHandler

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

LogHandler handles log query and streaming endpoints.

func NewLogHandler

func NewLogHandler(logs store.LogStore, permissions *PermissionService) *LogHandler

NewLogHandler creates a new LogHandler.

func (*LogHandler) Query

func (h *LogHandler) Query(w http.ResponseWriter, r *http.Request)

Query handles GET /api/v1/workflows/{id}/logs.

func (*LogHandler) Stream

func (h *LogHandler) Stream(w http.ResponseWriter, r *http.Request)

Stream handles GET /api/v1/workflows/{id}/logs/stream (SSE).

type Middleware

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

Middleware holds dependencies needed by authentication middleware.

func NewMiddleware

func NewMiddleware(jwtSecret []byte, users store.UserStore, permissions *PermissionService) *Middleware

NewMiddleware creates a new Middleware.

func (*Middleware) OptionalAuth

func (m *Middleware) OptionalAuth(next http.Handler) http.Handler

OptionalAuth is like RequireAuth but does not fail when no token is present.

func (*Middleware) RequireAuth

func (m *Middleware) RequireAuth(next http.Handler) http.Handler

RequireAuth validates the JWT Bearer token and loads the user into context. Returns 401 if the token is missing, invalid, or the user cannot be found.

func (*Middleware) RequireRole

func (m *Middleware) RequireRole(minRole store.Role, resourceType, idKey string) func(http.Handler) http.Handler

RequireRole returns middleware that checks the authenticated user has at least minRole on the resource identified by resourceType and the path parameter idKey.

type OAuthHandler

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

OAuthHandler handles OAuth2 login flows.

func NewOAuthHandler

func NewOAuthHandler(users store.UserStore, providers map[string]*OAuthProviderConfig, secret []byte, issuer string, accessTTL, refreshTTL time.Duration) *OAuthHandler

NewOAuthHandler creates a new OAuthHandler.

func (*OAuthHandler) Authorize

func (h *OAuthHandler) Authorize(w http.ResponseWriter, r *http.Request)

Authorize handles GET /api/v1/auth/oauth2/{provider}. Generates a state parameter, stores it in a cookie, and redirects.

func (*OAuthHandler) Callback

func (h *OAuthHandler) Callback(w http.ResponseWriter, r *http.Request)

Callback handles GET /api/v1/auth/oauth2/{provider}/callback.

type OAuthProviderConfig

type OAuthProviderConfig struct {
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	RedirectURL  string   `json:"redirect_url"`
	Scopes       []string `json:"scopes"`
	AuthURL      string   `json:"auth_url"`
	TokenURL     string   `json:"token_url"`
	UserInfoURL  string   `json:"user_info_url"`
}

OAuthProviderConfig describes one OAuth2 provider.

type OrgHandler

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

OrgHandler handles organization CRUD endpoints. Organizations are companies nested under a parent company. The store treats Company and Organization as the same type.

func NewOrgHandler

func NewOrgHandler(companies store.CompanyStore, memberships store.MembershipStore, permissions *PermissionService) *OrgHandler

NewOrgHandler creates a new OrgHandler.

func (*OrgHandler) Create

func (h *OrgHandler) Create(w http.ResponseWriter, r *http.Request)

Create handles POST /api/v1/companies/{cid}/organizations.

func (*OrgHandler) Delete

func (h *OrgHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /api/v1/organizations/{id}.

func (*OrgHandler) Get

func (h *OrgHandler) Get(w http.ResponseWriter, r *http.Request)

Get handles GET /api/v1/organizations/{id}.

func (*OrgHandler) List

func (h *OrgHandler) List(w http.ResponseWriter, r *http.Request)

List handles GET /api/v1/companies/{cid}/organizations.

func (*OrgHandler) Update

func (h *OrgHandler) Update(w http.ResponseWriter, r *http.Request)

Update handles PUT /api/v1/organizations/{id}.

type PermissionService

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

PermissionService resolves effective permissions across the resource hierarchy.

func NewPermissionService

func NewPermissionService(memberships store.MembershipStore, workflows store.WorkflowStore, projects store.ProjectStore) *PermissionService

NewPermissionService creates a new PermissionService.

func (*PermissionService) CanAccess

func (ps *PermissionService) CanAccess(ctx context.Context, userID uuid.UUID, resourceType string, resourceID uuid.UUID, minRole store.Role) bool

CanAccess returns true if the user has at least minRole on the given resource.

func (*PermissionService) GetEffectiveRole

func (ps *PermissionService) GetEffectiveRole(ctx context.Context, userID uuid.UUID, resourceType string, resourceID uuid.UUID) (store.Role, error)

GetEffectiveRole resolves the cascading effective role for a user on a resource. Cascade: workflow_permissions -> project_memberships -> company_memberships.

type ProjectHandler

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

ProjectHandler handles project CRUD and member endpoints.

func NewProjectHandler

func NewProjectHandler(projects store.ProjectStore, companies store.CompanyStore, memberships store.MembershipStore, permissions *PermissionService) *ProjectHandler

NewProjectHandler creates a new ProjectHandler.

func (*ProjectHandler) AddMember

func (h *ProjectHandler) AddMember(w http.ResponseWriter, r *http.Request)

AddMember handles POST /api/v1/projects/{id}/members.

func (*ProjectHandler) Create

func (h *ProjectHandler) Create(w http.ResponseWriter, r *http.Request)

Create handles POST /api/v1/organizations/{oid}/projects.

func (*ProjectHandler) Delete

func (h *ProjectHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /api/v1/projects/{id}.

func (*ProjectHandler) Get

Get handles GET /api/v1/projects/{id}.

func (*ProjectHandler) List

List handles GET /api/v1/organizations/{oid}/projects.

func (*ProjectHandler) ListMembers

func (h *ProjectHandler) ListMembers(w http.ResponseWriter, r *http.Request)

ListMembers handles GET /api/v1/projects/{id}/members.

func (*ProjectHandler) Update

func (h *ProjectHandler) Update(w http.ResponseWriter, r *http.Request)

Update handles PUT /api/v1/projects/{id}.

type Stores

type Stores struct {
	Users       store.UserStore
	Sessions    store.SessionStore
	Companies   store.CompanyStore
	Projects    store.ProjectStore
	Workflows   store.WorkflowStore
	Memberships store.MembershipStore
	Links       store.CrossWorkflowLinkStore
	Executions  store.ExecutionStore
	Logs        store.LogStore
	Audit       store.AuditStore
	IAM         store.IAMStore
}

Stores groups all store interfaces needed by the API.

type WorkflowHandler

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

WorkflowHandler handles workflow CRUD and lifecycle endpoints.

func NewWorkflowHandler

func NewWorkflowHandler(workflows store.WorkflowStore, projects store.ProjectStore, memberships store.MembershipStore, permissions *PermissionService) *WorkflowHandler

NewWorkflowHandler creates a new WorkflowHandler.

func (*WorkflowHandler) Create

func (h *WorkflowHandler) Create(w http.ResponseWriter, r *http.Request)

Create handles POST /api/v1/projects/{pid}/workflows.

func (*WorkflowHandler) Delete

func (h *WorkflowHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /api/v1/workflows/{id}.

func (*WorkflowHandler) Deploy

func (h *WorkflowHandler) Deploy(w http.ResponseWriter, r *http.Request)

Deploy handles POST /api/v1/workflows/{id}/deploy.

func (*WorkflowHandler) Get

Get handles GET /api/v1/workflows/{id}.

func (*WorkflowHandler) GetVersion

func (h *WorkflowHandler) GetVersion(w http.ResponseWriter, r *http.Request)

GetVersion handles GET /api/v1/workflows/{id}/versions/{v}.

func (*WorkflowHandler) ListAll

func (h *WorkflowHandler) ListAll(w http.ResponseWriter, r *http.Request)

ListAll handles GET /api/v1/workflows (all accessible workflows).

func (*WorkflowHandler) ListInProject

func (h *WorkflowHandler) ListInProject(w http.ResponseWriter, r *http.Request)

ListInProject handles GET /api/v1/projects/{pid}/workflows.

func (*WorkflowHandler) ListPermissions

func (h *WorkflowHandler) ListPermissions(w http.ResponseWriter, r *http.Request)

ListPermissions handles GET /api/v1/workflows/{id}/permissions.

func (*WorkflowHandler) ListVersions

func (h *WorkflowHandler) ListVersions(w http.ResponseWriter, r *http.Request)

ListVersions handles GET /api/v1/workflows/{id}/versions.

func (*WorkflowHandler) SetPermission

func (h *WorkflowHandler) SetPermission(w http.ResponseWriter, r *http.Request)

SetPermission handles POST /api/v1/workflows/{id}/permissions.

func (*WorkflowHandler) Status

func (h *WorkflowHandler) Status(w http.ResponseWriter, r *http.Request)

Status handles GET /api/v1/workflows/{id}/status.

func (*WorkflowHandler) Stop

Stop handles POST /api/v1/workflows/{id}/stop.

func (*WorkflowHandler) Update

func (h *WorkflowHandler) Update(w http.ResponseWriter, r *http.Request)

Update handles PUT /api/v1/workflows/{id}.

Jump to

Keyboard shortcuts

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