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

licensetool: embed license DB, update for more modules #3665

Merged
merged 2 commits into from
Dec 2, 2022
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
13 changes: 12 additions & 1 deletion tools/licensescan/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"bytes"
"context"
"debug/buildinfo"
"embed"
"encoding/json"
"fmt"
"io"
Expand All @@ -35,6 +36,9 @@ import (
"sigs.k8s.io/yaml"
)

//go:embed modules/*
var modulesFS embed.FS
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting: eventually we can have it in its own Go package that will make this DB portable across all the tools :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope so :-)


func main() {
rootCmd := buildRootCommand()

Expand Down Expand Up @@ -125,7 +129,14 @@ func RunLicenseScan(ctx context.Context, opts RunLicenseScanOptions) error {
modules = append(modules, module)

p := filepath.Join("modules", module.Name, module.Version+".yaml")
b, err := ioutil.ReadFile(p)
b, err := os.ReadFile(p)
if err != nil && os.IsNotExist(err) {
b2, err2 := modulesFS.ReadFile(p)
if err2 == nil {
b = b2
Copy link
Contributor

Choose a reason for hiding this comment

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

so this will ensure license info from the moduleFS gets written back to local FS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, ish. The workflow I use is to run it against the binary. Then I search for license: TODO go through and fill in any missing licenses that are generated. The link to the go package DB makes this easy, if a little tedious. Then I commit the files, and then yes the go:embed ensures that (once merged) they are automatically embedded in as part of go build.

err = err2
}
Copy link
Contributor

Choose a reason for hiding this comment

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

err2 != nil is being ignored and I believe that's intentional because err is what we care about in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is deliberate (I think), but I think I'll take a second look and maybe log a V(4) message to make the code at least more self-explanatory.

}
if err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/bitbucket.org/creachadair/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/cloud.google.com/go/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/cloud.google.com/go/iam/v0.3.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/cloud.google.com/go/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/cloud.google.com/go/v0.102.1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/cloud.google.com/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/Azure/go-autorest/autorest/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/Azure/go-autorest/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/GoogleCloudPlatform/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/GoogleContainerTools/kpt/porch/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/GoogleContainerTools/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/MakeNowJust/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/apparentlymart/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# https://pkg.go.dev/github.com/apparentlymart/go-textseg/[email protected]
license: Apache-2.0,MIT,Unicode-DFS-2016
licenseURLs:
- https://raw.githubusercontent.com/apparentlymart/go-textseg/master/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/cenkalti/[email protected]+incompatible
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/chai2010/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/emicklei/go-restful/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/evanphx/json-patch/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/fatih/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/golang-jwt/jwt/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/golang/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/golang/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/google/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/google/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/google/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/googleapis/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/googleapis/gax-go/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/googleapis/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/grpc-ecosystem/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/hcl/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/terraform-provider-google-beta@(devel)
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/hashicorp/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/mattn/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/mattn/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/mitchellh/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/mitchellh/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/mitchellh/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/mitchellh/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/mitchellh/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/nasa9084/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/sirupsen/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/spf13/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/spyzhov/[email protected]
license: MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/terraform-providers/[email protected]
license: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/vmihailenco/msgpack/[email protected]
license: BSD-2-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/vmihailenco/[email protected]
license: BSD-2-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/github.com/zclconf/[email protected]
license: MIT
2 changes: 2 additions & 0 deletions tools/licensescan/modules/go.opencensus.io/v0.23.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/golang.org/x/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/golang.org/x/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/golang.org/x/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/golang.org/x/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/golang.org/x/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/golang.org/x/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/golang.org/x/[email protected]
license: BSD-3-Clause
2 changes: 2 additions & 0 deletions tools/licensescan/modules/google.golang.org/api/v0.92.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/google.golang.org/[email protected]
license: BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/google.golang.org/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/google.golang.org/grpc/v1.48.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/google.golang.org/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/k8s.io/api/v0.23.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/k8s.io/api/v0.25.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/k8s.io/apimachinery/v0.23.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/k8s.io/apimachinery/v0.25.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/k8s.io/cli-runtime/v0.25.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/k8s.io/client-go/v0.23.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/k8s.io/client-go/v0.25.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/k8s.io/component-base/v0.25.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/k8s.io/klog/v2/v2.70.1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/klog/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/k8s.io/kubectl/v0.25.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/k8s.io/[email protected]
license: Apache-2.0
2 changes: 2 additions & 0 deletions tools/licensescan/modules/sigs.k8s.io/cli-utils/v0.34.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/sigs.k8s.io/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/sigs.k8s.io/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/sigs.k8s.io/[email protected]
license: Apache-2.0, BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/sigs.k8s.io/[email protected]
license: Apache-2.0, BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/sigs.k8s.io/structured-merge-diff/[email protected]
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://pkg.go.dev/sigs.k8s.io/structured-merge-diff/[email protected]
license: Apache-2.0