Documentation
¶
Overview ¶
Package gofleetresources holds the one shape in which every fleet service prints a resource: its conditions, the identifiers that other stores join on, and the parser for a resource's name.
The types follow JSON Schemas that the fleet library, terminal-library-fleet, owns. The module embeds a byte copy of each in SchemaCopies. The constants for each condition status, condition type, reason and identifier are generated from those copies.
A reader parses a name against the collections that the collections schema declares:
collections := gofleetresources.DeclaredCollections()
name, err := gofleetresources.ParseName("github/datapointchris/slate/pulls/412", collections)
if err != nil {
return err // a *NameError, naming the grammar and an example of each nearby collection
}
name.Service() // "github"
name.ID() // "412"
name.Segment("repo") // "slate", true
name.APIPath() // "/repos/datapointchris/slate/pulls/412", true
Index ¶
- Constants
- Variables
- type Collection
- type Collections
- type Condition
- type ConditionReason
- type ConditionReasonDefinition
- type ConditionStatus
- type ConditionType
- type ConditionTypeDefinition
- type Identifier
- type IdentifierDefinition
- type IdentifierValue
- type Metadata
- type Name
- type NameError
- type Relation
- type Resource
- type Status
Constants ¶
const ( ResourceShapeSchemaFile = "resource-shape-schema.json" ResourceConditionTypesSchemaFile = "resource-condition-types-schema.json" ServiceResourceCollectionsSchemaFile = "service-resource-collections-schema.json" )
The file names of the schema copies that SchemaCopies holds. Each is a byte copy of the file of the same name in the fleet library, terminal-library-fleet, and keeps that file's $id.
const MediaType = "application/vnd.fleet.resource+json"
MediaType is what a client names in Accept to have a service answer with a resource, and the Content-Type of that answer. A request that names another media type gets the route's own shape, so a client that never asks keeps reading what it always read.
const NameGrammar = "<service>/<collection>/<id>, with the id percent-encoded as one path segment"
NameGrammar is the form of every resource name, apart from a vendor's collection, which declares its own pattern.
const SchemaVersion = 1
SchemaVersion is the version of resource-shape-schema.json that a Resource prints in.
Variables ¶
var SchemaCopies embed.FS
SchemaCopies holds the module's schema copies, by the file names above. A service's test validates a resource it serves against the shape copy here, and DeclaredCollections reads the collections copy.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection struct {
// Key is the collection's $defs key, such as slate-records.
Key string
Description string
// Service is the service that serves the collection, such as slate or github.
Service string
// Kinds names the resource kinds that the collection holds.
Kinds []string
// Pattern is the regular expression that every name in the collection matches.
Pattern string
// NameTemplate names each segment of the collection's names, as an RFC 6570 template such as
// github/{owner}/{repo}/pulls/{id}.
NameTemplate string
// APIPath is the route at which the service serves one resource, such as
// /api/v1/records/{id}. It is empty where the service serves no route of its own for one.
APIPath string
// Contract is the catalog contract that each resource in the collection holds to.
Contract string
// Identifier is the identifier that the collection's id is.
Identifier Identifier
Examples []string
// contains filtered or unexported fields
}
Collection is one collection of resources that a service serves by name, as one $defs entry of service-resource-collections-schema.json declares it.
func (Collection) Name ¶
func (c Collection) Name(values map[string]string) (Name, error)
Name builds the name of the resource in the collection whose template variables take values, such as {"id": "4048"}, percent-encoding each value as one segment. It refuses values that leave a variable empty or name one that the template lacks. It also refuses a name that fails the collection's pattern.
func (Collection) WholeName ¶ added in v0.4.0
func (c Collection) WholeName() (string, bool)
WholeName returns the name of the collection as a whole, such as slate/records: its name template less the {id} segment that ends it. It returns false where another variable precedes the id, as in github/{owner}/{repo}/pulls/{id}, because such a collection has a whole name for each value of that variable rather than one.
type Collections ¶
type Collections struct {
// contains filtered or unexported fields
}
Collections is the set of collections that one copy of service-resource-collections-schema.json declares. ParseCollections and DeclaredCollections build it.
func DeclaredCollections ¶
func DeclaredCollections() Collections
DeclaredCollections returns the collections in the module's copy of service-resource-collections-schema.json. The module's tests read that copy, so a release whose copy does not parse is never cut, and DeclaredCollections panics only where one was.
func ParseCollections ¶
func ParseCollections(schema []byte) (Collections, error)
ParseCollections reads every collection that schema declares, in the order of its oneOf. schema is a copy of service-resource-collections-schema.json. It refuses a collection that lacks a pattern, a service or a name template, and one whose examples do not each parse by its own pattern and template alone.
func (Collections) All ¶
func (c Collections) All() []Collection
All returns every collection, in the order of the schema's oneOf.
func (Collections) Lookup ¶
func (c Collections) Lookup(key string) (Collection, bool)
Lookup returns the collection whose $defs key is key, and false where none is.
func (Collections) LookupWholeName ¶ added in v0.4.0
func (c Collections) LookupWholeName(raw string) (Collection, bool)
LookupWholeName returns the collection whose whole name is raw, such as slate/records, and false where no collection's is. A reader that takes a collection or one of its resources, such as a follower of either, tries it before ParseName.
type Condition ¶
type Condition struct {
Type ConditionType `json:"type"`
Status ConditionStatus `json:"status"`
Reason ConditionReason `json:"reason"`
// Message is the reason's detail for a person, such as the records a dependency waits on.
Message string `json:"message,omitempty"`
}
Condition is one condition that a service derives on every read, as resource-shape-schema.json gives a condition. resource-condition-types-schema.json lists each type and its reasons, and ConditionTypeDefinitions reads that list.
type ConditionReason ¶
type ConditionReason string
ConditionReason is why a condition's status is what it is, one of the reasons its type lists.
const ( // ReadyReasonClosed: The issue is completed or canceled. ReadyReasonClosed ConditionReason = "Closed" // ReadyReasonIncoming: The issue is still in triage. ReadyReasonIncoming ConditionReason = "Incoming" // ReadyReasonInitiativeShelved: Its initiative is someday. ReadyReasonInitiativeShelved ConditionReason = "InitiativeShelved" // ReadyReasonDependencyOpen: An issue it depends on is open. ReadyReasonDependencyOpen ConditionReason = "DependencyOpen" // ReadyReasonInitiativeWaits: Its initiative waits on an open record. ReadyReasonInitiativeWaits ConditionReason = "InitiativeWaits" // ReadyReasonChildrenOpen: A child issue is open. ReadyReasonChildrenOpen ConditionReason = "ChildrenOpen" // ReadyReasonDeferred: Its deferred-until date is ahead. ReadyReasonDeferred ConditionReason = "Deferred" // ReadyReasonClaimed: A live claim holds it. ReadyReasonClaimed ConditionReason = "Claimed" // ReadyReasonNothingBlocks: None of the reasons above holds, so the issue can start. ReadyReasonNothingBlocks ConditionReason = "NothingBlocks" )
The reasons that the Ready condition type lists, in its order.
const ( // HeldReasonLiveClaim: A live claim holds the record, and the message names its holder. HeldReasonLiveClaim ConditionReason = "LiveClaim" // HeldReasonNoClaim: No live claim holds the record. HeldReasonNoClaim ConditionReason = "NoClaim" )
The reasons that the Held condition type lists, in its order.
const ( // StillHoldsReasonHolds: The latest check found that the record still describes work to do. StillHoldsReasonHolds ConditionReason = "Holds" // StillHoldsReasonCorrected: The latest check found that the record describes work to do once what // was wrong in it is rewritten. StillHoldsReasonCorrected ConditionReason = "Corrected" // StillHoldsReasonDone: The latest check found the work already done. StillHoldsReasonDone ConditionReason = "Done" // StillHoldsReasonGone: The latest check found that what the record describes no longer exists. StillHoldsReasonGone ConditionReason = "Gone" // StillHoldsReasonDuplicate: The latest check found another record carrying the same work. StillHoldsReasonDuplicate ConditionReason = "Duplicate" // StillHoldsReasonContradicts: The latest check found that something else rules out what the record // asks for. StillHoldsReasonContradicts ConditionReason = "Contradicts" // StillHoldsReasonUnclear: The latest check settled nothing, so the record comes due again at its // interval. StillHoldsReasonUnclear ConditionReason = "Unclear" )
The reasons that the StillHolds condition type lists, in its order.
const ( // NeedsPersonReasonClaimWaitsOnPerson: The claim holding the record waits on a person, and the // message says on what. NeedsPersonReasonClaimWaitsOnPerson ConditionReason = "ClaimWaitsOnPerson" // NeedsPersonReasonSessionWaitsOnPerson: The run's session waits on a person, and the message says // since when. NeedsPersonReasonSessionWaitsOnPerson ConditionReason = "SessionWaitsOnPerson" // NeedsPersonReasonRowWaitsOnPerson: The inbox row moves only once a person acts, and the message // says what it waits on, such as an answer or a review. NeedsPersonReasonRowWaitsOnPerson ConditionReason = "RowWaitsOnPerson" // NeedsPersonReasonItemWaitsInReview: The item waits in ingestion's review for a person to place // it, and the message names why, as ingestion's review reasons name it. NeedsPersonReasonItemWaitsInReview ConditionReason = "ItemWaitsInReview" // NeedsPersonReasonNothingAsked: Nothing on the resource waits on a person. NeedsPersonReasonNothingAsked ConditionReason = "NothingAsked" )
The reasons that the NeedsPerson condition type lists, in its order.
const ( // AdmittedReasonStarted: Admission started the run's newest attempt, and the message says when. AdmittedReasonStarted ConditionReason = "Started" // AdmittedReasonEndedUnadmitted: The run ended before any admission started it: a person canceled // it, or its dispatch stopped taking work. AdmittedReasonEndedUnadmitted ConditionReason = "EndedUnadmitted" // AdmittedReasonNotBefore: The run waits for the time its schedule booked it at. AdmittedReasonNotBefore ConditionReason = "NotBefore" // AdmittedReasonQuietBackOff: The run waits out its job's back-off after runs that ended quietly. AdmittedReasonQuietBackOff ConditionReason = "QuietBackOff" // AdmittedReasonAfter: The run waits on runs it declared it goes after. AdmittedReasonAfter ConditionReason = "After" // AdmittedReasonPaused: A pause holds runs of its kind. AdmittedReasonPaused ConditionReason = "Paused" // AdmittedReasonTrackedRecord: The tracker does not yet read the record the run is for as ready. AdmittedReasonTrackedRecord ConditionReason = "TrackedRecord" // AdmittedReasonRegistry: The repo registry does not yet hold what the run needs. AdmittedReasonRegistry ConditionReason = "Registry" // AdmittedReasonRepoFindings: Open finding rows on the run's repo hold it. AdmittedReasonRepoFindings ConditionReason = "RepoFindings" // AdmittedReasonRoleAccount: No account its place starts the run under is free. AdmittedReasonRoleAccount ConditionReason = "RoleAccount" // AdmittedReasonClaudeProfile: The Claude Code profile the run pulls is not yet resolved. AdmittedReasonClaudeProfile ConditionReason = "ClaudeProfile" // AdmittedReasonCaptureScreen: The capture screenshot the run reads has not yet reached the // warehouse. AdmittedReasonCaptureScreen ConditionReason = "CaptureScreen" // AdmittedReasonBudget: The model budget leaves no room for the run. AdmittedReasonBudget ConditionReason = "Budget" // AdmittedReasonKind: Its kind already runs as many runs at once as its limit allows. AdmittedReasonKind ConditionReason = "Kind" // AdmittedReasonDispatch: Its dispatch already runs as many runs at once as its limit allows. AdmittedReasonDispatch ConditionReason = "Dispatch" // AdmittedReasonRoom: No place has room for the run. AdmittedReasonRoom ConditionReason = "Room" // AdmittedReasonLease: Another run holds a lease the run needs. AdmittedReasonLease ConditionReason = "Lease" // AdmittedReasonAwaitsNextPass: No gate holds the queued run, so the next admission pass may start // it. AdmittedReasonAwaitsNextPass ConditionReason = "AwaitsNextPass" )
The reasons that the Admitted condition type lists, in its order.
type ConditionReasonDefinition ¶
type ConditionReasonDefinition struct {
Reason ConditionReason
Description string
// Kinds names the resource kinds that carry the reason: its own x-kinds, or its type's where
// it names none.
Kinds []string
}
ConditionReasonDefinition is one reason that a condition type lists.
type ConditionStatus ¶
type ConditionStatus string
ConditionStatus is whether a condition holds, as Kubernetes spells a condition's status.
const ( ConditionTrue ConditionStatus = "True" ConditionFalse ConditionStatus = "False" ConditionUnknown ConditionStatus = "Unknown" )
Each status that a condition takes, as resource-shape-schema.json gives a condition.
type ConditionType ¶
type ConditionType string
ConditionType is what a condition reports, such as Ready.
const ( // ConditionTypeReady: Whether the issue can start now, as slate's readiness decides. Its reasons // are an order, and the first that holds is the condition's reason. ConditionTypeReady ConditionType = "Ready" // ConditionTypeHeld: Whether a live claim holds the record, so no other session takes it. ConditionTypeHeld ConditionType = "Held" // ConditionTypeStillHolds: Whether the record still describes the world, as its latest check found. // Its reasons are slate's check verdicts, one each, in PascalCase. A record that no check has read // carries no StillHolds condition. ConditionTypeStillHolds ConditionType = "StillHolds" // ConditionTypeNeedsPerson: Whether the work on the resource waits on a person. ConditionTypeNeedsPerson ConditionType = "NeedsPerson" // ConditionTypeAdmitted: Whether admission started the run's newest attempt. Its reasons are an // order, and the first that holds is the condition's reason. A queued run reads False with the gate // that admission last held it at, and the message gives admission's own words for the hold. ConditionTypeAdmitted ConditionType = "Admitted" )
Each condition type that resource-condition-types-schema.json declares, in its order.
type ConditionTypeDefinition ¶
type ConditionTypeDefinition struct {
Type ConditionType
Description string
// Normal is the status a view treats as unremarkable. A view colors a condition whose status
// differs from it.
Normal ConditionStatus
// Kinds names the resource kinds that carry the condition.
Kinds []string
// Reasons lists the type's reasons in the schema's order. Where the type's description says
// its reasons are an order, the first reason that holds is the condition's reason.
Reasons []ConditionReasonDefinition
}
ConditionTypeDefinition is one condition type as resource-condition-types-schema.json declares it.
func ConditionTypeDefinitions ¶
func ConditionTypeDefinitions() []ConditionTypeDefinition
ConditionTypeDefinitions returns every condition type that the module's copy of resource-condition-types-schema.json declares, in its order.
func LookupConditionType ¶
func LookupConditionType(conditionType ConditionType) (ConditionTypeDefinition, bool)
LookupConditionType returns the definition of the condition type named conditionType, and false where the schema declares no such type.
type Identifier ¶
type Identifier string
Identifier is the name of an identity that more than one store carries, such as slate-record or flow, as identifiers-shared-across-stores-schema.json names it.
const ( // IdentifierActor: One principal acting through a fleet service, by the name its token carries: a // service's client id, such as slate-svc-fleet-runs, or a person's login. IdentifierActor Identifier = "actor" // IdentifierAgentKind: One kind of agent the fleet runs. IdentifierAgentKind Identifier = "agent-kind" // IdentifierAPIMessage: One response from the model. IdentifierAPIMessage Identifier = "api-message" // IdentifierClaudeCodeTaskRun: One background task Claude Code ran in a session, by the id its task // notification carries. IdentifierClaudeCodeTaskRun Identifier = "claude-code-task-run" // IdentifierClaudeSession: One Claude Code session. IdentifierClaudeSession Identifier = "claude-session" // IdentifierCommit: One git commit. IdentifierCommit Identifier = "commit" // IdentifierDotfilesRun: One run of a dotfiles verb, by the id its run record carries. IdentifierDotfilesRun Identifier = "dotfiles-run" // IdentifierFleetRun: One execution of a fleet job, by the id silver.runs gives it. A queued job // and its run are one row under one number, so a job waiting in the queue already carries its run's // id. IdentifierFleetRun Identifier = "fleet-run" // IdentifierFlow: One cause followed through the fleet. IdentifierFlow Identifier = "flow" // IdentifierGitHubActionsRun: One GitHub Actions workflow run, by the id GitHub gives it. IdentifierGitHubActionsRun Identifier = "github-actions-run" // IdentifierHomelabApplyRun: One plan, apply, container operation or backup trigger, by the id the // homelab apply worker's runs table gives it. IdentifierHomelabApplyRun Identifier = "homelab-apply-run" // IdentifierInboxRow: One row of the fleet's inbox. IdentifierInboxRow Identifier = "inbox-row" // IdentifierIngestionItem: One item that ingestion landed, by the key it derives from the item's // artifact, such as reddit/t3_aq7ggd. IdentifierIngestionItem Identifier = "ingestion-item" // IdentifierMachine: One box, by its lowercased short hostname. IdentifierMachine Identifier = "machine" // IdentifierMachineRun: One run of a fleet tool on a machine, as gold.machine_runs names it: its // source's prefix, then that source's own id. IdentifierMachineRun Identifier = "machine-run" // IdentifierPsycheEvalRun: One evaluation run psyche keeps in its eval_run table. IdentifierPsycheEvalRun Identifier = "psyche-eval-run" // IdentifierPullRequest: One pull request in a repo. IdentifierPullRequest Identifier = "pull-request" // IdentifierRepo: One registered repo, by its registry name. IdentifierRepo Identifier = "repo" // IdentifierScheduledJob: One job on the fleet's schedule. IdentifierScheduledJob Identifier = "scheduled-job" // IdentifierSlateRecord: One slate issue, initiative or idea, by its number. IdentifierSlateRecord Identifier = "slate-record" // IdentifierSlateWorklog: One worklog of a slate record, by its record's number and its place among // that record's worklogs, such as 4941.2. IdentifierSlateWorklog Identifier = "slate-worklog" // IdentifierToolUse: One tool call in a Claude Code session. IdentifierToolUse Identifier = "tool-use" // IdentifierTrace: One OpenTelemetry trace. IdentifierTrace Identifier = "trace" // IdentifierYplSyncRun: One sync of the YouTube library ypl keeps in its sync_runs table. IdentifierYplSyncRun Identifier = "ypl-sync-run" )
Each identifier that identifiers-shared-across-stores-schema.json declares, sorted by name.
type IdentifierDefinition ¶
type IdentifierDefinition struct {
Identifier Identifier
Description string
// ValueType is the JSON type of the identifier's value, string or integer.
ValueType string
// OTelAttribute is the attribute that an OpenTelemetry span, log or event carries the
// identifier under. It is empty for a trace, which OpenTelemetry carries in its own trace id.
OTelAttribute string
// WarehouseColumn is the column that a warehouse table names the identifier.
WarehouseColumn string
}
IdentifierDefinition is one identifier as identifiers-shared-across-stores-schema.json declares it.
func IdentifierDefinitions ¶
func IdentifierDefinitions() []IdentifierDefinition
IdentifierDefinitions returns every identifier that the module's copy of identifiers-shared-across-stores-schema.json declares, sorted by name.
func LookupIdentifier ¶
func LookupIdentifier(identifier Identifier) (IdentifierDefinition, bool)
LookupIdentifier returns the definition of identifier, and false where the schema declares no such identifier.
type IdentifierValue ¶
type IdentifierValue struct {
// contains filtered or unexported fields
}
IdentifierValue is one identifier's value, as the JSON wrote it: an integer for a JSON integer, and a string for a JSON string. It does not check the value against the type that identifiers-shared-across-stores-schema.json gives the identifier. IdentifierDefinition's ValueType holds that type.
func IntIdentifier ¶
func IntIdentifier(number int64) IdentifierValue
IntIdentifier returns an identifier value holding number.
func StringIdentifier ¶
func StringIdentifier(text string) IdentifierValue
StringIdentifier returns an identifier value holding text.
func (IdentifierValue) Int ¶
func (v IdentifierValue) Int() (int64, bool)
Int returns the value's integer, and false where the value is a string.
func (IdentifierValue) MarshalJSON ¶
func (v IdentifierValue) MarshalJSON() ([]byte, error)
MarshalJSON writes the value as a JSON integer or string.
func (IdentifierValue) String ¶
func (v IdentifierValue) String() string
String returns the value as text: a string as it is, and an integer in decimal.
func (*IdentifierValue) UnmarshalJSON ¶
func (v *IdentifierValue) UnmarshalJSON(data []byte) error
UnmarshalJSON reads a JSON string or integer, and refuses any other value.
type Metadata ¶
type Metadata struct {
// Created and Updated are written in UTC, whatever their location.
Created time.Time `json:"created,omitzero"`
Updated time.Time `json:"updated,omitzero"`
// Owners names the resources this one belongs to, such as an issue's initiative.
Owners []string `json:"owners,omitzero"`
Relations []Relation `json:"relations,omitzero"`
// Identifiers holds every identity that another store joins on, keyed by its name in
// identifiers-shared-across-stores-schema.json. The shape requires the key, so Resource writes
// a nil map as {}.
Identifiers map[Identifier]IdentifierValue `json:"identifiers"`
}
Metadata is what every resource carries whatever its kind.
type Name ¶
type Name struct {
// contains filtered or unexported fields
}
Name is a resource's name, parsed against the collection whose pattern it matched. ParseName and Collection.Name build one.
func ParseName ¶
func ParseName(raw string, collections Collections) (Name, error)
ParseName reads raw as a resource's name, against the collections whose patterns it may match. It refuses a name that matches no collection's pattern, or more than one, with a *NameError.
func (Name) APIPath ¶
APIPath returns the route at which the name's service serves the resource, with each placeholder taking the segment of the same name, encoded. It returns false where the collection declares no route.
func (Name) Collection ¶
func (n Name) Collection() Collection
Collection returns the collection that holds the named resource.
func (Name) Segment ¶
Segment returns the decoded value of the template variable called variable, such as owner in github/{owner}/{repo}/pulls/{id}, and false where the collection's template has no such variable.
type NameError ¶
type NameError struct {
// Name is the string that was refused.
Name string
// Near holds the collections of the service that the name starts with, or every collection
// where no service matches.
Near []Collection
// Matched holds each collection whose pattern matched, where more than one did.
Matched []Collection
}
NameError says why a string is not a resource name. Its message names the grammar, and the collections near the name with an example of each.
type Relation ¶
type Relation struct {
// Type says how the two relate, such as DiscoveredFrom.
Type string `json:"type"`
Name string `json:"name"`
}
Relation is one other resource that a resource points at, and how.
type Resource ¶
type Resource struct {
SchemaVersion int `json:"schema_version"`
Kind string `json:"kind"`
// Name is the resource's name, which ParseName reads.
Name string `json:"name"`
Metadata Metadata `json:"metadata"`
// Spec is the kind's own object, as the service wrote it. A reader decodes it into the kind's
// own type with json.Unmarshal. The shape requires an object, so an empty Spec is written as {}.
Spec json.RawMessage `json:"spec"`
Status Status `json:"status"`
}
Resource is one object that a fleet service serves, in the shape resource-shape-schema.json holds. Spec holds what the resource's author set, in its kind's own keys, and Status what its service derives or observes.
func (Resource) MarshalJSON ¶
MarshalJSON writes the resource as the shape requires it: an empty Spec and nil identifiers as {}, and each time in UTC.
type Status ¶
type Status struct {
// State is the resource's lifecycle, in its service's own words, such as open or running.
State string `json:"state,omitempty"`
Conditions []Condition `json:"conditions,omitzero"`
// Children names what the resource produced, such as a slate issue's pull requests.
Children []string `json:"children,omitzero"`
// Extra holds each key that the resource's kind adds beside the three above, as the service
// wrote it. A key that names one of the three is ignored when the status is written.
Extra map[string]json.RawMessage `json:"-"`
}
Status is what a resource's service derives or observes.
func (Status) MarshalJSON ¶
MarshalJSON writes the status's three keys and each key of Extra beside them.
func (*Status) UnmarshalJSON ¶
UnmarshalJSON reads the status's three keys, and keeps every other key in Extra.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
cmd/write-schema-constants
command
Command write-schema-constants writes schema_constants_generated.go from the schema copies in the current directory.
|
Command write-schema-constants writes schema_constants_generated.go from the schema copies in the current directory. |
|
schemaconstants
Package schemaconstants renders the Go file of constants that the module's schema copies declare: each condition status, condition type, reason and identifier, and the definitions that describe them.
|
Package schemaconstants renders the Go file of constants that the module's schema copies declare: each condition status, condition type, reason and identifier, and the definitions that describe them. |