licenses

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

README

License

MIT

MIT license text as an input to the scanning service:



Permission is hereby granted, free of charge, to any person obtaining a copy of <<match=this|the>> <<match=.*>> <<beginOptional>>software <<match=and/?o?r?>> associated documentation<<endOptional>> <<beginOptional>>SOFTWARE<<endOptional>> <<beginOptional>><<match=files?>> (the <<match="?Software"?|"?Materials"?>>),<<endOptional>> to deal in the <<match=Software|Code|Materials>> without restriction, including without <<match=limitation,?>> <<beginOptional>>on<<endOptional>> the <<beginOptional>>irrevocable, perpetual, worldwide, and royalty-free<<endOptional>> rights to use, copy, modify, merge, publish, distribute, <<beginOptional>>sublicense,<<endOptional>> <<beginOptional>>distribute with modifications,<<endOptional>> <<beginOptional>><<match=sub ?license,?>><<endOptional>> <<beginOptional>>display, perform, create derivative works from<<endOptional>> <<match=and ?/ ?or>> sell copies of the <<match=Software|code|Materials>>, <<beginOptional>> both in source<<endOptional>> and <<beginOptional>>object code form, and<<endOptional>> to permit persons to whom the <<match=Software|code|materials>> <<match=is|are>> furnished to do so, subject to the following <<match=conditions|disclaimer>>:

<<beginOptional>>
The above copyright notice<<match= and|,>> this permission notice <<beginOptional>>and the disclaimer statement<<endOptional>> <<beginOptional>>(including the next
paragraph)<<endOptional>> <<match=shall|must>> be included in all copies or substantial portions of the <<match=Software|code|materials>>.
<<endOptional>>

Normalized license text after running through the normalization guidelines:

permission is hereby granted, free of charge, to any person obtaining a copy of <<this|the>> <<.{0,144}>> <<omitable>>software <<and/?o?r?>> associated documentation<</omitable>> <<omitable>>software<</omitable>> <<omitable>><<files?>> (the <<'?software'?|'?materials'?>>),<</omitable>> to deal in the <<software|code|materials>> without restriction, including without <<limitation,?>> <<omitable>>on<</omitable>> the <<omitable>>irrevocable, perpetual, worldwide, and royalty-free<</omitable>> rights to use, copy, modify, merge, publish, distribute, <<omitable>>sublicense,<</omitable>> <<omitable>>distribute with modifications,<</omitable>> <<omitable>><<sub ?license,?>><</omitable>> <<omitable>>display, perform, create derivative works from<</omitable>> <<and ?/ ?or>> sell copies of the <<software|code|materials>>, <<omitable>> both in source<</omitable>> and <<omitable>>object code form, and<</omitable>> to permit persons to whom the <<software|code|materials>> <<is|are>> furnished to do so, subject to the following <<conditions|disclaimer>>: <<omitable>> the above copyright notice<< and|,>> this permission notice <<omitable>>and the disclaimer statement<</omitable>> <<omitable>>(including the next paragraph)<</omitable>> <<shall|must>> be included in all copies or substantial portions of the <<software|code|materials>>. <</omitable>>

License with the metadata:

{
  id: 'MIT',
  name: 'MIT License',
  spdx_standard: true,
  osi_approved: true,
  primary_patterns: [
    {
      text: '\n' +
        '\n' +
        '\n' +
        'Permission is hereby granted, free of charge, to any person obtaining a copy of <<match=this|the>> <<match=.*>> <<beginOptional>>software <<match=and/?o?r?>> associated documentation<<endOptional>> <<beginOptional>>SOFTWARE<<endOptional>> <<beginOptional>><<match=files?>> (the <<match="?Software"?|"?Materials"?>>),<<endOptional>> to deal in the <<match=Software|Code|Materials>> without restriction, including without <<match=limitation,?>> <<beginOptional>>on<<endOptional>> the <<beginOptional>>irrevocable, perpetual, worldwide, and royalty-free<<endOptional>> rights to use, copy, modify, merge, publish, distribute, <<beginOptional>>sublicense,<<endOptional>> <<beginOptional>>distribute with modifications,<<endOptional>> <<beginOptional>><<match=sub ?license,?>><<endOptional>> <<beginOptional>>display, perform, create derivative works from<<endOptional>> <<match=and ?/ ?or>> sell copies of the <<match=Software|code|Materials>>, <<beginOptional>> both in source<<endOptional>> and <<beginOptional>>object code form, and<<endOptional>> to permit persons to whom the <<match=Software|code|materials>> <<match=is|are>> furnished to do so, subject to the following <<match=conditions|disclaimer>>:\n' +
        '\n' +
        '<<beginOptional>>\n' +
        'The above copyright notice<<match= and|,>> this permission notice <<beginOptional>>and the disclaimer statement<<endOptional>> <<beginOptional>>(including the next\n' +
        'paragraph)<<endOptional>> <<match=shall|must>> be included in all copies or substantial portions of the <<match=Software|code|materials>>.\n' +
        '<<endOptional>>\n',
      regex: /permission is hereby granted, free of charge, to any person obtaining a copy of ?(?:(this|the) ?) ?(?:(.{0,144}) ?) ?(?:software ?(?:(and\/?o?r?) ?)associated documentation ?)? ?(?:software ?)? ?(?: ?(?:(files?) ?)\(the ?(?:('?software'?|'?materials'?) ?)\), ?)?to deal in the ?(?:(software|code|materials) ?)without restriction, including without ?(?:(limitation,?) ?) ?(?:on ?)?the ?(?:irrevocable, perpetual, worldwide, and royalty-free ?)?rights to use, copy, modify, merge, publish, distribute, ?(?:sublicense, ?)? ?(?:distribute with modifications, ?)? ?(?: ?(?:(sub ?license,?) ?) ?)? ?(?:display, perform, create derivative works from ?)? ?(?:(and ?\/ ?or) ?)sell copies of the ?(?:(software|code|materials) ?), ?(?:both in source ?)?and ?(?:object code form, and ?)?to permit persons to whom the ?(?:(software|code|materials) ?) ?(?:(is|are) ?)furnished to do so, subject to the following ?(?:(conditions|disclaimer) ?): ?(?:the above copyright notice ?(?:( and|,) ?)this permission notice ?(?:and the disclaimer statement ?)? ?(?:\(including the next paragraph\) ?)? ?(?:(shall|must) ?)be included in all copies or substantial portions of the ?(?:(software|code|materials) ?)\. ?)?/,
      capture_groups: [Array],
      prechecks_required: [Array],
      filename: 'license_MIT.txt'
    },
    {
      text: '<<match=\\(?(?:the )?\\bMIT License\\b(?: license)?\\)?>>',
      regex: / ?(?:(\(?(?:the )?\bmit license\b(?: license)?\)?) ?)/,
      capture_groups: [Array],
      prechecks_required: [Array],
      filename: 'License Name'
    },
    {
      text: '<<match=(?:https?://)?(www\\.)?opensource\\.org/licenses/mit-license\\.php(?:\\/[a-z0-9._-]*)*\\/?>>',
      regex: / ?(?:((?:http?:\/\/)?(www\.)?opensource\.org\/licenses\/mit-license\.php(?:\/[a-z0-9._-]*)*\/?) ?)/,
      capture_groups: [Array],
      prechecks_required: false,
      filename: 'url'
    },
    {
      text: '<<match=(?:https?://)?(www\\.)?opensource\\.org/licenses/MIT(?:\\/[a-z0-9._-]*)*\\/?>>',
      regex: / ?(?:((?:http?:\/\/)?(www\.)?opensource\.org\/licenses\/mit(?:\/[a-z0-9._-]*)*\/?) ?)/,
      capture_groups: [Array],
      prechecks_required: false,
      filename: 'url'
    }
  ],
  primary_pattern_sources: [
    {
      source_text: '\n' +
        '\n' +
        '\n' +
        'Permission is hereby granted, free of charge, to any person obtaining a copy of <<match=this|the>> <<match=.*>> <<beginOptional>>software <<match=and/?o?r?>> associated documentation<<endOptional>> <<beginOptional>>SOFTWARE<<endOptional>> <<beginOptional>><<match=files?>> (the <<match="?Software"?|"?Materials"?>>),<<endOptional>> to deal in the <<match=Software|Code|Materials>> without restriction, including without <<match=limitation,?>> <<beginOptional>>on<<endOptional>> the <<beginOptional>>irrevocable, perpetual, worldwide, and royalty-free<<endOptional>> rights to use, copy, modify, merge, publish, distribute, <<beginOptional>>sublicense,<<endOptional>> <<beginOptional>>distribute with modifications,<<endOptional>> <<beginOptional>><<match=sub ?license,?>><<endOptional>> <<beginOptional>>display, perform, create derivative works from<<endOptional>> <<match=and ?/ ?or>> sell copies of the <<match=Software|code|Materials>>, <<beginOptional>> both in source<<endOptional>> and <<beginOptional>>object code form, and<<endOptional>> to permit persons to whom the <<match=Software|code|materials>> <<match=is|are>> furnished to do so, subject to the following <<match=conditions|disclaimer>>:\n' +
        '\n' +
        '<<beginOptional>>\n' +
        'The above copyright notice<<match= and|,>> this permission notice <<beginOptional>>and the disclaimer statement<<endOptional>> <<beginOptional>>(including the next\n' +
        'paragraph)<<endOptional>> <<match=shall|must>> be included in all copies or substantial portions of the <<match=Software|code|materials>>.\n' +
        '<<endOptional>>\n',
      filename: 'license_MIT.txt'
    },
    {
      source_text: '<<match=\\(?(?:the )?\\bMIT License\\b(?: license)?\\)?>>',
      filename: 'License Name'
    },
    {
      source_text: '<<match=(?:https?://)?(www\\.)?opensource\\.org/licenses/mit-license\\.php(?:\\/[a-z0-9._-]*)*\\/?>>',
      filename: 'url'
    },
    {
      source_text: '<<match=(?:https?://)?(www\\.)?opensource\\.org/licenses/MIT(?:\\/[a-z0-9._-]*)*\\/?>>',
      filename: 'url'
    }
  ],
  associated_patterns: [
    {
      text: '\n' +
        '\n' +
        '<<beginOptional>>The<<endOptional>> MIT <<match=License[: -]*>> <<beginOptional>>(MIT)<<endOptional>>\n',
      regex: / ?(?:the ?)?mit ?(?:(license[: -]*?) ?) ?(?:\(mit\) ?)?/,
      capture_groups: [Array],
      prechecks_required: [Array],
      filename: 'associated_full-title.txt'
    },
    {
      text: '\n' +
        '\n' +
        'THE <<match=SOFTWARE|CODE|MATERIALS>> <<match=IS|ARE>> PROVIDED <<match=["*]?AS IS["*]?,?>> WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE<<beginOptional>> AND <<match=NON-?INFRINGEMENT>><<endOptional>><<match=\\. ?>>IN NO EVENT SHALL <<match=.+>> BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, <<beginOptional>>ARISING FROM,<<endOptional>> OUT OF OR IN CONNECTION WITH THE <<match=SOFTWARE|CODE|MATERIALS>> OR THE USE OR OTHER DEALINGS IN THE <<match=SOFTWARE|CODE|MATERIALS>><<beginOptional>>.<<endOptional>>\n',
      regex: /the ?(?:(software|code|materials) ?) ?(?:(is|are) ?)provided ?(?:(['*]?as is['*]?,?) ?)without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose ?(?:and ?(?:(non-?infringement) ?) ?)? ?(?:(\. ?) ?)in no event shall ?(?:(.{1,144}) ?)be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, ?(?:arising from, ?)?out of or in connection with the ?(?:(software|code|materials) ?)or the use or other dealings in the ?(?:(software|code|materials) ?) ?(?:\. ?)?/,
      capture_groups: [Array],
      prechecks_required: false,
      filename: 'associated_liability_clause.txt'
    },
    {
      text: '\n\n<<match=(^|\\b)\\(?MIT\\)?>>\n',
      regex: / ?(?:((^|\b)\(?mit\)?) ?)/,
      capture_groups: [Array],
      prechecks_required: [Array],
      filename: 'associated_short-title.txt'
    }
  ],
  associated_pattern_sources: [
    {
      source_text: '\n' +
        '\n' +
        '<<beginOptional>>The<<endOptional>> MIT <<match=License[: -]*>> <<beginOptional>>(MIT)<<endOptional>>\n',
      filename: 'associated_full-title.txt'
    },
    {
      source_text: '\n' +
        '\n' +
        'THE <<match=SOFTWARE|CODE|MATERIALS>> <<match=IS|ARE>> PROVIDED <<match=["*]?AS IS["*]?,?>> WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE<<beginOptional>> AND <<match=NON-?INFRINGEMENT>><<endOptional>><<match=\\. ?>>IN NO EVENT SHALL <<match=.+>> BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, <<beginOptional>>ARISING FROM,<<endOptional>> OUT OF OR IN CONNECTION WITH THE <<match=SOFTWARE|CODE|MATERIALS>> OR THE USE OR OTHER DEALINGS IN THE <<match=SOFTWARE|CODE|MATERIALS>><<beginOptional>>.<<endOptional>>\n',
      filename: 'associated_liability_clause.txt'
    },
    {
      source_text: '\n\n<<match=(^|\\b)\\(?MIT\\)?>>\n',
      filename: 'associated_short-title.txt'
    }
  ]
}

Documentation

Index

Constants

View Source
const (
	LicenseInfoJSON    = "license_info.json"
	PreChecksPattern   = "prechecks_"
	PrimaryPattern     = "license_"
	AssociatedPattern  = "associated_"
	OptionalPattern    = "optional_"
	AcceptablePatterns = "acceptable_patterns"
)

Variables

View Source
var (
	Logger = log.NewLogger(log.INFO)

	RegexUnsafePattern = regexp.MustCompile(`([\\.*+?^${}()|[\]])`)
)

Functions

func AddLicense

func AddLicense(id string, ll *LicenseLibrary) error

func AddPrimaryPatternAndSource

func AddPrimaryPatternAndSource(fileContents string, filePath string, l *License) error

func GenerateMatchingPatternFromSourceText

func GenerateMatchingPatternFromSourceText(pp *PrimaryPatterns) (*regexp.Regexp, error)

GenerateMatchingPatternFromSourceText normalizes and compiles a pattern once with sync

func GenerateRegexFromNormalizedText

func GenerateRegexFromNormalizedText(normalizedText string) (*regexp.Regexp, error)

func List

func List(config *viper.Viper) (lics []Detail, deprecatedLics []Detail, exceptions []Exception, deprecatedExceptions []Exception, spdxVersion string, err error)

func ReadSPDXLicenseLists added in v0.10.0

func ReadSPDXLicenseLists(r *resources.Resources) (licenseList SPDXLicenceList, exceptionsList SPDXLicenceList, err error)

Types

type Detail

type Detail struct {
	ID            string
	Name          string
	Family        string
	NumTemplates  int
	IsOSIApproved bool
	IsFSFLibre    bool
}

type Exception

type Exception struct {
	ID           string
	Name         string
	Family       string
	NumTemplates int
}

type License

type License struct {
	// SPDX License ID if applicable, for example, "Apache-2.0"
	SPDXLicenseID             string
	LicenseInfo               LicenseInfo
	PrimaryPatterns           []*PrimaryPatterns
	PrimaryPatternsSources    []PrimaryPatternsSources
	AssociatedPatterns        []*PrimaryPatterns
	AssociatedPatternsSources []PrimaryPatternsSources
	// Aliases (and names and IDs) can be used like primary patterns (unless disabled), but are simple strings not regex. They also require word boundaries.
	Aliases []string
	// URLs can be used like primary patterns (unless disabled), but are simple strings not regex with URL matching.
	URLs []string
	// license text or an expression
	Text LicenseText
}

License holds the specification of each license

func (License) GetID

func (l License) GetID() string

type LicenseInfo

type LicenseInfo struct {
	Name             string         `json:"name"`
	Family           string         `json:"family"`
	SPDXStandard     bool           `json:"spdx_standard"`
	SPDXException    bool           `json:"spdx_exception"`
	OSIApproved      bool           `json:"osi_approved"`
	IgnoreIDMatch    bool           `json:"ignore_id_match"`
	IgnoreNameMatch  bool           `json:"ignore_name_match"`
	Aliases          SliceOfStrings `json:"aliases"`
	URLs             SliceOfStrings `json:"urls"`
	EligibleLicenses SliceOfStrings `json:"eligible_licenses"`
	IsMutator        bool           `json:"is_mutator"`
	IsDeprecated     bool           `json:"is_deprecated"`
	IsFSFLibre       bool           `json:"is_fsf_libre"`
}

func ReadLicenseInfoJSON added in v0.10.0

func ReadLicenseInfoJSON(fileContents []byte) (*LicenseInfo, error)

ReadLicenseInfoJSON unmarshalls the json bytes into LicenseInfo

type LicenseLibrary

type LicenseLibrary struct {
	SPDXVersion               string
	LicenseMap                LicenseMap
	PrimaryPatternPreCheckMap PrimaryPatternPreCheckMap
	AcceptablePatternsMap     PatternsMap
	Config                    *viper.Viper
	Resources                 *resources.Resources
}

func NewLicenseLibrary

func NewLicenseLibrary(config *viper.Viper) (*LicenseLibrary, error)

func (*LicenseLibrary) AddAll

func (ll *LicenseLibrary) AddAll() error

func (*LicenseLibrary) AddAllCustom added in v0.10.0

func (ll *LicenseLibrary) AddAllCustom() error

func (*LicenseLibrary) AddAllSPDX

func (ll *LicenseLibrary) AddAllSPDX() error

func (*LicenseLibrary) AddCustomLicenses added in v0.10.0

func (ll *LicenseLibrary) AddCustomLicenses() error

AddCustomLicenses initializes the license data set to scan the input license file against all the possible licenses available in the resources are read

type LicenseMap

type LicenseMap map[string]License

type LicensePatternKey

type LicensePatternKey struct {
	FilePath string // Each ID may have multiple license_*.txt primary patterns
}

type LicensePreChecks

type LicensePreChecks struct {
	StaticBlocks []string
}

type LicenseText

type LicenseText struct {
	// content type of the license, for example, "text/plain"
	ContentType string
	// any encoding if the license text is encoded in any particular format, for example, "base64"
	Encoding string
	// license text encoded in the format specified
	Content string
}

LicenseText contains the content type along with the content

type PatternsMap

type PatternsMap map[string]*regexp.Regexp

type PrimaryPatternPreCheckMap

type PrimaryPatternPreCheckMap map[LicensePatternKey]*LicensePreChecks

type PrimaryPatterns

type PrimaryPatterns struct {
	Text string

	CaptureGroups []*normalizer.CaptureGroup
	FileName      string
	// contains filtered or unexported fields
}

type PrimaryPatternsSources

type PrimaryPatternsSources struct {
	SourceText string
	Filename   string
}

type SPDXExceptionInfo

type SPDXExceptionInfo struct {
	Name                  string `json:"name"`
	LicenseExceptionID    string `json:"licenseExceptionId"`
	IsDeprecatedLicenseID bool   `json:"isDeprecatedLicenseId"`
}

type SPDXLicenceInfo

type SPDXLicenceInfo struct {
	Name                  string `json:"name"`
	LicenseID             string `json:"licenseId"`
	IsOSIApproved         bool   `json:"isOsiApproved"`
	IsFSFLibre            bool   `json:"isFsfLibre"`
	IsDeprecatedLicenseID bool   `json:"isDeprecatedLicenseId"`
}

type SPDXLicenceList

type SPDXLicenceList struct {
	LicenseListVersion string              `json:"licenseListVersion"`
	Licenses           []SPDXLicenceInfo   `json:"licenses"`
	Exceptions         []SPDXExceptionInfo `json:"exceptions"`
}

func ReadSPDXLicenseListJSON

func ReadSPDXLicenseListJSON(fileContents []byte) (*SPDXLicenceList, error)

ReadSPDXLicenseListJSON unmarshalls the json bytes into SPDXLicenseList

type SliceOfStrings

type SliceOfStrings []string

SliceOfStrings gives us []string with special UnmarshalJSON

func (*SliceOfStrings) UnmarshalJSON

func (stringArray *SliceOfStrings) UnmarshalJSON(b []byte) error

UnmarshalJSON reads string or array of strings into []string when json.Unmarshal encounters a SliceOfStrings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL