Skip to content

Commit

Permalink
docs: update cli call syntax and output format
Browse files Browse the repository at this point in the history
  • Loading branch information
HabibMAALEM committed Dec 11, 2020
1 parent 4f50db9 commit b99698b
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -81,6 +81,7 @@ Available Commands:

Flags:
--auth-basic-token string authentication token used to fetch remote repositories
--concurrent int concurrent worker used to run analysus
-c, --config string path to watchdog configuration file
--docs-link string link to documentation
-h, --help help for watchdog
Expand All @@ -90,7 +91,6 @@ Flags:
--logs-format string logging level (default "json")
--logs-level string logging level (default "info")
--logs-path string path to logs (default "/var/log/watchdog/watchdog.log")
--max-workers int coccurent worker used to run analysus
--output string path to output file
--output-format string report format (default "text")
--plugins-directory string path to plugins directory (default "plugins")
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Expand Up @@ -27,7 +27,7 @@ func Execute(ctx context.Context) error {
func init() {
cobra.OnInitialize(initConfig)
rootCommand.PersistentFlags().Bool("profile", false, "collect the profile to hercules.pprof.")
rootCommand.PersistentFlags().Int("max-workers", 0, "coccurent worker used to run analysus")
rootCommand.PersistentFlags().Int("concurrent", 0, "concurrent worker used to run analysus")
rootCommand.PersistentFlags().Int("security.reveal-secrets", 0, "full or partial reveal of secrets in report and logs")
rootCommand.PersistentFlags().String("auth-basic-token", "", "authentication token used to fetch remote repositories")
rootCommand.PersistentFlags().String("hook-input", "", "standard input <old-value> SP <new-value> SP <ref-name> LF")
Expand Down
4 changes: 2 additions & 2 deletions config/config.yml
Expand Up @@ -36,8 +36,8 @@ logs_level: info
logs_format: json
# logs path
logs_path: /var/log/watchdog/watchdog.log
# number of cocurrent worker user to run analysis
max_workers: 8
# number of cocurrent worker used to run analysis
concurrent: 4
# output file for analysis report
output:
# report format
Expand Down
2 changes: 2 additions & 0 deletions docs/assets/scss/_variables_project.scss
@@ -0,0 +1,2 @@
$primary: #024BB0;
$secondary: #FA5716;
21 changes: 21 additions & 0 deletions docs/content/en/docs/configuration/_index.md
@@ -0,0 +1,21 @@
---
title: "Configuration"
linkTitle: "Configuration"
weight: 2
description: >
Learn how to configure Watchdog.
---

Watchdog configuration uses the [YAML](https://yaml.org/) format.

The file to be edited can be found in:
1. `/etc/watchdog/config.yaml` on \*nix systems when Watchdog is executed as root
2. `~/.watchdog/config.yaml` on \*nix systems when Watchdog is executed as non-root
2. `./config.yaml` on other systems

Configuration example:

```yaml
concurrent: 4
logs_level: "warning"
```
2 changes: 1 addition & 1 deletion docs/content/en/docs/deployment/gitlab.md
Expand Up @@ -24,7 +24,7 @@ For a global deployment, you must create one of the `pre-receive.d`,` post-recei
HOOKS=("pre-receive" "post-receive" "update")
HOOK_TYPE=$(cd $(dirname "${BASH_SOURCE[0]}") >/dev/null 2>&1 && echo ${PWD##*/})
while read -r OLDREV NEWREV REFNAME; do
/usr/local/bin/watchdog \
/usr/local/bin/watchdog analyze \
--docs-link="https://groupe-edf.github.io/watchdog/docs/" \
--hook-type="pre-receive" \
--hook-input="$OLDREV $NEWREV $REFNAME" \
Expand Down
30 changes: 29 additions & 1 deletion docs/content/en/docs/quickstart/output.md
Expand Up @@ -43,6 +43,8 @@ remote: Operation took 43.319478ms
Format
--------------------

### logfmt

The default output format of the messages is [logfmt] (https://brandur.org/logfmt) prefixed by `GL-HOOK-ERR:` to have the possibility of uploading these messages on the Gitlab graphical interface in the case of a direct modification of the code on Gitlab.

```bash
Expand All @@ -55,4 +57,30 @@ severity=high handler=file condition=extension commit=eda373cc message="'*.exe'
* **commit** The current hash of the commit (On 8 characters)
* **message** Issue description

Only high severity issues block commits from being persisted in the Git repository.
Only high severity issues block commits from being persisted in the Git repository.

### json
```bash
[
{
"author": "Habib MAALEM",
"commit": "9560bbeb3b93d9a6d545133dea3e26e0f1fd7a66",
"condition": "secret",
"email": "habib.maalem@gmail.com",
"handler": "security",
"leaks": [
{
"file": "src/main/resources/rsa_server.key",
"line_number": 1,
"rule": "ASYMMETRIC_PRIVATE_KEY",
"severity": "MAJOR",
"tags": [
"key"
]
}
],
"message": "Secrets, token and passwords are forbidden, `src/main/resources/rsa_server.key:----***********************`",
"severity": "low"
}
]
```
10 changes: 5 additions & 5 deletions docs/content/en/docs/quickstart/usage.md
Expand Up @@ -12,11 +12,11 @@ On the developer side, to invoke customs hooks, the user must add a configuratio

``` bash
$ ll /workspaces/project-name
|--docs/
|--src/
|--tests/
|--.gitignore
|--.githooks.yml
|__ docs/
|__ src/
|__ tests/
|__ .gitignore
|__ .githooks.yml
```

.githooks.yml
Expand Down
8 changes: 4 additions & 4 deletions internal/config/config.go
Expand Up @@ -30,8 +30,8 @@ type Options struct {
LogsPath string `mapstructure:"logs-path"`
MaxFileSize uint
MaxRepositorySize uint
// MaxWorkers max workers running at the same time
MaxWorkers int `mapstructure:"max-workers"`
// Concurrent max workers running at the same time
Concurrent int `mapstructure:"concurrent"`
Output string `mapstructure:"output"`
OutputFormat string `mapstructure:"output-format"`
PluginsDirectory string `mapstructure:"plugins-directory"`
Expand Down Expand Up @@ -62,8 +62,8 @@ func (options *Options) Validate() error {
if options.LogsPath == "" {
options.LogsPath = LogsPath
}
if options.MaxWorkers == 0 {
options.MaxWorkers = runtime.NumCPU()
if options.Concurrent == 0 {
options.Concurrent = runtime.NumCPU()
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/analyzer.go
Expand Up @@ -39,7 +39,7 @@ func (analyzer *Analyzer) Analyze(ctx context.Context, commitIter object.CommitI
ctx, cancel := context.WithCancel(ctx)
defer cancel()
defer commitIter.Close()
maxWorkers := make(chan struct{}, analyzer.Options.MaxWorkers)
maxWorkers := make(chan struct{}, analyzer.Options.Concurrent)
if len(analyzer.GitHooks.Hooks) > 0 {
analyzer.Logger.WithFields(logging.Fields{
"correlation_id": util.GetRequestID(ctx),
Expand Down
12 changes: 11 additions & 1 deletion internal/issue/score.go
Expand Up @@ -14,7 +14,7 @@ const (
// Score type used by severity and confidence values
type Score int

// MarshalJSON return score as json
// MarshalJSON marshal score to json
func (score Score) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString("\"")
buffer.WriteString(score.String())
Expand All @@ -34,6 +34,16 @@ func (score Score) String() string {
return "undefined"
}

// UnmarshalJSON unmarshal json to score
func (score *Score) UnmarshalJSON(raw []byte) error {
runes := bytes.Runes(raw)
if runes[0] == '"' && runes[len(runes)-1] == '"' {
runes = runes[1 : len(runes)-1]
}
*score = ParseScore(string(runes))
return nil
}

// ParseScore parse score from string input
func ParseScore(score string) Score {
switch score {
Expand Down

0 comments on commit b99698b

Please sign in to comment.