core

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package core provides a small, stable facade over Redactyl's internal engine for external integrations. It deliberately re-exports a narrow API surface to allow Enterprise and third-party tools to depend on a stable import path without exposing internal implementation packages.

Example:

cfg := core.Config{Root: ".", Threads: 0}
findings, err := core.Scan(cfg)
if err != nil { /* handle */ }
_ = core.MarshalFindings(os.Stdout, findings)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectorIDs

func DetectorIDs() []string

DetectorIDs returns the list of configured detector IDs. This is exposed for convenience to avoid importing internals directly.

func MarshalFindings

func MarshalFindings(w io.Writer, findings []Finding) error

MarshalFindings pretty-prints findings as JSON for humans or pipelines.

Types

type Config

type Config = engine.Config

Re-export selected internal types as a stable public API surface. These are type aliases so external consumers can depend on a stable path. We can replace these with decoupled structs later without breaking callers.

type DeepStats

type DeepStats = engine.DeepStats

type Finding

type Finding = types.Finding

func Scan

func Scan(cfg Config) ([]Finding, error)

Scan is the stable entrypoint for other programs.

Example

ExampleScan demonstrates how to perform a simple scan of a directory.

package main

import (
	"fmt"
	"os"

	"github.com/varalys/redactyl/pkg/core"
)

func main() {
	// 1. Configure the scan
	cfg := core.Config{
		Root:         ".",         // Scan the current directory
		Threads:      4,           // Number of concurrent workers
		IncludeGlobs: "*.go",      // Only scan Go files (optional)
		MaxBytes:     1024 * 1024, // Skip files larger than 1MB
	}

	// 2. Run the scan
	findings, err := core.Scan(cfg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Scan failed: %v\n", err)
		return
	}

	// 3. Process findings
	if len(findings) == 0 {
		fmt.Println("No secrets found.")
	} else {
		fmt.Printf("Found %d secrets.\n", len(findings))
		// Helper to write JSON output to stdout
		_ = core.MarshalFindings(os.Stdout, findings)
	}
}

func UnmarshalFindings

func UnmarshalFindings(r io.Reader) ([]Finding, error)

UnmarshalFindings decodes findings JSON, useful for ingestion tests.

type Result

type Result = engine.Result

func ScanWithStats

func ScanWithStats(cfg Config) (Result, error)

ScanWithStats is the extended entrypoint that returns findings plus statistics. This is useful for integrations that need to report on scan performance or partial failures.

Example

ExampleScanWithStats shows how to run a scan and retrieve execution statistics.

package main

import (
	"fmt"
	"time"

	"github.com/varalys/redactyl/pkg/core"
)

func main() {
	cfg := core.Config{
		Root:           "test/integration/fixtures", // Point to a directory
		ScanTimeBudget: 5 * time.Second,             // Set a time limit per artifact
	}

	// Run scan and get detailed result object
	result, err := core.ScanWithStats(cfg)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Scanned %d files in %s\n", result.FilesScanned, result.Duration)
	fmt.Printf("Found %d secrets\n", len(result.Findings))

	// Check artifact scanning stats
	if result.ArtifactStats.AbortedByTime > 0 {
		fmt.Printf("Warning: %d artifacts timed out\n", result.ArtifactStats.AbortedByTime)
	}
}

Jump to

Keyboard shortcuts

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