-
Notifications
You must be signed in to change notification settings - Fork 369
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
validate-krew-manifest: add license check #642
Changes from 1 commit
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ import ( | |
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/klog" | ||
|
||
"sigs.k8s.io/krew/internal/environment" | ||
"sigs.k8s.io/krew/internal/index/indexscanner" | ||
"sigs.k8s.io/krew/internal/index/validation" | ||
"sigs.k8s.io/krew/internal/installation" | ||
|
@@ -159,7 +160,44 @@ func installPlatformSpec(manifestFile string, p index.Platform) error { | |
output := strings.ReplaceAll(string(b), "\n", "\n\t") | ||
return errors.Wrapf(err, "plugin install command failed: %s", output) | ||
} | ||
return nil | ||
|
||
err = validateLicenseFileExists(tmpDir) | ||
return errors.Wrap(err, "LICENSE (or alike) file is not extracted from the archive as part of installation") | ||
} | ||
|
||
var licenseFiles = []string{ | ||
"license", | ||
"license.txt", | ||
"copying", | ||
"copying.txt", | ||
} | ||
|
||
func validateLicenseFileExists(krewRoot string) error { | ||
dir := environment.NewPaths(krewRoot).InstallPath() | ||
var files []string | ||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info.Mode().IsRegular() { | ||
files = append(files, info.Name()) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to walk installation directory") | ||
} | ||
|
||
for _, f := range files { | ||
klog.V(8).Infof("found installed file: %s", f) | ||
f = strings.ToLower(filepath.Base(f)) | ||
for _, lf := range licenseFiles { | ||
if lf == f { | ||
return 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. nit: klog.V(8).Infof("found license file: %s", f) 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. done |
||
} | ||
} | ||
} | ||
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. Maybe use a map instead? var licenseFiles = map[string]bool{
"license": true,
"license.txt": true,
"copying": true,
"copying.txt":true,
}
// ...
if licenseFiles[f] {
return 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. done |
||
return errors.Errorf("could not find license file among [%s]", strings.Join(files, ", ")) | ||
} | ||
|
||
// findAnyMatchingPlatform finds an <os,arch> pair matches to given selector | ||
|
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.
Maybe also allow
license.md
?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.
done