package oracle

import "github.com/open-policy-agent/opa/v1/ast/oracle"

Copyright 2020 The OPA Authors. All rights reserved. Use of this source code is governed by an Apache2 license that can be found in the LICENSE file.

Index

Variables

var (
	// ErrNoDefinitionFound indicates the position was valid but no matching definition was found.
	ErrNoDefinitionFound = Error{Code: "oracle_no_definition_found"}

	// ErrNoMatchFound indicates the position was invalid.
	ErrNoMatchFound = Error{Code: "oracle_no_match_found"}
)

Types

type DefinitionQuery

type DefinitionQuery struct {
	Modules  map[string]*ast.Module // workspace modules; buffer may shadow a file inside the workspace
	Filename string                 // name of file to search for position inside of
	Buffer   []byte                 // buffer that overrides module with filename
	Pos      int                    // position to search for
}

DefinitionQuery defines a Rego definition query.

type DefinitionQueryResult

type DefinitionQueryResult struct {
	Result *ast.Location `json:"result"`
}

DefinitionQueryResult defines output of a definition query.

type Error

type Error struct {
	Code string `json:"code"`
}

Error defines the structure of errors returned by the oracle.

func (Error) Error

func (e Error) Error() string

type Oracle

type Oracle struct {
	// contains filtered or unexported fields
}

Oracle implements different queries over ASTs, e.g., find definition.

func New

func New() *Oracle

New returns a new Oracle object.

func (*Oracle) FindDefinition

func (o *Oracle) FindDefinition(q DefinitionQuery) (*DefinitionQueryResult, error)

FindDefinition returns the location of the definition referred to by the symbol at the position in q.

func (*Oracle) WithCompiler

func (o *Oracle) WithCompiler(compiler *ast.Compiler) *Oracle

WithCompiler sets the compiler to use for the oracle. If not set, a new ast.Compiler will be created when needed.

Source Files

oracle.go

Version
v1.4.2 (latest)
Published
May 2, 2025
Platform
linux/amd64
Imports
3 packages
Last checked
4 hours ago

Tools for package owners.