Skip to content
Open
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
5 changes: 5 additions & 0 deletions LicenceTerms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"hashicorp, inc.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why do we need hashicorp, inc. in this file now ?

Also "copyright" is missing in this list. Can you also move this file under addlicense directory ?

"mozilla public",
"spdx-license-identifier",
]
26 changes: 23 additions & 3 deletions addlicense/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,27 @@ func hasLicense(b []byte) bool {
if len(b) < 1000 {
n = len(b)
}
return bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright")) ||
bytes.Contains(bytes.ToLower(b[:n]), []byte("mozilla public")) ||
bytes.Contains(bytes.ToLower(b[:n]), []byte("spdx-license-identifier"))

// Default conditions
defaultTerms := []string{"hashicorp, inc.", "mozilla public", "spdx-license-identifier"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: We should now be iterating only on the list present in the json file

We can keep the default terms in the LicenseTerms.json


// Load conditions from config file
configPath := "../LicenceCopywrite.json"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Having the file path hardcoded over here prevents users from adding any new licenses in the cli
Maybe we can have the file path as a parameter in the hcl config

file, err := os.ReadFile(configPath)
if err == nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: We should add the capability for this function to return errors

Instead of having the function silently failing and using default terms, we should let the user know that the Readfile function failed

var customTerms []string
if json.Unmarshal(file, &customTerms) == nil && len(customTerms) > 0 {
defaultTerms = customTerms
}
}

// Check for license terms
content := bytes.ToLower(b[:n])
for _, term := range defaultTerms {
if bytes.Contains(content, []byte(strings.ToLower(term))) {
return true
}
}
return false
}