Documentation ¶
Overview ¶
SHA1 is the currently accepted hash algorithm for SPDX documents, used for file integrity checks, NOT security. Instances of G401 and G505 can be safely ignored in this file.
Index ¶
- Constants
- Variables
- func HasKubernetesBoilerPlate(filePath string) (bool, error)
- type Catalog
- type CatalogOptions
- type ClassifyResult
- type DefaultDownloaderImpl
- type Downloader
- type DownloaderImplementation
- type DownloaderOptions
- type License
- type List
- type ListEntry
- type Reader
- func (r *Reader) LicenseFromFile(filePath string) (license *License, err error)
- func (r *Reader) LicenseFromLabel(label string) (license *License)
- func (r *Reader) ReadLicenses(path string) (licenseList []*ClassifyResult, unknownPaths []string, err error)
- func (r *Reader) ReadTopLicense(path string) (*ClassifyResult, error)
- func (r *Reader) SetImplementation(i ReaderImplementation) error
- type ReaderDefaultImpl
- func (d *ReaderDefaultImpl) Catalog() *Catalog
- func (d *ReaderDefaultImpl) Classifier() *licenseclassifier.Classifier
- func (d *ReaderDefaultImpl) ClassifyFile(path string) (licenseTag string, moreTags []string, err error)
- func (d *ReaderDefaultImpl) ClassifyLicenseFiles(paths []string) (licenseList []*ClassifyResult, unrecognizedPaths []string, err error)
- func (d *ReaderDefaultImpl) FindLicenseFiles(path string) ([]string, error)
- func (d *ReaderDefaultImpl) Initialize(opts *ReaderOptions) error
- func (d *ReaderDefaultImpl) LicenseFromFile(path string) (license *License, err error)
- func (d *ReaderDefaultImpl) LicenseFromLabel(label string) (license *License)
- type ReaderImplementation
- type ReaderOptions
Constants ¶
const ( LicenseDataURL = "https://spdx.org/licenses/" LicenseListFilename = "licenses.json" )
ListURL is the json list of all spdx licenses
Variables ¶
var DebianLicenseLabels = map[string]string{
"Apache-2.0": "Apache-2.0",
"Artistic": "Artistic-1.0-Perl",
"BSD": "BSD-1-Clause",
"CC0-1.0": "CC0-1.0",
"GFDL-1.2": "GFDL-1.2",
"GFDL-1.3": "GFDL-1.3",
"GPL": "GPL-1.0",
"GPL-1": "GPL-1.0",
"GPL-2": "GPL-2.0",
"GPL-3": "GPL-3.0",
"LGPL-2": "LGPL-2.0",
"LGPL-2.1": "LGPL-2.1",
"LGPL-3": "LGPL-3.0",
"MPL-1.1": "MPL-1.1",
"MPL-2.0": "MPL-2.0",
}
DebianLicenseLabels is a map to get the SPDX label from a debian label
var DefaultCatalogOpts = &CatalogOptions{}
DefaultCatalogOpts are the predetermined settings. License and cache directories are in the temporary OS directory and are created if the do not exist
var DefaultDownloaderOpts = &DownloaderOptions{ EnableCache: true, CacheDir: "", parallelDownloads: 5, }
DefaultDownloaderOpts set of options for the license downloader
var DefaultReaderOptions = &ReaderOptions{
ConfidenceThreshold: 0.9,
}
DefaultReaderOptions is the default set of options for the classifier
Functions ¶
func HasKubernetesBoilerPlate ¶ added in v0.9.0
HasKubernetesBoilerPlate checks if a file contains the Kubernetes License boilerplate
Types ¶
type Catalog ¶ added in v0.9.0
type Catalog struct { Downloader *Downloader // License Downloader List *List // List of licenses // contains filtered or unexported fields }
Catalog is an objec to interact with licenses and manifest creation
func NewCatalogWithOptions ¶ added in v0.9.0
func NewCatalogWithOptions(opts *CatalogOptions) (catalog *Catalog, err error)
NewCatalogWithOptions returns a SPDX object with the specified options
func (*Catalog) GetLicense ¶ added in v0.9.0
GetLicense returns a license struct from its SPDX ID label
func (*Catalog) LoadLicenses ¶ added in v0.9.0
LoadLicenses reads the license data from the downloader
func (*Catalog) Options ¶ added in v0.9.0
func (catalog *Catalog) Options() *CatalogOptions
Options returns a pointer to the catlog options
func (*Catalog) WriteLicensesAsText ¶ added in v0.9.0
WriteLicensesAsText writes the SPDX license collection to text files
type CatalogOptions ¶ added in v0.9.0
type CatalogOptions struct {
CacheDir string // Directrory to catch the license we download from SPDX.org
}
CatalogOptions are the spdx settings
type ClassifyResult ¶
ClassifyResult abstracts the data resulting from a file classification
type DefaultDownloaderImpl ¶
type DefaultDownloaderImpl struct {
Options *DownloaderOptions
}
DefaultDownloaderImpl is the default implementation that gets licenses
func (*DefaultDownloaderImpl) GetLicenses ¶
func (ddi *DefaultDownloaderImpl) GetLicenses() (licenses *List, err error)
GetLicenses downloads the main json file listing all SPDX supported licenses
func (*DefaultDownloaderImpl) SetOptions ¶
func (ddi *DefaultDownloaderImpl) SetOptions(opts *DownloaderOptions)
SetOptions sets the implementation options
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader handles downloading f license data
func NewDownloader ¶
func NewDownloader() (*Downloader, error)
NewDownloader returns a downloader with the default options
func NewDownloaderWithOptions ¶
func NewDownloaderWithOptions(opts *DownloaderOptions) (*Downloader, error)
NewDownloaderWithOptions returns a downloader with specific options
func (*Downloader) GetLicenses ¶
func (d *Downloader) GetLicenses() (*List, error)
GetLicenses is the mina function of the downloader. Returns a license list or an error if could get them
func (*Downloader) SetImplementation ¶
func (d *Downloader) SetImplementation(di DownloaderImplementation)
SetImplementation sets the implementation that will drive the downloader
type DownloaderImplementation ¶
type DownloaderImplementation interface { GetLicenses() (*List, error) SetOptions(*DownloaderOptions) }
DownloaderImplementation has only one method
type DownloaderOptions ¶
type DownloaderOptions struct { EnableCache bool // Should we use the cache or not CacheDir string // Directory where data will be cached, defaults to temporary dir // contains filtered or unexported fields }
DownloaderOptions is a set of options for the license downloader
func (*DownloaderOptions) Validate ¶
func (do *DownloaderOptions) Validate() error
Validate Checks the downloader options
type License ¶ added in v0.9.0
type License struct { IsDeprecatedLicenseID bool `json:"isDeprecatedLicenseId"` IsFsfLibre bool `json:"isFsfLibre"` IsOsiApproved bool `json:"isOsiApproved"` LicenseText string `json:"licenseText"` StandardLicenseHeaderTemplate string `json:"standardLicenseHeaderTemplate"` StandardLicenseTemplate string `json:"standardLicenseTemplate"` Name string `json:"name"` LicenseID string `json:"licenseId"` StandardLicenseHeader string `json:"standardLicenseHeader"` SeeAlso []string `json:"seeAlso"` }
SPDXLicense is a license described in JSON
func ParseLicense ¶ added in v0.9.0
ParseLicense parses a SPDX license from its JSON source
type List ¶ added in v0.9.0
type List struct { sync.RWMutex Version string `json:"licenseListVersion"` ReleaseDateString string `json:"releaseDate "` LicenseData []ListEntry `json:"licenses"` Licenses map[string]*License }
List abstracts the list of licenses published by SPDX.org
type ListEntry ¶ added in v0.9.0
type ListEntry struct { IsOsiApproved bool `json:"isOsiApproved"` IsDeprectaed bool `json:"isDeprecatedLicenseId"` Reference string `json:"reference"` DetailsURL string `json:"detailsUrl"` ReferenceNumber int `json:"referenceNumber"` Name string `json:"name"` LicenseID string `json:"licenseId"` SeeAlso []string `json:"seeAlso"` }
ListEntry a license entry in the list
type Reader ¶
type Reader struct { Options *ReaderOptions // contains filtered or unexported fields }
Reader is an object that finds and interprets license files
func NewReaderWithOptions ¶
func NewReaderWithOptions(opts *ReaderOptions) (r *Reader, err error)
NewReaderWithOptions returns a new license reader with the specified options
func (*Reader) LicenseFromFile ¶ added in v0.9.0
LicenseFromFile reads a file ans returns its license
func (*Reader) LicenseFromLabel ¶ added in v0.9.0
LicenseFromLabel returns a spdx license from its label
func (*Reader) ReadLicenses ¶
func (r *Reader) ReadLicenses(path string) ( licenseList []*ClassifyResult, unknownPaths []string, err error, )
ReadLicenses returns an array of all licenses found in the specified path
func (*Reader) ReadTopLicense ¶ added in v0.10.0
func (r *Reader) ReadTopLicense(path string) (*ClassifyResult, error)
ReadTopLicense returns the topmost license file in a directory
func (*Reader) SetImplementation ¶
func (r *Reader) SetImplementation(i ReaderImplementation) error
SetImplementation sets the implementation that the license reader will use
type ReaderDefaultImpl ¶
type ReaderDefaultImpl struct {
// contains filtered or unexported fields
}
ReaderDefaultImpl the default license reader imlementation, uses Google's cicense classifier
func (*ReaderDefaultImpl) Catalog ¶ added in v0.9.0
func (d *ReaderDefaultImpl) Catalog() *Catalog
SPDX returns the reader's SPDX object
func (*ReaderDefaultImpl) Classifier ¶
func (d *ReaderDefaultImpl) Classifier() *licenseclassifier.Classifier
Classifier returns the license classifier
func (*ReaderDefaultImpl) ClassifyFile ¶
func (d *ReaderDefaultImpl) ClassifyFile(path string) (licenseTag string, moreTags []string, err error)
ClassifyFile takes a file path and returns the most probable license tag
func (*ReaderDefaultImpl) ClassifyLicenseFiles ¶
func (d *ReaderDefaultImpl) ClassifyLicenseFiles(paths []string) ( licenseList []*ClassifyResult, unrecognizedPaths []string, err error)
ClassifyLicenseFiles takes a list of paths and tries to find return all licenses found in it
func (*ReaderDefaultImpl) FindLicenseFiles ¶
func (d *ReaderDefaultImpl) FindLicenseFiles(path string) ([]string, error)
FindLicenseFiles will scan a directory and return files that may be licenses
func (*ReaderDefaultImpl) Initialize ¶
func (d *ReaderDefaultImpl) Initialize(opts *ReaderOptions) error
Initialize checks the options and creates the needed objects
func (*ReaderDefaultImpl) LicenseFromFile ¶ added in v0.9.0
func (d *ReaderDefaultImpl) LicenseFromFile(path string) (license *License, err error)
LicenseFromFile a file path and returns its license
func (*ReaderDefaultImpl) LicenseFromLabel ¶ added in v0.9.0
func (d *ReaderDefaultImpl) LicenseFromLabel(label string) (license *License)
LicenseFromLabel return a spdx license from its label
type ReaderImplementation ¶
type ReaderImplementation interface { Initialize(*ReaderOptions) error ClassifyLicenseFiles([]string) ([]*ClassifyResult, []string, error) ClassifyFile(string) (string, []string, error) LicenseFromFile(string) (*License, error) LicenseFromLabel(string) *License FindLicenseFiles(string) ([]string, error) }
ReaderImplementation implements the basic lifecycle of a license reader: initializes -> finds license files to scan -> classifies them to a SPDX license
type ReaderOptions ¶
type ReaderOptions struct { ConfidenceThreshold float64 // Miniumum confidence to consider a license detected WorkDir string // Directory where the reader will store its data CacheDir string // Optional directory where the reader will store its downloads cache LicenseDir string // Optional dir to store and read the SPDX licenses from }
ReaderOptions are the optional settings for the license reader
func (*ReaderOptions) CachePath ¶
func (ro *ReaderOptions) CachePath() string
CachePath return the full path to the downloads cache
func (*ReaderOptions) LicensesPath ¶
func (ro *ReaderOptions) LicensesPath() string
LicensesPath return the full path the dir where the licenses are
func (*ReaderOptions) Validate ¶
func (ro *ReaderOptions) Validate() error
Validate checks the options to verify the are sane