-
Notifications
You must be signed in to change notification settings - Fork 21
Dynamic license terms #124
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
"hashicorp, inc.", | ||
"mozilla public", | ||
"spdx-license-identifier", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
file, err := os.ReadFile(configPath) | ||
if err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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 | ||
} | ||
|
There was a problem hiding this comment.
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 underaddlicense
directory ?