Documentation ¶
Overview ¶
Package fossa provides a high-level interface to the FOSSA API (by default, located at https://app.fossa.com).
Index ¶
- Constants
- Variables
- func CreateTarball(dir string) (*os.File, []byte, error)
- func CreateTarballFromFiles(files []string, name string) (*os.File, []byte, error)
- func Get(endpoint string) (res string, statusCode int, err error)
- func GetJSON(endpoint string, v interface{}) (statusCode int, err error)
- func GetOrganizationID() (string, error)
- func NormalizeGitURL(project string) string
- func NormalizeGitURLTest(project string) string
- func Post(endpoint string, body []byte) (res string, statusCode int, err error)
- func SetAPIKey(key string)
- func SetEndpoint(endpoint string) error
- func SourceUnitType(t pkg.Type) (string, error)
- type Build
- type Component
- type ComponentSpec
- type Issue
- type Issues
- type License
- type Locator
- func LocatorOf(id pkg.ID) Locator
- func ReadLocator(locator string) Locator
- func Upload(title string, locator Locator, options UploadOptions, data []SourceUnit) (Locator, error)
- func UploadTarball(dir string, dependency bool, upload bool) (Locator, error)
- func UploadTarballDependency(dir string, upload bool) (Locator, error)
- func UploadTarballDependencyFiles(dir string, fileList []string, name string, upload bool) (Locator, error)
- func UploadTarballProject(dir string) (Locator, error)
- type Organization
- type Project
- type Revision
- type RevisionMeta
- type SignedURL
- type SourceUnit
- type SourceUnitBuild
- type SourceUnitDependency
- type UploadOptions
Constants ¶
const BuildsAPI = "/api/cli/%s/latest_build"
const IssuesAPI = "/api/cli/%s/issues"
const OrganizationAPI = "/api/cli/organization"
const RevisionsAPI = "/api/revisions/%s"
RevisionsAPI is the API endpoint for revisions.
const RevisionsDependenciesAPI = "/api/revisions/%s/dependencies"
RevisionsDependenciesAPI is the API endpoint to retrieve transitive dependencies of a revision.
Variables ¶
var ( SignedURLAPI = "/api/components/signed_url" ComponentsBuildAPI = "/api/components/build" )
var ( ErrNoProject = errors.New("no project provided for upload") ErrNoRevision = errors.New("no revision provided for upload") ErrNoBuildData = errors.New("no build data to upload") )
Errors related to preconditions.
var ( ErrForbidden = errors.New("authentication failed (is the API key correct?)") ErrRevisionDoesNotExist = errors.New("revision does not exist (are the project and revision correct and published in FOSSA?)") )
Errors resulting from a bad API response.
var (
MockOrgID string
)
Functions ¶
func CreateTarball ¶ added in v0.7.4
CreateTarball archives and compresses a directory's contents to a temporary file while simultaneously computing its MD5 hash. The caller is responsible for closing the file handle.
func CreateTarballFromFiles ¶ added in v0.7.18
CreateTarballFromFiles archives and compresses a list of files to a temporary file while simultaneously computing its MD5 hash. The caller is responsible for closing the file handle.
func GetJSON ¶ added in v0.7.0
GetJSON makes an authenticated JSON GET request to a FOSSA API endpoint.
func GetOrganizationID ¶ added in v0.7.0
func NormalizeGitURL ¶
NormalizeGitURL normalizes all forms of git remote URLs to a single standard form.
func NormalizeGitURLTest ¶ added in v0.7.9
NormalizeGitURL normalizes all forms of git remote URLs to a single standard form. This works around the backend only normalizing strings starting with http. HACK until the backend and cli are more in sync
func Post ¶
Post makes an authenticated POST request to a FOSSA API endpoint. TODO: maybe `body` should be an `io.Reader` instead.
func SetEndpoint ¶ added in v0.7.6
Types ¶
type Build ¶
A Build holds the FOSSA API response for the builds API.
func GetLatestBuild ¶ added in v0.7.7
GetLatestBuild loads the most recent build for a revision or returns an error if the revision does not exist, or the revision has no builds.
type ComponentSpec ¶ added in v0.7.5
type ComponentSpec struct {
Archives []Component `json:"archives"`
}
type Issues ¶ added in v0.7.7
A wrapped list of issues returned by the FOSSA CLI issues endpoint If a push-only API key is used, then only the count is returned
type License ¶ added in v0.7.0
type License struct { ID int64 LicenseID string RevisionID string LicenseGroupID int64 Ignored bool Title string URL string FullText string Copyright string }
A License holds the FOSSA API response for the license API.
type Locator ¶
type Locator struct { Fetcher string `json:"fetcher"` Project string `json:"package"` Revision string `json:"revision"` }
Locator serializes FOSSA API locators.
func ReadLocator ¶
ReadLocator parses a string locator into a Locator.
func Upload ¶
func Upload(title string, locator Locator, options UploadOptions, data []SourceUnit) (Locator, error)
Upload uploads a project's analysis.
func UploadTarball ¶ added in v0.7.4
func UploadTarballDependency ¶ added in v0.7.18
UploadTarball archives, compresses, and uploads a specified directory. It uses the directory name as the project name and the MD5 of the uploaded tarball as the revision name. It returns the locator of the uploaded tarball.
In order to upload the tarball, we need the revision name. In order to get the revision name, we need to compute the tarball's MD5 hash. In order to compute the MD5 hash, we need to see every byte of the final tarball.
To do this, we actually stream through the tarball _twice_: once to create the compressed tarball (and writing it to disk) while simultaneously calculating its hash, and again to perform the upload.
The alternative is to hold the entire tarball in memory while we upload. Since this will be running within CI machines, this is probably not a good idea. (See https://circleci.com/docs/2.0/configuration-reference/#resource_class for an example of our memory constraints.)
func UploadTarballDependencyFiles ¶ added in v0.7.18
func UploadTarballDependencyFiles(dir string, fileList []string, name string, upload bool) (Locator, error)
UploadTarballDependencyFiles generates and uploads a tarball from the provided list of files to FOSSA. The tarball's contents are marked as a component (as opposed to a project).
func UploadTarballProject ¶ added in v0.7.18
func (Locator) IsResolved ¶
IsResolved returns true only if a locator is resolved.
func (Locator) OrgString ¶ added in v0.7.9
OrgString returns a locator converted to a string as a URL path for API access. The OrgID is included for custom fetchers.
type Organization ¶ added in v0.7.7
type Organization struct {
OrganizationID int
}
type Revision ¶ added in v0.7.0
type Revision struct { Locator *Locator `json:"loc"` Licenses []License Project *Project Meta []RevisionMeta Issues []Issue }
A Revision holds the FOSSA API response for the revision API.
func GetRevision ¶ added in v0.7.0
GetRevision loads a single revision.
func GetRevisionDependencies ¶ added in v0.7.18
GetRevisionDependencies returns all transitive dependencies for a project revision.
func GetRevisions ¶ added in v0.7.0
GetRevisions loads many revisions in batched requests.
type RevisionMeta ¶ added in v0.7.0
type RevisionMeta struct {
LastScan string `json:"last_scan"`
}
A RevisionMeta holds metadata about a FOSSA API revision.
type SourceUnit ¶
type SourceUnit struct { Name string Type string Manifest string Build SourceUnitBuild }
SourceUnit is the basic module unit of the FOSSA API.
type SourceUnitBuild ¶ added in v0.7.0
type SourceUnitBuild struct { Artifact string Context interface{} Succeeded bool Error error `json:",omitempty"` Imports []string Dependencies []SourceUnitDependency }
A SourceUnitBuild contains the build information of a SourceUnit.
type SourceUnitDependency ¶ added in v0.7.0
type SourceUnitDependency struct { // Location Locator string `json:"locator"` Imports []string `json:"imports,omitempty"` // Metadata Data *json.RawMessage `json:"data,omitempty"` // Context Depth int `json:"depth,omitempty"` Parent string `json:"parent,omitempty"` UnresolvedLocators []string `json:"unresolved_locators,omitempty"` }
A SourceUnitDependency contains the dependency information of a SourceUnit.