platform

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 48 Imported by: 0

Documentation

Overview

Package platform is the platform of one workspace (ADR-0021): it keeps the workspace's members, roles, permissions, invites, projects and the audit log. It runs no containers: agents do. An installation keeps exactly one workspace, made at its first start with its owner. It keeps its own accounts: sign-in (package auth) runs inside it at /auth, for the owner, the members and the invited alone (ADR-0024). It decides permissions itself.

Index

Constants

View Source
const AuthPath = "/auth"

AuthPath is where sign-in lives on the platform's address.

View Source
const InviteTTL = 7 * 24 * time.Hour

InviteTTL is how long an invite can be accepted.

Variables

Kinds are every action a policy is asked about.

Functions

func AccessOf

AccessOf is the access a method declares in proto; nil when it declares none.

Types

type Action

type Action struct {
	Kind Kind
	// Actor is the email of who acts.
	Actor string
	// Email and Role, of a member; Project and Server, of what is made.
	Email, Role     string
	Project, Server string
	Usage           Usage
}

Action is what a policy is asked: the action, who asks, and what the workspace holds before it.

type Config

type Config struct {
	// PublicURL is the server's address as clients use it. It is the audience of the
	// access tokens it accepts: a token for another server — a self-hosted one run by
	// someone else, say — does not work here, and ours not there.
	PublicURL string
	// Workspace and Owner make the workspace at the first start: its name and the email
	// of its owner, who becomes its member with the role owner when they first call. Later starts keep what
	// is there.
	Workspace, Owner string
	// Mailer sends sign-in codes and invites; the log when nil.
	Mailer mail.Mailer
	// TrustProxy takes the client's address from X-Forwarded-For (sign-in limits):
	// only behind a proxy that sets it.
	TrustProxy bool
	Log        *slog.Logger
	// Now is the clock; time.Now when nil.
	Now func() time.Time
	// Extensions are what another build adds; the core has none.
	Extensions Extensions
}

Config configures the server.

type Extensions

type Extensions struct {
	// Policy is asked before the actions an installation may limit; nil allows all.
	Policy Policy
	// Setup gives the workspace and its owner at the first start; nil takes
	// Config.Workspace and Config.Owner (the flags of devopus-server).
	Setup func(ctx context.Context) (workspace, owner string, err error)
	// Mount adds handlers to the platform's address: an API of its own, more RPC
	// (behind Service.Check). It runs once, in Handler.
	Mount func(mux *http.ServeMux, s *Service)
	// Plan is what the workspace's people see of its plan; nil shows none.
	Plan func(ctx context.Context) *workspacev1.Plan
}

Extensions are what another build of the platform adds to the core (ADR-0021): the core runs with none, and nothing in it knows what fills them.

type Kind

type Kind string

Kind is an action a policy is asked about.

const (
	// InviteMember: Email is invited with Role.
	InviteMember Kind = "member.invite"
	// JoinMember: Email accepts their invite and joins with Role.
	JoinMember Kind = "member.join"
	// CreateProject: Project is made.
	CreateProject Kind = "project.create"
	// AddServer: Server, a server of the team, is added.
	AddServer Kind = "server.add"
	// CreateEnvironment: an environment of Project on Server is made.
	CreateEnvironment Kind = "environment.create"
)

type Policy

type Policy interface {
	Allow(ctx context.Context, a Action) error
}

Policy decides whether an installation allows an action: its error, a reason a person reads, refuses it. The caller's role is checked before it.

type PolicyFunc

type PolicyFunc func(ctx context.Context, a Action) error

PolicyFunc is a Policy of a function.

func (PolicyFunc) Allow

func (f PolicyFunc) Allow(ctx context.Context, a Action) error

type Service

type Service struct {
	workspacev1connect.UnimplementedWorkspaceServiceHandler
	// contains filtered or unexported fields
}

Service is the workspace server.

func New

func New(pool *pgxpool.Pool, cfg Config) (*Service, error)

New opens the server on a migrated database.

func (*Service) Check

func (s *Service) Check() connect.HandlerOption

Check is the access check of the platform's RPC for handlers an extension mounts: their methods declare access like the core's.

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler serves the API: every call goes through the access check.

func (*Service) ListProjects

ListProjects shows every project of the workspace: a role holds in all of them.

func (*Service) ListWorkspaces

ListWorkspaces is the platform's workspace when the caller is a member of it.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run does the background work of sign-in until ctx ends: new signing keys, expired codes and sessions deleted.

func (*Service) WorkspaceID

func (s *Service) WorkspaceID() string

WorkspaceID is the id of the platform's workspace.

type Usage

type Usage struct {
	// Members are its people (not its servers); Invites, the open invites.
	Members, Invites  int
	Projects, Servers int
	Environments      int
}

Usage is what the workspace holds.

Directories

Path Synopsis
Package store is the workspace server's database: the schema (migrations), the queries (sqlc) and the migration runner.
Package store is the workspace server's database: the schema (migrations), the queries (sqlc) and the migration runner.

Jump to

Keyboard shortcuts

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