project

package
v0.0.0-...-24c8cf0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedToCreateDir = errors.New("failed to create directory")

ErrFailedToCreateDir is returned when we were unable to create a directory

View Source
var ErrFailedToCreateFile = errors.New("failed to write to file")

ErrFailedToCreateFile is returned when we were unable to create a file

View Source
var ErrFailedToMarshalManifest = errors.New("failed to marshal manifest")

ErrFailedToMarshalManifest is returned when we were unable to marshal the manifest to JSON

View Source
var ErrFailedToParseRegoFile = errors.New("failed to parse rego file")
View Source
var ErrFailedToReadPath = errors.New("failed to read path")

ErrFailedToReadPath is returned when we encountered a filesystem error while reading a path.

View Source
var ErrFailedToUnmarshalManifest = errors.New("failed to unmarshal manifest")

ErrFailedToUnmarshalManifest is returned when we were unable to unmarshal the manifest from JSON

View Source
var ErrInvalidIdentifier = errors.New("invalid identifier")

ErrInvalidIdentifier is returned when an identifier does not satisfy some constraint.

View Source
var ErrRuleDirAlreadyExists = errors.New("rule directory already exists")

ErrRuleDirAlreadyExists is returned when a rule already exists

View Source
var ErrRuleSpecAlreadyExists = errors.New("rule spec already exists")
View Source
var ErrUnexpectedType = errors.New("unexpected file type")

ErrUnexpectedType is returned when we expected a directory and found a file or vice versa.

Functions

func RuleIDToSafeFileName

func RuleIDToSafeFileName(ruleID string) (string, error)

func SafePackageName

func SafePackageName(s string) (string, error)

Types

type Dir

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

Dir represents a directory on disk.

func DirFromPath

func DirFromPath(fsys afero.Fs, path string) (*Dir, error)

DirFromPath returns a Dir for the given path whether it exists or not.

func ExistingDir

func ExistingDir(path string) *Dir

ExistingDir returns a Dir object that represents an existing directory on disk.

func NewDir

func NewDir(path string) *Dir

NewDir returns a Dir object that represents a directory that does not exist yet.

func (*Dir) Exists

func (d *Dir) Exists() bool

Exists returns whether the represented directory exists or not.

func (*Dir) IsDir

func (d *Dir) IsDir() bool

IsDir always returns true.

func (*Dir) Path

func (d *Dir) Path() string

Path returns the path of this Dir object.

func (*Dir) WriteChanges

func (d *Dir) WriteChanges(fsys afero.Fs) error

WriteChanges will create the directory on disk if it does not already exist.

type FSNode

type FSNode interface {
	// Path returns the path for this node.
	Path() string
	// Exists returns whether or not this node exists on disk.
	Exists() bool
	// IsDir returns whether or not this node is a directory.
	IsDir() bool
	// WriteChanges persists any changes to this node back to disk.
	WriteChanges(fsys afero.Fs) error
}

FSNode defines the base set of operations for both files and directories.

func FSNodeFromFileInfo

func FSNodeFromFileInfo(parent string, i fs.FileInfo) FSNode

FSNodeFromFileInfo returns an FSNode for the given fs.FileInfo object in the parent directory.

type File

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

File represents a file on disk.

func ExistingFile

func ExistingFile(path string) *File

ExistingFile returns a File object that represents an existing file on disk.

func FileFromPath

func FileFromPath(fsys afero.Fs, path string) (*File, error)

FileFromPath returns a File for the given path whether it exists or not.

func NewFile

func NewFile(path string) *File

NewFile returns a File object that represents a file that does not exist yet.

func (*File) Exists

func (f *File) Exists() bool

Exists returns whether the represented file exists or not.

func (*File) IsDir

func (f *File) IsDir() bool

IsDir always returns false.

func (*File) Path

func (f *File) Path() string

Path returns the path of this File object.

func (*File) UpdateContents

func (f *File) UpdateContents(b []byte)

UpdateContents will stage changes to this file that will be persisted when WriteChanges is called.

func (*File) WriteChanges

func (f *File) WriteChanges(fsys afero.Fs) error

WriteChanges persists any changes to this file to disk.

type Manifest

type Manifest struct {
	Name string         `json:"name"`
	Push []ManifestPush `json:"push,omitempty"`
}

Manifest contains metadata about the custom rules project.

type ManifestPush

type ManifestPush struct {
	CustomRulesID  string `json:"custom_rules_id,omitempty"`
	OrganizationID string `json:"organization_id,omitempty"`
}

ManifestPush contains metadata about where this rule bundle should be pushed to. Currently this will always be the cloud API service.

type Project

type Project struct {
	*Dir
	FS afero.Fs
	// contains filtered or unexported fields
}

Project represents a custom rules project directory. It encapsulates all operations for creating and updating the contents of that directory.

func FromDir

func FromDir(fsys afero.Fs, root string) (*Project, error)

FromDir returns a Project object from the given directory, whether it exists or not.

func (*Project) AddRelation

func (p *Project) AddRelation(contents string) (string, error)

AddRelation adds the given relation rule to the relations library for this project.

func (*Project) AddRule

func (p *Project) AddRule(ruleID string, regoFileName string, contents []byte) (string, error)

AddRule adds a rule to the project. The given rule ID will be transformed to a valid package name and the rego filename will be transformed to fit similar constraints.

func (*Project) AddRuleSpec

func (p *Project) AddRuleSpec(ruleID string, name string, contents []byte) (string, error)

AddRuleSpec adds a rule to the project. The given rule ID will be transformed to a valid package name and the spec name will be transformed to fit similar constraints.

func (*Project) Engine

func (p *Project) Engine(ctx context.Context) (*engine.Engine, error)

func (*Project) InputTypeForRule

func (p *Project) InputTypeForRule(ruleID string) (string, error)

InputTypeForRule returns the input for the given rule ID

func (*Project) ListRules

func (p *Project) ListRules() []string

ListRules lists the rule directories in the project.

func (*Project) Manifest

func (p *Project) Manifest() Manifest

Manifest retrieves a copy of the project's manifest.

func (*Project) Providers

func (p *Project) Providers() (providers []data.Provider)

func (*Project) RelationNames

func (p *Project) RelationNames() ([]string, error)

RelationNames returns the names of all relations defined in the project.

func (*Project) RuleMetadata

func (p *Project) RuleMetadata() (map[string]RuleMetadata, error)

RuleMetadata returns a map of rule ID to rule metadata from all rules in the project.

func (*Project) RuleSpecs

func (p *Project) RuleSpecs() []*RuleSpec

RuleSpecs returns the rule specs in the project. The returned fixtures can be modified in-place, then the changes can be persisted by calling WriteChanges on the project.

func (*Project) UpdateManifest

func (p *Project) UpdateManifest(m Manifest)

UpdateManifest updates the project's manifest.

func (*Project) WriteChanges

func (p *Project) WriteChanges() error

WriteChanges persists any changes to this project back to disk. This operation is (essentially) idempotent.

type RuleMetadata

type RuleMetadata struct {
	ID           string   `json:"id"`
	Severity     string   `json:"severity"`
	Title        string   `json:"title"`
	Description  string   `json:"description"`
	Product      []string `json:"product"`
	Category     string   `json:"category,omitempty"`
	Labels       []string `json:"labels,omitempty"`
	Platform     []string `json:"platform,omitempty"`
	ServiceGroup string   `json:"service_group,omitempty"`
}

RuleMetadata contains all of the rule metadata fields that are supported for custom rules.

type RuleSpec

type RuleSpec struct {
	RuleDirName string
	Input       FSNode
	Expected    *File
	// contains filtered or unexported fields
}

RuleSpec represents an input file or directory and an expected output file.

func (*RuleSpec) ExpectedPath

func (f *RuleSpec) ExpectedPath() string

func (*RuleSpec) UpdateExpected

func (f *RuleSpec) UpdateExpected(contents []byte)

UpdateExpected updates the expected output file for this fixture.

func (*RuleSpec) WriteChanges

func (f *RuleSpec) WriteChanges(fsys afero.Fs) error

WriteChanges persists any changes to this fixture to disk.

Jump to

Keyboard shortcuts

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