index

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RuleFQN

func RuleFQN(ns, policy, rule string) string

FQN utilities

func ShapeFQN

func ShapeFQN(ns, shape string) string

Types

type ExportedRule

type ExportedRule struct {
	RuleName    string
	Attachments []*RuleExportAttachment // names only; values computed at runtime
}

ExportedRule captures an exported rule's name and its attachment names.

type ExportedShape

type ExportedShape struct {
	Statement *ast.ShapeExportStatement
	Name      string
}

type Index

type Index struct {
	Pack       *pack.PackFile
	Namespaces map[string]*Namespace
	Programs   map[string]*Program
	// contains filtered or unexported fields
}

func CreateIndex

func CreateIndex() *Index

func (*Index) AddProgram

func (idx *Index) AddProgram(ctx context.Context, astProgram *ast.Program) error

func (*Index) Commit

func (idx *Index) Commit(ctx context.Context) error

func (*Index) IsValid

func (idx *Index) IsValid(ctx context.Context) error

func (*Index) ResolveNamespace

func (idx *Index) ResolveNamespace(ns string) (*Namespace, error)

func (*Index) ResolvePolicy

func (idx *Index) ResolvePolicy(ns, policy string) (*Policy, error)

ResolvePolicy tries exact namespace match; it does not traverse parents.

func (*Index) ResolveSegments

func (idx *Index) ResolveSegments(path string) (ns, policy, rule string, err error)

func (*Index) ResolveShape

func (idx *Index) ResolveShape(ns, shape string) (*Shape, error)

func (*Index) SetPack

func (idx *Index) SetPack(ctx context.Context, p *pack.PackFile) error

func (*Index) Validate

func (idx *Index) Validate(ctx context.Context) error

Validate the index for consistency and correctness. Checks for: - Cyclic dependencies

type Namespace

type Namespace struct {
	Statement    *ast.NamespaceStatement
	FQN          ast.FQN // this is always the FQN
	Parent       *Namespace
	Children     []*Namespace
	Policies     map[string]*Policy
	Shapes       map[string]*Shape // namespace-level shapes
	ShapeExports map[string]*ExportedShape
}

Namespace is an index of policies and shapes visible within (namespace & sub-namespaces).

func (Namespace) IsChildOf

func (n Namespace) IsChildOf(another *Namespace) bool

func (Namespace) IsParentOf

func (n Namespace) IsParentOf(another *Namespace) bool

func (Namespace) VerifyShapeExported

func (ns Namespace) VerifyShapeExported(shape string) error

type Policy

type Policy struct {
	Statement  *ast.PolicyStatement
	Namespace  *Namespace
	Name       string
	FQN        ast.FQN
	FilePath   string
	Statements []ast.Statement

	Title          *string
	Description    *string
	VersionLiteral string
	Version        *semver.Version
	TagPairs       []PolicyTagPair
	// TagsByKey is derived from TagPairs for query ergonomics; map iteration order is not stable.
	TagsByKey map[string][]string

	Lets        map[string]*ast.VarDeclaration
	Facts       map[string]*ast.FactStatement
	Rules       map[string]*Rule
	RuleExports map[string]*ExportedRule
	Uses        map[string]*ast.UseStatement // alias -> use statement
	Shapes      map[string]*Shape            // policy-local shapes
	// contains filtered or unexported fields
}

Policy holds the AST statements and exports.

func (*Policy) AddFact

func (p *Policy) AddFact(fact *ast.FactStatement) error

func (*Policy) AddLet

func (p *Policy) AddLet(let *ast.VarDeclaration) error

func (*Policy) AddRule

func (p *Policy) AddRule(rule *ast.RuleStatement) error

func (*Policy) AddShape

func (p *Policy) AddShape(shape *ast.ShapeStatement) error

func (*Policy) String

func (p *Policy) String() string

func (Policy) VerifyRuleExported

func (p Policy) VerifyRuleExported(rule string) error

VerifyRuleExported verifies that a rule is exported in its policy. Returns an error if the rule is not exported.

type PolicyTagPair added in v0.0.3

type PolicyTagPair struct {
	Key   string
	Value string
}

PolicyTagPair is one key/value from policy `tag` statements (order preserved in Policy.TagPairs).

type Program

type Program struct {
	Reference    *ast.Program
	Namespace    *ast.NamespaceStatement
	Policies     []*ast.PolicyStatement
	Shapes       []*ast.ShapeStatement
	ShapeExports []*ast.ShapeExportStatement
}

type Rule

type Rule struct {
	Node    *ast.RuleStatement
	Policy  *Policy
	Name    string
	FQN     ast.FQN
	Default ast.Expression
	When    ast.Expression
	Body    ast.Expression
}

func (*Rule) Span

func (r *Rule) Span() tokens.Range

func (*Rule) String

func (r *Rule) String() string

type RuleExportAttachment

type RuleExportAttachment struct {
	Name  string
	Value ast.Expression
}

type Shape

type Shape struct {
	Statement *ast.ShapeStatement
	Namespace *Namespace
	Policy    *Policy
	Name      string
	FQN       ast.FQN
	Model     *ShapeModel
	AliasOf   ast.TypeRef
	FilePath  string
	// contains filtered or unexported fields
}

func (*Shape) Span

func (s *Shape) Span() tokens.Range

func (*Shape) String

func (s *Shape) String() string

type ShapeModel

type ShapeModel struct {
	WithFQN *ast.FQN
	Fields  map[string]*ShapeModelField
}

type ShapeModelField

type ShapeModelField struct {
	Node     *ast.ShapeField
	Name     string
	Optional bool
	TypeRef  ast.TypeRef
}

type String

type String string

func (String) String

func (s String) String() string

Jump to

Keyboard shortcuts

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