diff --git a/.conform.yaml b/.conform.yaml index e08a2446..d0af3baf 100644 --- a/.conform.yaml +++ b/.conform.yaml @@ -19,4 +19,7 @@ policies: spec: includeSuffixes: - .go - headerFile: LICENSE_HEADER + header: | + /* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ diff --git a/LICENSE_HEADER b/LICENSE_HEADER deleted file mode 100644 index e0032240..00000000 --- a/LICENSE_HEADER +++ /dev/null @@ -1,3 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ diff --git a/internal/policy/license/license.go b/internal/policy/license/license.go index c4f1dea0..0038dcd3 100644 --- a/internal/policy/license/license.go +++ b/internal/policy/license/license.go @@ -24,8 +24,8 @@ type License struct { // ExcludeSuffixes is the Suffixes used to find files that the license policy // should not be applied to. ExcludeSuffixes []string `mapstructure:"excludeSuffixes"` - // LicenseHeaderFile is the path to the license header file. - LicenseHeaderFile string `mapstructure:"headerFile"` + // Header is the contents of the license header. + Header string `mapstructure:"header"` } // Compliance implements the policy.Policy.Compliance function. @@ -33,12 +33,10 @@ func (l *License) Compliance(options *policy.Options) (report policy.Report) { var err error report = policy.Report{} - - var value []byte - if value, err = ioutil.ReadFile(l.LicenseHeaderFile); err != nil { - report.Errors = append(report.Errors, errors.Errorf("Failed to open %s", l.LicenseHeaderFile)) + if l.Header == "" { + report.Errors = append(report.Errors, errors.New("Header is not defined")) + return report } - err = filepath.Walk(".", func(path string, info os.FileInfo, err error) error { if err != nil { return err @@ -58,7 +56,7 @@ func (l *License) Compliance(options *policy.Options) (report policy.Report) { report.Errors = append(report.Errors, errors.Errorf("Failed to open %s", path)) return nil } - ValidateLicenseHeader(&report, info.Name(), contents, value) + ValidateLicenseHeader(&report, info.Name(), contents, []byte(l.Header)) } } }