Skip to content

Commit 519b56c

Browse files
authored
licensetool: embed license DB, update for more modules (#3665)
* licensescan: Embed licenses in binary We now embed some licenses using go:embed, so we don't need to set up a modules DB in every project. A local modules folder is still checked first, and TODO files are still written locally to a local modules folder. * licensescan: Update modules Update a bunch of licenses from different places I've been running the licensetool.
1 parent 960a945 commit 519b56c

File tree

92 files changed

+196
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+196
-1
lines changed

tools/licensescan/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"bytes"
2020
"context"
2121
"debug/buildinfo"
22+
"embed"
2223
"encoding/json"
2324
"fmt"
2425
"io"
@@ -35,6 +36,9 @@ import (
3536
"sigs.k8s.io/yaml"
3637
)
3738

39+
//go:embed modules/*
40+
var modulesFS embed.FS
41+
3842
func main() {
3943
rootCmd := buildRootCommand()
4044

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

127131
p := filepath.Join("modules", module.Name, module.Version+".yaml")
128-
b, err := ioutil.ReadFile(p)
132+
b, err := os.ReadFile(p)
133+
if err != nil && os.IsNotExist(err) {
134+
b2, err2 := modulesFS.ReadFile(p)
135+
if err2 == nil {
136+
b = b2
137+
err = err2
138+
}
139+
}
129140
if err != nil {
130141
if os.IsNotExist(err) {
131142
if err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pkg.go.dev/bitbucket.org/creachadair/[email protected]
2+
license: BSD-3-Clause
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pkg.go.dev/cloud.google.com/go/[email protected]
2+
license: Apache-2.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pkg.go.dev/cloud.google.com/go/[email protected]
2+
license: Apache-2.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pkg.go.dev/cloud.google.com/[email protected]
2+
license: Apache-2.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pkg.go.dev/github.com/Azure/go-autorest/autorest/[email protected]
2+
license: Apache-2.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pkg.go.dev/github.com/Azure/go-autorest/[email protected]
2+
license: Apache-2.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pkg.go.dev/github.com/GoogleCloudPlatform/[email protected]
2+
license: Apache-2.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pkg.go.dev/github.com/GoogleContainerTools/kpt/porch/[email protected]
2+
license: Apache-2.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pkg.go.dev/github.com/GoogleContainerTools/[email protected]
2+
license: Apache-2.0

0 commit comments

Comments
 (0)