Skip to content

Configurable check#150

Merged
Bobgy merged 9 commits intogoogle:masterfrom
becoded:configurable-check
Sep 28, 2022
Merged

Configurable check#150
Bobgy merged 9 commits intogoogle:masterfrom
becoded:configurable-check

Conversation

@becoded
Copy link
Copy Markdown
Contributor

@becoded becoded commented Sep 21, 2022

Allow to configure the check action.
Added flags:

  --disallowed_types  list of disallowed types
  --allowed_licenses list of allowed license names

Keeping the default behaviour of just checking the forbidden licenses.

check.go Outdated
return false
}

func getSupportedLicenseNames() []string {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Curious, why do we need this list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't find a method in github.com/google/licenseclassifier to get all defined license names.
It is used here to validate the input of flag allowed_license_names.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there a strong need to do this validation? If there is a typo, the check command fails and reports the correct license name in error message.

An extraneous invalid license name seems not much harm either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You have a valid point! I removed the validation.

@Bobgy
Copy link
Copy Markdown
Collaborator

Bobgy commented Sep 23, 2022

Thank you for the contribution!

Let me start with high level questions.

Can you clarify the use case for allowed licenses? That seems too flexible as interface, it's probably only useful when very limited license types are allowed.

Would it be simpler asking someone with such flexible use case to directly parse the license CSV file and write custom validation?

@becoded
Copy link
Copy Markdown
Contributor Author

becoded commented Sep 23, 2022

Currently, only the list of forbidden licenses, defined in google/licenseclassifier, is validated.
And there is no way to change that, so it doesn't leave any room for flexibility in controlling that.
So for that reason, I added the other flags (--exclude_forbidden, --exclude_notice, --exclude_permissive, --exclude_reciprocal, --exclude_restricted, --exclude_unencumbered).
However, these sets are fixed.
I have a case where a subset is allowed and for others, we need special approval.
By allowing to create your own list of allowed licenses --allowed_license_names we are able to verify exactly what we need.

Personally, I don't think it would be simpler to parse the report.
A part of this tool is written to check licenses, it makes sense to me that you can also control what is checked. Otherwise you could argue also that there is no need for the check action as you could also write a parser to check for the forbidden licenses.

@Bobgy
Copy link
Copy Markdown
Collaborator

Bobgy commented Sep 26, 2022

To explain why I'm asking, this tool was built primarily for Google's own use-cases for open source go projects, so I am seeking a balance between maintenance cost vs use-case coverage. I'm asking to learn more about why this feature is useful to you.

I think your use-case convinces me it may be useful to more people. Thank you for explaining that!

@Bobgy
Copy link
Copy Markdown
Collaborator

Bobgy commented Sep 26, 2022

Regarding the interface, do the following changes make it slightly simpler and more consistent?

Also, I think we should add validation and description that, the two flags cannot be used at the same time.

@becoded
Copy link
Copy Markdown
Contributor Author

becoded commented Sep 26, 2022

I changed the interface. I did name it types instead of categories as that is what is used in multiple places in this repo and in google/licenseclassifier

@Bobgy
Copy link
Copy Markdown
Collaborator

Bobgy commented Sep 27, 2022

nit: update PR description?

README.md Outdated
* See supported license names: [github.com/google/licenseclassifier](https://github.com/google/licenseclassifier/blob/e6a9bb99b5a6f71d5a34336b8245e305f5430f99/license_type.go#L28)


Typically, specify the Go package that builds your Go binary.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you move this paragraph above? It's more important than exlude options I feel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added it to the top of the usage block as it is helpful for all comments.

check.go Outdated

func init() {
checkCmd.Flags().StringSliceVar(&allowedLicenses, "allowed_licenses", []string{}, "list of allowed license names, can't be used in combination with disallowed_types")
checkCmd.Flags().StringSliceVar(&disallowedTypes, "disallowed_types", []string{}, "list of disallowed license types, can't be used in combination with allowed_licenses")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add comment about default behavior?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

check.go Outdated
case "unencumbered":
excludedLicenseTypes = append(excludedLicenseTypes, licenses.Unencumbered)
default:
fmt.Fprintf(os.Stderr, "Unknown license type '%s' provided", v)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also print the list of supported types?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

found = true
}

if hasLicenseType && isDisallowedLicenseType(licenseType, disallowedLicenseTypes) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See previous unmerged PR for a reference of how to handle unknown types: #44

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added support for unknown and added it to the default set.

Didn't implement different exit codes.
In the past, it stopped as soon as one forbidden license was found. In the meantime, it reports all forbidden licenses.


```shell
go-licenses check <package> [package...]
go-licenses check <package> [package...]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also comment default behavior is disallow forbidden and unknown licenses?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added it to the title

@hansinator
Copy link
Copy Markdown

hey thank you for this PR and hopefully this gets merged soon, b/c we need to maintain a fork of license checker and it causes trouble with replace directives and deprecated go get / go install behaviour. basically soft-forks of "go install"-ed things are no longer a supported use-case since a few go versions so I'd really appreciate it if this goes upstream

@becoded becoded requested a review from Bobgy September 28, 2022 11:03
Copy link
Copy Markdown
Collaborator

@Bobgy Bobgy left a comment

Choose a reason for hiding this comment

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

Awesome 👍!
Thank you for the great contribution!

@Bobgy Bobgy merged commit 5b8f2a2 into google:master Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants