lib

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UseColour specifies whether we use ANSI/HTML colours or not.
	UseColour = true

	// DefaultProfileName is the name given to the built-in "include all"
	// profile.
	DefaultProfileName = "default"
)

Variables

View Source
var Backends = []string{
	"licenseclassifier",
	"cran",
	"pom",
	"spdx",
	"askalono",
	"scancode",
	"bitbake",
	"regexp",
}

Backends are a list of the available backends. We will eventually replace this with a registration mechanism.

Functions

func ReturnOutputConsole added in v0.0.6

func ReturnOutputConsole(output *Output) (string, error)

ReturnOutputConsole returns a string of output, formatted for the console.

func ReturnOutputFile added in v0.0.7

func ReturnOutputFile(output *Output) (string, error)

ReturnOutputFile returns a string of output, formatted for a text file.

func SimpleProfiles added in v0.0.2

func SimpleProfiles(results interfaces.ResultSet, passes []string, warnings map[string]error, profile *ProfileData, summary bool, backendWeights map[interfaces.Backend]float64, style string) (string, error)

SimpleProfiles is a simple way to filter the results. This is the first filter function created and is mostly used for an initial POC. It is the more complicated successor to the SimpleResults function. Style can be `ansi`, `html`, or `text`.

func SimpleResults

func SimpleResults(results interfaces.ResultSet, backendWeights map[interfaces.Backend]float64) (string, error)

SimpleResults is a simple way to format the results. This is the first display function created and is mostly used for debugging and initial POC.

Types

type AnnotatedBackend

type AnnotatedBackend struct {
	Backend          interfaces.Backend
	Weight           float64
	ScaledConfidence float64
}

type Core

type Core struct {
	Debug bool
	Logf  func(format string, v ...interface{})

	// Backends represents the list of backends to run for this execution.
	// In particular, there's nothing stopping you from initializing the
	// same backend multiple times with different input parameters, as long
	// as it was designed to be thread-safe.
	Backends        []interfaces.Backend
	Iterators       []interfaces.Iterator // TODO: should this be passed into Run instead?
	ShutdownOnError bool
}

Core is the core runner logic that is used in Main to achieve the desired result that you want. It is implemented this way so that it can be reused from multiple different frontends including a CLI, LIB, API, WEBUI and BOTUI.

func (*Core) Init

func (obj *Core) Init(ctx context.Context) error

Init initializes and validates the core struct before use.

func (*Core) Run

func (obj *Core) Run(ctx context.Context) (interfaces.ResultSet, []string, map[string]error, error)

Run launches each iterator and passes in a scan function that runs over (loops over) each backend.

To run this in parallel, simplistically, it would mean that each backend would effectively perform its own iteration, and that each file will probably get loaded separately into memory from disk, which is inefficient. The advantage is that it's architecturally easier, and it allows us to easily drop-in any backend. If a backend can be made to supports more precise interfaces, then we can iterate over the entire filesystem once, and share that iteration with more than one backend. Ideally, we would initialize each backend and keep it running as a function that accepts a stream of work to process... There's also no reason that we can't even add the same backend in twice with different params passed to it, as long as each is thread-safe and doesn't incorrectly misuse global state.

type Main added in v0.0.4

type Main struct {
	Program string
	Version string
	Debug   bool
	Logf    func(format string, v ...interface{})

	// This is the argv of the function.
	Args []string

	// Backends gives us a list of backends we use. If the corresponding
	// bool value in the map is true, then the backend is enabled. It can be
	// false if we want to show that it exists but is not enabled. This is
	// useful for display purposes.
	Backends map[string]bool

	// Profiles is the list of profiles to use. Either the names from
	// ~/.config/yesiscan/profiles/<name>.json or full paths.
	Profiles []string

	// RegexpPath specifies a path the regular expressions to use.
	RegexpPath string
}

Main is the general entry point for running this software. Populate this struct with the inputs and then call the Run() method.

func (*Main) Run added in v0.0.4

func (obj *Main) Run(ctx context.Context) (*Output, error)

Run is the main method for the Main struct. We use a struct as a way to pass in a ton of different arguments in a cleaner way.

type Output added in v0.0.6

type Output struct {
	Program string
	Version string

	// TODO: we could build and return a UID here instead of doing it in
	// web and separately generating a time UID for --output-template.
	Args           []string
	Backends       map[string]bool
	Results        map[string]map[interfaces.Backend]*interfaces.Result
	Passes         []string
	Warnings       map[string]error
	Profiles       []string
	ProfilesData   map[string]*ProfileData
	BackendWeights map[interfaces.Backend]float64
}

Output combines all of the returned data from Run() into a consistent form.

type ProfileConfig added in v0.0.2

type ProfileConfig struct {

	// Licenses is the list of license SPDX ID's to match.
	Licenses []string `json:"licenses"`

	// Exclude these licenses from match instead of including by default.
	Exclude bool `json:"exclude"`

	// Comment adds a user friendly comment for this file.
	Comment string `json:"comment"`
}

ProfileConfig is the datastructure representing the profile config that is used for the .json files on disk.

type ProfileData added in v0.0.2

type ProfileData struct {

	// Licenses is the list of license SPDX ID's to match.
	Licenses []*licenses.License

	// Exclude these licenses from match instead of including by default.
	Exclude bool
}

ProfileData is the parsed version of ProfileConfig with real license structs.

type Scanner

type Scanner struct {
	Debug bool
	Logf  func(format string, v ...interface{})

	Backends []interfaces.Backend
	// contains filtered or unexported fields
}

Scanner is functionality that encapsulates the running of each backend. It builds and provides a generic scan mechanism that can be easily passed to the core logic for reuse. Concurrent running of each backend happens in here, and a caching layer for results is also available within.

func (*Scanner) Init

func (obj *Scanner) Init() error

Init initializes the scanner struct before use.

func (*Scanner) Passes added in v0.0.11

func (obj *Scanner) Passes() ([]string, error)

Passes contains a list of every file scanned that did not get listed in the full ResultSet that is returned by the Result method. That ResultSet will contain files that were skipped over due to a scanning error of some sort. Having an error that occurs during a scan is different from scanning and not being able to get any data from it. TODO: do we want to return a better type?

func (*Scanner) Result

func (obj *Scanner) Result() (interfaces.ResultSet, error)

Result returns the results after a Scan operation is run. It contains a Wait the blocks until all the Scan work has finished. To cancel and unblock this, cancel the context that was passed in to the Scan function. Do *not* call Result until the Recurse function finished or you will not necessarily get the correct results. For example, if all of the backends haven't started running, then you won't get the right value.

func (*Scanner) Scan

func (obj *Scanner) Scan(ctx context.Context, path safepath.Path, info *interfaces.Info) error

Scan runs the correct scanning function of each backend. This function will get called in parallel, by multiple different iterators. As a result, it must be thread-safe. This function is passed in to the iterators by Core.

type SortedBackends

type SortedBackends []*AnnotatedBackend

func (SortedBackends) Len

func (obj SortedBackends) Len() int

func (SortedBackends) Less

func (obj SortedBackends) Less(i, j int) bool

func (SortedBackends) Swap

func (obj SortedBackends) Swap(i, j int)

Jump to

Keyboard shortcuts

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