-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add exit-level parameter * sort Levels by risk * rename file * create config pkg and global Conf * change abend algorithm * update readme
- Loading branch information
1 parent
25d0a13
commit 135d2e5
Showing
9 changed files
with
156 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package config | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"strings" | ||
|
||
"github.com/goodwithtech/dockle/pkg/types" | ||
|
||
"github.com/goodwithtech/dockle/pkg/log" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
const ( | ||
dockleIgnore = ".dockleignore" | ||
) | ||
|
||
var exitLevelMap = map[string]int{ | ||
"info": types.InfoLevel, | ||
"INFO": types.InfoLevel, | ||
"warn": types.WarnLevel, | ||
"WARN": types.WarnLevel, | ||
"fatal": types.FatalLevel, | ||
"FATAL": types.FatalLevel, | ||
} | ||
|
||
type Config struct { | ||
IgnoreMap map[string]struct{} | ||
ExitCode int | ||
ExitLevel int | ||
} | ||
|
||
var Conf Config | ||
|
||
func CreateFromCli(c *cli.Context) { | ||
ignoreRules := c.StringSlice("ignore") | ||
Conf = Config{ | ||
IgnoreMap: getIgnoreCheckpointMap(ignoreRules), | ||
ExitCode: c.Int("exit-code"), | ||
ExitLevel: getExitLevel(c.String("exit-level")), | ||
} | ||
} | ||
|
||
func getExitLevel(param string) (exitLevel int) { | ||
exitLevel, ok := exitLevelMap[param] | ||
if !ok { | ||
return types.WarnLevel | ||
} | ||
return exitLevel | ||
} | ||
|
||
func getIgnoreCheckpointMap(ignoreRules []string) map[string]struct{} { | ||
ignoreCheckpointMap := map[string]struct{}{} | ||
// from cli command | ||
for _, rule := range ignoreRules { | ||
ignoreCheckpointMap[rule] = struct{}{} | ||
} | ||
|
||
// from ignore file | ||
f, err := os.Open(dockleIgnore) | ||
if err != nil { | ||
log.Logger.Debug("There is no .dockleignore file") | ||
// dockle must work even if there isn't ignore file | ||
return ignoreCheckpointMap | ||
} | ||
scanner := bufio.NewScanner(f) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
line = strings.TrimSpace(line) | ||
if strings.HasPrefix(line, "#") || line == "" { | ||
continue | ||
} | ||
log.Logger.Debugf("Add new ignore code: %s", line) | ||
ignoreCheckpointMap[line] = struct{}{} | ||
} | ||
return ignoreCheckpointMap | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.