Documentation ¶
Index ¶
- Variables
- func RuleIDToSafeFileName(ruleID string) (string, error)
- func SafePackageName(s string) (string, error)
- type Dir
- type FSNode
- type File
- type Manifest
- type ManifestPush
- type Project
- func (p *Project) AddRelation(contents string) (string, error)
- func (p *Project) AddRule(ruleID string, regoFileName string, contents []byte) (string, error)
- func (p *Project) AddRuleSpec(ruleID string, name string, contents []byte) (string, error)
- func (p *Project) Engine(ctx context.Context) (*engine.Engine, error)
- func (p *Project) InputTypeForRule(ruleID string) (string, error)
- func (p *Project) ListRules() []string
- func (p *Project) Manifest() Manifest
- func (p *Project) Providers() (providers []data.Provider)
- func (p *Project) RelationNames() ([]string, error)
- func (p *Project) RuleMetadata() (map[string]RuleMetadata, error)
- func (p *Project) RuleSpecs() []*RuleSpec
- func (p *Project) UpdateManifest(m Manifest)
- func (p *Project) WriteChanges() error
- type RuleMetadata
- type RuleSpec
Constants ¶
This section is empty.
Variables ¶
var ErrFailedToCreateDir = errors.New("failed to create directory")
ErrFailedToCreateDir is returned when we were unable to create a directory
var ErrFailedToCreateFile = errors.New("failed to write to file")
ErrFailedToCreateFile is returned when we were unable to create a file
var ErrFailedToMarshalManifest = errors.New("failed to marshal manifest")
ErrFailedToMarshalManifest is returned when we were unable to marshal the manifest to JSON
var ErrFailedToParseRegoFile = errors.New("failed to parse rego file")
var ErrFailedToReadPath = errors.New("failed to read path")
ErrFailedToReadPath is returned when we encountered a filesystem error while reading a path.
var ErrFailedToUnmarshalManifest = errors.New("failed to unmarshal manifest")
ErrFailedToUnmarshalManifest is returned when we were unable to unmarshal the manifest from JSON
var ErrInvalidIdentifier = errors.New("invalid identifier")
ErrInvalidIdentifier is returned when an identifier does not satisfy some constraint.
var ErrRuleDirAlreadyExists = errors.New("rule directory already exists")
ErrRuleDirAlreadyExists is returned when a rule already exists
var ErrRuleSpecAlreadyExists = errors.New("rule spec already exists")
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 SafePackageName ¶
Types ¶
type Dir ¶
type Dir struct {
// contains filtered or unexported fields
}
Dir represents a directory on disk.
func DirFromPath ¶
DirFromPath returns a Dir for the given path whether it exists or not.
func ExistingDir ¶
ExistingDir returns a Dir object that represents an existing directory on disk.
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.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents a file on disk.
func ExistingFile ¶
ExistingFile returns a File object that represents an existing file on disk.
func FileFromPath ¶
FileFromPath returns a File for the given path whether it exists or not.
func (*File) UpdateContents ¶
UpdateContents will stage changes to this file that will be persisted when WriteChanges is called.
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 ¶
Project represents a custom rules project directory. It encapsulates all operations for creating and updating the contents of that directory.
func (*Project) AddRelation ¶
AddRelation adds the given relation rule to the relations library for this project.
func (*Project) AddRule ¶
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 ¶
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) InputTypeForRule ¶
InputTypeForRule returns the input for the given rule ID
func (*Project) RelationNames ¶
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 ¶
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 ¶
UpdateManifest updates the project's manifest.
func (*Project) WriteChanges ¶
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 (*RuleSpec) UpdateExpected ¶
UpdateExpected updates the expected output file for this fixture.