filesystem

package
v0.0.0-...-b788499 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 18 Imported by: 0

README

filesystem

import "github.com/altessa-s/go-atlas/auth/opa/sources/filesystem"

Package filesystem provides a PolicySource implementation that reads OPA policies from the local filesystem with optional hot-reload support via fsnotify. Reads .rego files from a directory (or a single file), computes content-based revisions, and optionally loads .json data files into the OPA data store. Supports SHA-256 checksum verification for policy integrity.

Options

Option Default Description
WithExtensions [".rego"] File extensions to include when scanning for policy files
WithIncludeData false Load .json files as OPA data alongside Rego policies
WithLogger discard Structured logger (*slog.Logger)
WithChecksums nil SHA-256 hex digests map for policy file integrity verification

Documentation

Overview

Package filesystem provides a PolicySource implementation that reads OPA policies from the local filesystem. Change detection is handled by the Manager.

Example usage:

source, err := filesystem.New("/path/to/policies",
    filesystem.WithExtensions(".rego"),
    filesystem.WithIncludeData(true),
)
if err != nil {
    log.Fatal(err)
}
defer source.Close()

bundle, err := source.Fetch(ctx)
if err != nil {
    log.Fatal(err)
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrChecksumMismatch is returned when a policy file's SHA-256 hash does not match the expected value.
	ErrChecksumMismatch = errors.New("policy file checksum mismatch")
	// ErrUnexpectedPolicyFile is returned when a policy file is found on disk but has no entry in the checksums manifest.
	ErrUnexpectedPolicyFile = errors.New("policy file not in checksums manifest")
	// ErrMissingPolicyFile is returned when an entry in the checksums manifest has no corresponding file on disk.
	ErrMissingPolicyFile = errors.New("expected policy file not found")
)
View Source
var DefaultExtensions = []string{".rego"}

DefaultExtensions are the default file extensions to include.

Functions

This section is empty.

Types

type Option

type Option func(o *options)

Option is a functional option for configuring options.

func WithChecksums

func WithChecksums(v map[string]string) Option

WithChecksums sets the checksums option.

func WithExtensions

func WithExtensions(v ...string) Option

WithExtensions sets the extensions option.

func WithIncludeData

func WithIncludeData() Option

WithIncludeData enables the includeData option.

func WithLogger

func WithLogger(v *slog.Logger) Option

WithLogger sets the logger option.

type Source

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

Source implements opa.PolicySource for filesystem-based policies. It reads .rego files from a directory. Change detection is handled by the Manager.

func New

func New(path string, opts ...Option) (*Source, error)

New creates a new filesystem policy source. The path can be a directory containing .rego files or a single .rego file.

func (*Source) Close

func (s *Source) Close() error

Close releases resources held by the source.

func (*Source) Extensions

func (s *Source) Extensions() []string

Extensions returns the file extensions being watched as a slice.

func (*Source) ExtensionsIter

func (s *Source) ExtensionsIter() iter.Seq[string]

ExtensionsIter returns an iterator over the file extensions being watched. This is more efficient when you don't need a slice.

func (*Source) Fetch

func (s *Source) Fetch(ctx context.Context) (*opa.PolicyBundle, error)

Fetch reads all policy files from the configured path.

func (*Source) Name

func (s *Source) Name() string

Name returns the source identifier.

func (*Source) Path

func (s *Source) Path() string

Path returns the configured filesystem path.

Jump to

Keyboard shortcuts

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