scanner

package
v1.1.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Reset   = "\033[0m"
	Red     = "\033[31m"
	Green   = "\033[32m"
	Yellow  = "\033[33m"
	Blue    = "\033[34m"
	Magenta = "\033[35m"
	Cyan    = "\033[36m"
	Gray    = "\033[37m"
	White   = "\033[97m"
)

Color codes

Variables

This section is empty.

Functions

func AutoFixRepository

func AutoFixRepository(regex *regexp.Regexp, isDryRun bool) error

AutoFixRepository tries to match and replace third-party action references with SHA It uses SHA resolution to find accurate SHA

Types

type Branch

type Branch interface {
	Name() string
}

Branch abstracts a branch in a repository.

type FileScanner

type FileScanner interface {
	ScanContent(content []byte, regex *regexp.Regexp) ([]string, error)
}

FileScanner defines functionality to scan file content using a regex.

type GitHubVCS

type GitHubVCS struct{}

GitHub VCS

func (GitHubVCS) ListRepositories

func (g GitHubVCS) ListRepositories(root string) ([]Repository, error)

type GitHubWorkFlowScanner

type GitHubWorkFlowScanner struct{}

GitHubWorkFlowScanner implements Scanner interface

func (GitHubWorkFlowScanner) ScanContent

func (gws GitHubWorkFlowScanner) ScanContent(content []byte, regex *regexp.Regexp) ([]string, error)

ScanContent finds matches in given content

type GitRepository

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

GitRepository implements Repository interface

func (GitRepository) ListBranches

func (g GitRepository) ListBranches() ([]string, error)

func (GitRepository) ListFiles

func (g GitRepository) ListFiles(loc string) ([]string, error)

func (GitRepository) Location

func (g GitRepository) Location() string

func (GitRepository) Name

func (g GitRepository) Name() string

func (GitRepository) ReadFile

func (g GitRepository) ReadFile(filePath string) ([]byte, error)

func (GitRepository) SwitchBranch

func (g GitRepository) SwitchBranch(branchName string) error

type Inventory

type Inventory struct {
	Records []*InventoryRecord `json:"findings"`
}

Inventory aggregates multiple inventory records.

func AuditRepository

func AuditRepository(regex *regexp.Regexp) (*Inventory, error)

AuditRepository collects inventory details from current Git repository.

type InventoryRecord

type InventoryRecord struct {
	Repository string   `json:"repository_name"` // Repository name or path
	Branch     string   `json:"branch_name"`     // Branch name
	FilePath   string   `json:"actions_file"`    // File path where the match was found
	Matches    []string `json:"matches"`         // Regex match results from the file content
}

InventoryRecord holds details for a regex match in a file.

type Repository

type Repository interface {
	Name() string

	// Location gets absolute path of repository
	Location() string
	// ListBranches returns all branches available in the repository.
	ListBranches() ([]string, error)
	// ReadFile retrieves the content of a file given a file path.
	ReadFile(filePath string) ([]byte, error)
	// ListFiles returns all file paths under a given directory in a branch.
	ListFiles(loc string) ([]string, error)
	// SwitchBranch checks out the repository to given branch
	SwitchBranch(branchName string) error
}

Repository abstracts a single repository and its operations.

type Scanner

type Scanner struct {
	// VCS system implementation (e.g., GitHub, GitLab)
	VCS         VCS
	FileScanner FileScanner
}

Scanner ties together VCS operations with file scanning logic.

func (*Scanner) ScanBranch

func (s *Scanner) ScanBranch(branch string, repo Repository, regex *regexp.Regexp, dirPath string) *Inventory

func (*Scanner) ScanRepos

func (s *Scanner) ScanRepos(root string, regex *regexp.Regexp, ho bool) (*Inventory, error)

ScanRepos traverses all repositories found under the root directory, checks each branch, enumerates over files in the given workflow directory path, and scans each file's content for regex matches. ho - HEAD only

type VCS

type VCS interface {
	ListRepositories(root string) ([]Repository, error)
}

VCS defines operations common to all version control systems.

Jump to

Keyboard shortcuts

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