appcfg

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package appcfg controls actions that can be performed around the app's configuration file and config directory. Currently we use HCL as the config file format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigFilePath

func ConfigFilePath() string

ConfigFilePath returns the absolute path of the configuration file. By default this is ~/.tfvet.d/.tfvet.hcl

func ConfigPath

func ConfigPath() string

ConfigPath returns the absolute config path determined by environment variable. The default is ~/.tfvet.d

func CreateNewFile

func CreateNewFile() error

CreateNewFile creates a new empty config file

func RepoPath

func RepoPath(ruleset string) string

RepoPath returns the absolute path for the repo directory inside of a specific ruleset. By default this is ~/.tfvet.d/rulesets.d/<ruleset>/repo

func RepoRulesPath

func RepoRulesPath(ruleset string) string

RepoRulesPath returns the absolute path for the rules directory inside of a repo directory of a ruleset By default this is ~/.tfvet.d/rulesets.d/<ruleset>/repo/rules

func RulePath

func RulePath(ruleset, ruleID string) string

RulePath returns the absolute path for a rule within a ruleset directory. By default this is ~/.tfvet.d/rulesets.d/<ruleset>/<ruleID>

func RulesetPath

func RulesetPath(ruleset string) string

RulesetPath returns the directory path to a supplied ruleset name. By default this is ~/.tfvet.d/rulesets.d/<ruleset>

func RulesetsPath

func RulesetsPath() string

RulesetsPath returns the absolute directory path of the directory that stores rulesets. By default this is ~/.tfvet.d/rulesets.d

Note: this is not the ruleset itself just the parent folder. Use RulesetPath() to get a path to a specific ruleset.

Types

type Appcfg

type Appcfg struct {
	Rulesets []models.Ruleset `hcl:"ruleset,block"`
}

Appcfg represents the parsed hcl config of the main app configuration. We wrap this so that we can add other attributes in here.

func GetConfig

func GetConfig() (*Appcfg, error)

GetConfig parses the on disk config file and returns its representation in golang.

func (*Appcfg) AddRuleset

func (appcfg *Appcfg) AddRuleset(rs models.Ruleset) error

AddRuleset adds a new ruleset. Returns error if ruleset already exists.

func (*Appcfg) GetRule

func (appcfg *Appcfg) GetRule(rulesetName, ruleID string) (models.Rule, error)

GetRule returns the rule object of a given name. Returns an error if ruleset or rule isn't found.

func (*Appcfg) GetRuleset

func (appcfg *Appcfg) GetRuleset(name string) (models.Ruleset, error)

GetRuleset returns the ruleset object of a given name. Returns an error if ruleset isn't found.

func (*Appcfg) RepositoryExists

func (appcfg *Appcfg) RepositoryExists(repo string) bool

RepositoryExists checks to see if the config already has an entry for the repository in the config.

func (*Appcfg) RulesetExists

func (appcfg *Appcfg) RulesetExists(name string) bool

RulesetExists determines if a ruleset has already been added.

func (*Appcfg) SetRuleEnabled

func (appcfg *Appcfg) SetRuleEnabled(ruleset, rule string, enabled bool) error

SetRuleEnabled changes the enabled attribute on a rule. Returns an error if the ruleset or rule isn't found.

func (*Appcfg) SetRulesetEnabled

func (appcfg *Appcfg) SetRulesetEnabled(name string, enabled bool) error

SetRulesetEnabled changes the enabled attribute on a ruleset. Returns an error if the ruleset isn't found.

func (*Appcfg) UpdateRuleset

func (appcfg *Appcfg) UpdateRuleset(rs models.Ruleset) error

UpdateRuleset updates an existing ruleset. Returns an error if the ruleset could not be found.

func (*Appcfg) UpsertRule

func (appcfg *Appcfg) UpsertRule(rulesetName string, newRule models.Rule) error

UpsertRule adds a new rule to an already established ruleset if it does not exist. If the rule already exists it simply updates the rule with the newer information. Returns an error if the ruleset is not found or there was an error writing to the file.

Jump to

Keyboard shortcuts

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