Repository navigation
Expand file tree
/
Copy pathconfig.go
More file actions
executable file
·61 lines (49 loc) · 1.59 KB
/
Copy pathconfig.go
File metadata and controls
executable file
·61 lines (49 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package core
import (
"errors"
"io/ioutil"
"os"
"path"
"strings"
"gopkg.in/yaml.v3"
)
type Config struct {
GitHubAccessTokens []string `yaml:"github_access_tokens"`
SlackWebhook string `yaml:"slack_webhook,omitempty"`
BlacklistedExtensions []string `yaml:"blacklisted_extensions"`
BlacklistedPaths []string `yaml:"blacklisted_paths"`
BlacklistedEntropyExtensions []string `yaml:"blacklisted_entropy_extensions"`
Signatures []ConfigSignature `yaml:"signatures"`
}
type ConfigSignature struct {
Name string `yaml:"name"`
Part string `yaml:"part`
Match string `yaml:"match,omitempty`
Regex string `yaml:"regex,omitempty"`
Verifier string `yaml:"verifier,omitempty"`
}
func ParseConfig() (*Config, error) {
config := &Config{}
dir, _ := os.Getwd()
data, err := ioutil.ReadFile(path.Join(dir, "config.yaml"))
if err != nil {
return config, err
}
err = yaml.Unmarshal([]byte(data), config)
if err != nil {
return config, err
}
return config, nil
}
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = Config{}
type plain Config
err := unmarshal((*plain)(c))
if err != nil {
return err
}
if len(c.GitHubAccessTokens) < 1 || strings.TrimSpace(strings.Join(c.GitHubAccessTokens, "")) == "" {
return errors.New("You need to provide at least one GitHub Access Token. See https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line")
}
return nil
}