Documentation
¶
Overview ¶
Package docs is the hub's side of documents and boards (docs/hub/docs.md): the page's document API (<platform api>/docs), which the web core calls, and the agents' doc.publish and doc.acl, which the machine's agent sends over its link. The documents themselves live in the documents service (github.com/ly-solutions/artifacts), the boards in the boards service; the hub keeps what neither has: who owns a document and who else may open it, the comment threads and what each person has read.
It is switched on by HUB_DOCS. Without the flag, or without the address and token of the documents service, every route answers 503 with {error, code: "docs_not_configured", reason} and the page says what is missing.
Index ¶
- Constants
- Variables
- func LegacyRedirect(publicURL string) http.Handler
- func ProbeReady(ctx context.Context, hc *http.Client, base string) error
- type Bell
- type Deps
- type Gate
- type Linker
- type Notice
- type Reply
- type Service
- func (s *Service) Deliver(commentID string)
- func (s *Service) Event(l *link.Link, m store.Machine, ev link.Event)
- func (s *Service) Handle(ctx context.Context, who Who, kind string, raw json.RawMessage) (rid string, rep Reply, ok bool)
- func (s *Service) Handler() http.Handler
- func (s *Service) Mount(mux *http.ServeMux)
- func (s *Service) Prefix() string
- func (s *Service) Run(ctx context.Context)
- func (s *Service) RunHealth(ctx context.Context)
- func (s *Service) RunSweep(ctx context.Context)
- func (s *Service) Services() map[string]ServiceHealth
- func (s *Service) Status() Status
- type ServiceHealth
- type Status
- type Who
Constants ¶
const ( ServiceDocuments = "documents" ServiceBoards = "boards" )
The services the hub probes, as the status names them.
const ( RightNone = "none" RightView = "view" RightComment = "comment" RightEdit = "edit" )
Rights a person has on a document, as the service is told.
const SwitchBoardEvents = "hub-board-events"
SwitchBoardEvents is the rollout switch (docs/hub/rollout-switches.md) that makes the hub take the events of the boards a person drew; for the others the hub passes them on or drops them.
Variables ¶
var ErrNoReadyz = errors.New("the address does not route /readyz")
ErrNoReadyz: the address answered 404 to /readyz. The service itself is not said to be down: the address only does not route that path (a public host that shows one prefix of the service is the usual case), so the answer tells nothing about the service. The status leaves such a service out and nobody is mailed; the doctor still reports it.
Functions ¶
func LegacyRedirect ¶
LegacyRedirect answers the old document address, /a/<slug> (HUB_DOCS_LEGACY_HOSTS), with a permanent redirect to the document's page in the hub's workspace. It serves no content: whether the person may read the document is decided there, by their sign-in and the document's own access, as for any link to it. Anything but /a/<slug> is 404.
Types ¶
type Bell ¶
Bell rings one hub user's bell: a notice without a chat, with a link; it reports whether the notice was put.
type Deps ¶
type Deps struct {
Config *config.Config
DB *store.DB
Auth *auth.Service
Log *slog.Logger
Now func() time.Time
// LinkKey is the hub's own secret: the address of a resource's general link is kept sealed with a key derived
// from it, so the share dialog can copy it again; nil keeps no address.
LinkKey []byte
// Links hands comments to the machines' conversations; nil keeps them on the hub.
Links Linker
// HTTP reaches the documents and boards services; nil: a client with a 30 second timeout.
HTTP *http.Client
// Notice tells a person by mail that they were mentioned; nil: nobody is told.
Notice Notice
// Gate says whether the rollout switch of the comments on boards is on for a person (boards.go); nil: off for everyone.
Gate Gate
// Bell rings a person's bell for a mention on a board (board_mentions.go); nil: nobody is told.
Bell Bell
// AppToken checks the platform's token of a person for an app's backend (the hub's signature, issuer, the audience
// given and the expiry) and answers whose it is; nil: a service cannot act for a person (manage.go).
AppToken func(token, audience string) (sub string, err error)
}
Deps are what the service needs from the hub.
type Linker ¶
type Linker interface {
Get(machineID string) *link.Link
Do(ctx context.Context, machineID, op string, params any, timeout time.Duration) (json.RawMessage, error)
}
Linker is the part of the machines' link registry delivery needs.
type Reply ¶
Reply is what the hub answers an agent's doc.publish or doc.acl: the agent turns it into the tool result.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service serves documents and boards.
func (*Service) Deliver ¶
Deliver hands a person's new comment to the conversation of its document, in the background.
func (*Service) Event ¶
Event takes the doc.publish and doc.acl events of a machine's link and answers each with the op doc.result. It returns at once; the answer is sent from a goroutine.
func (*Service) Handle ¶
func (s *Service) Handle(ctx context.Context, who Who, kind string, raw json.RawMessage) (rid string, rep Reply, ok bool)
Handle answers one event of an agent; ok is false for an event that is not this package's. Without documents set up the agent gets a 503 it can show, never silence.
func (*Service) Handler ¶
Handler answers the documents' routes alone, for the workspace (/agents/api/…) to hand them over; nil when the hub keeps no documents (HUB_DOCS off). Prefix is where those routes live.
func (*Service) Run ¶
Run probes the documents and boards services (health.go) and tries the comments not yet handed over again every minute until ctx ends, and gives up on those older than a day.
func (*Service) RunHealth ¶
RunHealth probes the documents and boards services until ctx ends (every replica keeps its own view of them).
func (*Service) RunSweep ¶
RunSweep tries the comments not yet handed over again every minute until ctx ends: with several replicas only the leader does it (docs/hub/replicas.md). It also sends the documents service the trash it has not confirmed yet (trashsync.go), at start and every minute.
func (*Service) Services ¶
func (s *Service) Services() map[string]ServiceHealth
Services is the last known health of each probed service; a service not probed yet is absent.
type ServiceHealth ¶
type ServiceHealth struct {
Up bool `json:"up"`
Since time.Time `json:"since"`
CheckedAt time.Time `json:"checkedAt"`
}
ServiceHealth is the last answer of one service. Since is when it last went up or down.
type Status ¶
type Status struct {
Enabled bool `json:"enabled"`
Documents bool `json:"documents"`
Boards bool `json:"boards"`
Reason string `json:"reason,omitempty"`
Text string `json:"text,omitempty"`
// Services is whether each configured service answers its /readyz (ServiceDocuments, ServiceBoards); a service not
// asked yet is absent, and the page then takes it for up.
Services map[string]ServiceHealth `json:"services,omitempty"`
}
Status says whether documents work and, when they do not, why. Reason is a code the page can match; Text is a sentence for the person.