package refactor

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

Package refactor implements different refactoring operations over Rego modules.

Index

Types

type Error

type Error struct {
	Message  string        `json:"message"`
	Location *ast.Location `json:"location,omitempty"`
}

Error defines the structure of errors returned by refactor.

func (Error) Error

func (e Error) Error() string

type MoveQuery

type MoveQuery struct {
	Modules       map[string]*ast.Module
	SrcDstMapping map[string]string
	// contains filtered or unexported fields
}

MoveQuery holds the set of Rego modules whose package paths and other references are to be rewritten as per the mapping defined in SrcDstMapping. If validate is true, the moved modules will be compiled to ensure they are valid.

func (MoveQuery) WithValidation

func (mq MoveQuery) WithValidation(v bool) MoveQuery

WithValidation controls whether to compile moved modules to ensure they are valid.

type MoveQueryResult

type MoveQueryResult struct {
	Result map[string]*ast.Module `json:"result"`
}

MoveQueryResult defines the output of a move query and holds the rewritten modules with updated packages paths and references.

type Refactor

type Refactor struct {
}

Refactor implements different refactoring operations over Rego modules eg. renaming packages.

func New

func New() *Refactor

New returns a new Refactor object.

func (*Refactor) Move

func (*Refactor) Move(q MoveQuery) (*MoveQueryResult, error)

Move rewrites Rego code by updating package paths and other references in q's modules as per the mapping specified in q.

Source Files

refactor.go

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

Tools for package owners.