This repository was archived by the owner on Jan 13, 2020. It is now read-only.
forked from apuigsech/git-seekret
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain_config.go
78 lines (68 loc) · 1.58 KB
/
main_config.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"github.com/libgit2/git2go"
"github.com/urfave/cli"
"strings"
)
func GitSeekretConfig(c *cli.Context) error {
if c.Bool("init") {
err := gs.InitConfig()
if err != nil {
return err
}
} else {
err := gs.LoadConfig(true)
if git.IsErrorClass(err, git.ErrClassConfig) {
return fmt.Errorf("Config not initialised - Try: 'git-seekret config --init'")
}
if err != nil {
return err
}
}
set := c.String("set")
if set != "" {
a := strings.SplitN(set, "=", 2)
key := a[0]
value := ""
if len(a) == 2 {
value = a[1]
fmt.Println("Value:", value)
}
err := setConfig(gs.config, key, value)
if err != nil {
return err
}
}
gs.SaveConfig()
showConfig(gs.config)
return nil
}
func setConfig(config *gitSeekretConfig, key string, value interface{}) error {
switch key {
case "version":
return fmt.Errorf("not suported")
case "rulespath":
rulespath, ok := value.(string)
if !ok {
return fmt.Errorf("invalid format")
}
config.rulespath = rulespath
case "rulesenabled":
return fmt.Errorf("not suported - change enabled rules using 'git-seekret rules'")
case "exceptionsfile":
exceptionsfile, ok := value.(string)
if !ok {
return fmt.Errorf("invalid format")
}
config.exceptionsfile = exceptionsfile
}
return nil
}
func showConfig(config *gitSeekretConfig) {
fmt.Printf("Config:\n")
fmt.Printf("\tversion = %d\n", config.version)
fmt.Printf("\trulespath = %s\n", config.rulespath)
fmt.Printf("\trulesenabled = %s\n", config.rulesenabled)
fmt.Printf("\texceptionsfile = %s\n", config.exceptionsfile)
}