Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move to allowlist and denylist #57

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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