Skip to content

Commit

Permalink
move to allowlist and denylist
Browse files Browse the repository at this point in the history
  • Loading branch information
frapposelli committed Jan 19, 2021
1 parent e7528bc commit a4048a3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .wwhrd.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
blacklist:
denylist:
- GPL-2.0

whitelist:
allowlist:
- Apache-2.0
- MIT
- ISC
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ brew install frapposelli/tap/wwhrd

Configuration for `wwhrd` is stored in `.wwhrd.yml` at the root of the repo you want to check.

The format is borrowed from [Anderson](https://github.com/xoebus/anderson) and it's 1:1 compatible (just run `wwhrd check -f .anderson.yml`).
The format is compatible with [Anderson](https://github.com/xoebus/anderson), just run `wwhrd check -f .anderson.yml`.

```yaml
---
blacklist:
denylist:
- GPL-2.0

whitelist:
allowlist:
- Apache-2.0
- MIT

Expand Down
4 changes: 2 additions & 2 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ func (c *Check) Execute(args []string) error {

// Make a map out of the blacklist
blacklist := make(map[string]bool)
for _, v := range t.Blacklist {
for _, v := range t.Denylist {
blacklist[v] = true
}

// Make a map out of the whitelist
whitelist := make(map[string]bool)
for _, v := range t.Whitelist {
for _, v := range t.Allowlist {
whitelist[v] = true
}

Expand Down
25 changes: 21 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,36 @@ import (
"gopkg.in/yaml.v2"
)

type OldConfig struct {
Allowlist []string `yaml:"whitelist"`
Denylist []string `yaml:"blacklist"`
Exceptions []string `yaml:"exceptions"`
}

type Config struct {
Whitelist []string `yaml:"whitelist"`
Blacklist []string `yaml:"blacklist"`
Allowlist []string `yaml:"allowlist"`
Denylist []string `yaml:"denylist"`
Exceptions []string `yaml:"exceptions"`
}

func ReadConfig(config []byte) (*Config, error) {

t := Config{}
var err error
if err = yaml.NewDecoder(bytes.NewReader(config)).Decode(&t); err != nil {
old := OldConfig{}

// Parse new format
if err := yaml.NewDecoder(bytes.NewReader(config)).Decode(&t); err != nil {
return nil, err
}

// Parse old format
if err := yaml.NewDecoder(bytes.NewReader(config)).Decode(&old); err != nil {
return nil, err
}

t.Allowlist = append(t.Allowlist, old.Allowlist...)
t.Denylist = append(t.Denylist, old.Denylist...)
t.Exceptions = append(t.Exceptions, old.Exceptions...)

return &t, nil
}
4 changes: 2 additions & 2 deletions wwhrd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func TestCliCommandsErrors(t *testing.T) {
}

var mockConf = `---
whitelist:
allowlist:
- BSD-3-Clause
`

var mockConfBL = `---
blacklist:
denylist:
- BSD-3-Clause
`

Expand Down

0 comments on commit a4048a3

Please sign in to comment.