func (s *Seekret) EnableRuleByRegexp(name string) int {
	return setRuleEnabledByRegexp(s.ruleList, name, true)
}
EnableRule enables rules that match with a regular expression.
package seekret
import (
	"fmt"
	"github.com/apuigsech/seekret/models"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"os"
	"path/filepath"
	"regexp"
	"strings"
)
type Seekret struct {
	ruleList []models.Rule
	objectList []models.Object
	exceptionList []models.Exception
	secretList []models.Secret
}
func NewSeekret() *Seekret {
	s := &Seekret{}
	return s
}
func (s *Seekret) AddRule(rule models.Rule, enabled bool) {
	if enabled {
		rule.Enable()
	}
	s.ruleList = append(s.ruleList, rule)
}
type ruleYaml struct {
	ObjectMatch string
	Match       string
	Unmatch     []string
}
func (s *Seekret) LoadRulesFromFile(file string, defaulEnabled bool) error {
	var ruleYamlMap map[string]ruleYaml
	if file == "" {
		return nil
	}
	filename, _ := filepath.Abs(file)
	ruleBase := filepath.Base(filename)
	if filepath.Ext(ruleBase) == ".rule" {
		ruleBase = ruleBase[0 : len(ruleBase)-5]
	}
	yamlData, err := ioutil.ReadFile(filename)
	if err != nil {
		return err
	}
	err = yaml.Unmarshal(yamlData, &ruleYamlMap)
	if err != nil {
		return err
	}
	for k, v := range ruleYamlMap {
		rule, err := models.NewRule(ruleBase+"."+k, v.Match)
		if err != nil {
			return err
		}
		for _, e := range v.Unmatch {
			rule.AddUnmatch(e)
		}
		s.AddRule(*rule, defaulEnabled)
	}
	return nil
}
func (s *Seekret) LoadRulesFromDir(dir string, defaulEnabled bool) error {
	fi, err := os.Stat(dir)
	if err != nil {
		return err
	}
	if !fi.IsDir() {
		err := fmt.Errorf("%s is not a directory", dir)
		return err
	}
	fileList, err := filepath.Glob(dir + "/*")
	if err != nil {
		return err
	}
	for _, file := range fileList {
		if strings.HasSuffix(file, ".rule") {
			err := s.LoadRulesFromFile(file, defaulEnabled)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
func (s *Seekret) LoadRulesFromPath(path string, defaulEnabled bool) error {
	if path == "" {
		path = DefaultRulesPath()
	}
	dirList := strings.Split(path, ":")
	for _, dir := range dirList {
		err := s.LoadRulesFromDir(dir, defaulEnabled)
		if err != nil {
			return err
		}
	}
	return nil
}
const defaultRulesDir = "$GOPATH/src/github.com/apuigsech/seekret/rules"
func DefaultRulesPath() string {
	rulesPath := os.Getenv("SEEKRET_RULES_PATH")
	if rulesPath == "" {
		rulesPath = os.ExpandEnv(defaultRulesDir)
	}
	return rulesPath
}
func (s *Seekret) ListRules() []models.Rule {
	return s.ruleList
}
func (s *Seekret) EnableRule(name string) error {
	return setRuleEnabled(s.ruleList, name, true)
}
func (s *Seekret) DisableRule(name string) error {
	return setRuleEnabled(s.ruleList, name, false)
}