spdxexp

package
v2.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 6 Imported by: 17

Documentation

Overview

Spdxexp package validates licenses and determines if a license expression is satisfied by a list of licenses. Validity of a license is determined by the SPDX license list.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractLicenses added in v2.2.0

func ExtractLicenses(expression string) ([]string, error)

ExtractLicenses extracts licenses from the given expression without duplicates. Returns an array of licenses or error if error occurs during processing.

func Satisfies

func Satisfies(testExpression string, allowedList []string) (bool, error)

Satisfies determines if the allowed list of licenses satisfies the test license expression. Returns true if allowed list satisfies test license expression; otherwise, false. Returns error if error occurs during processing.

Example (And)
fmt.Println(Satisfies("Apache-2.0 AND MIT", []string{"MIT", "Apache-2.0"}))
Output:

true <nil>
Example (AndNotFound)
fmt.Println(Satisfies("MIT AND Apache-2.0", []string{"MIT"}))
Output:

false <nil>
Example (ErrorUnknownLicense)
fmt.Println(Satisfies("GPL", []string{"GPL"}))
Output:

false unknown license 'GPL' at offset 0
Example (ExtraAllowedLicense)
fmt.Println(Satisfies("MIT AND Apache-2.0", []string{"MIT", "Apache-1.0", "Apache-2.0"}))
Output:

true <nil>
Example (Only)
fmt.Println(Satisfies("Apache-1.0", []string{"Apache-1.0-only"}))
Output:

true <nil>
Example (OnlyNotFound)
fmt.Println(Satisfies("Apache-2.0", []string{"Apache-1.0-only"}))
Output:

false <nil>
Example (Or)
fmt.Println(Satisfies("MIT OR Apache-2.0", []string{"MIT"}))
Output:

true <nil>
Example (OrLater)
fmt.Println(Satisfies("Apache-2.0", []string{"Apache-1.0-or-later"}))
Output:

true <nil>
Example (OrLaterNotFound)
fmt.Println(Satisfies("Apache-1.0", []string{"Apache-2.0-or-later"}))
Output:

false <nil>
Example (OrNotFound)
fmt.Println(Satisfies("MIT OR Apache-2.0", []string{"GPL-2.0"}))
Output:

false <nil>
Example (Plus)
fmt.Println(Satisfies("Apache-2.0", []string{"Apache-1.0+"}))
Output:

true <nil>
Example (PlusNotFound)
fmt.Println(Satisfies("Apache-1.0", []string{"Apache-2.0+"}))
Output:

false <nil>
Example (SingleLicense)
fmt.Println(Satisfies("MIT", []string{"MIT"}))
Output:

true <nil>

func ValidateLicenses

func ValidateLicenses(licenses []string) (bool, []string)

ValidateLicenses checks if given licenses are valid according to spdx. Returns true if all licenses are valid; otherwise, false. Returns all the invalid licenses contained in the `licenses` argument.

Example (AllBad)
fmt.Println(ValidateLicenses([]string{"MTI", "Apache--2.0", "GPL"}))
Output:

false [MTI Apache--2.0 GPL]
Example (AllGood)
fmt.Println(ValidateLicenses([]string{"MIT", "Apache-2.0", "GPL-2.0"}))
Output:

true []
Example (OneBad)
fmt.Println(ValidateLicenses([]string{"MIT", "Apache-2.0", "GPL"}))
Output:

false [GPL]

Types

This section is empty.

Directories

Path Synopsis
Spdxlicenses package provides functions to get licenses, deprecated licenses, and exceptions.
Spdxlicenses package provides functions to get licenses, deprecated licenses, and exceptions.

Jump to

Keyboard shortcuts

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