Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
Generate produces a markdown document describing the given policy element. Options control the diagrams embedded in it: by default every element gets a mermaid structure diagram, and policies embedded in sets and groups get none of their own (see WithPolicyDetails).
func IndexMarker ¶ added in v0.1.2
IndexMarker returns the comment delimiting a generated region of an index: section is "policies", "sets" or "groups" and edge is "begin" or "end".
Types ¶
type Diagrammer ¶ added in v0.1.2
type Diagrammer interface {
// Policy diagrams a policy: the inputs feeding it (attestation types,
// context values and chain links) and how its tenets combine, all of
// them required under AND or any one sufficient under OR.
Policy(p *papi.Policy) string
// PolicyGroup diagrams the blocks of a group and the policy alternatives
// each block offers, with the assert mode combining them at each level.
PolicyGroup(pg *papi.PolicyGroup) string
// PolicySet diagrams the composition of a set: its policies and groups.
PolicySet(ps *papi.PolicySet) string
}
Diagrammer renders diagrams of policy elements as markdown fragments that Generate inlines in the document, such as a fenced mermaid block. An implementation for another diagram language, or one that renders images, only has to return markdown that embeds its output.
type Index ¶ added in v0.1.2
type Index struct {
// contains filtered or unexported fields
}
Index lists policy materials by kind as markdown tables: policies with their name and the predicate types they consume, sets and groups with their composition and the predicate types consumed by everything inside.
Each table is wrapped in marker comments so Inject can refresh a document that carries hand written text around and between the tables.
func NewIndex ¶ added in v0.1.2
func NewIndex(entries []IndexEntry) (*Index, error)
NewIndex classifies entries by kind. It fails on unsupported elements.
func (*Index) Inject ¶ added in v0.1.2
Inject refreshes the marked regions of an existing document with the current tables and leaves everything outside the markers untouched, so a title, an introduction and per section text survive regeneration. A section with entries but no markers is appended at the end. Inject fails when a section has only one of its markers or they are out of order.
type IndexEntry ¶ added in v0.1.2
type IndexEntry struct {
// Element is the compiled *papi.Policy, *papi.PolicySet or *papi.PolicyGroup.
Element any
// Link is the path of the element's document relative to the index
// location. Its ID links there when set and stays plain text otherwise.
Link string
}
IndexEntry is a policy material listed in an index.
type Mermaid ¶ added in v0.1.2
type Mermaid struct{}
Mermaid renders diagrams as mermaid flowcharts wrapped in a fenced code block, which markdown viewers with mermaid support and the HTML output render inline.
func (Mermaid) Policy ¶ added in v0.1.2
Policy diagrams the inputs feeding the policy and how its tenets combine.
func (Mermaid) PolicyGroup ¶ added in v0.1.2
func (Mermaid) PolicyGroup(pg *papi.PolicyGroup) string
PolicyGroup diagrams the blocks of the group and the alternatives in each.
type Option ¶ added in v0.1.2
type Option func(*Options)
Option adjusts the generation Options.
func WithDiagrammer ¶ added in v0.1.2
func WithDiagrammer(d Diagrammer) Option
WithDiagrammer selects the Diagrammer rendering the embedded diagrams.
func WithPolicyDetails ¶ added in v0.1.2
WithPolicyDetails controls whether policies embedded in sets and groups get their own diagram.
func WithoutDiagrams ¶ added in v0.1.2
func WithoutDiagrams() Option
WithoutDiagrams omits every diagram from the document.
type Options ¶ added in v0.1.2
type Options struct {
// Diagrammer renders the diagrams embedded in the document. A nil
// Diagrammer omits every diagram.
Diagrammer Diagrammer
// PolicyDetails adds each embedded policy's own diagram to set and group
// documents. Standalone policy documents always carry theirs.
PolicyDetails bool
}
Options control document generation. Build them with Option functions.