OSS Index Python Library documentation
OSS Index is a free catalogue of open source components and scanning tools to help developers identify vulnerabilities, understand risk, and keep their software safe.
This library provides an interface to OSS Index in Python.
This module is not designed for standalone use (i.e. it is not executable on it’s own). If you’re looking for a tool that can sacn your Python applications and utilise OSS Index data, why not check out these tools:
Installation
Install from pypi.org as you would any other Python module using your preferred package manager:
pip install ossindex-lib
Usage
ossindex-lib
is designed to be included into other Python projects, not used as a standalone application.
Library Configuration
There are two key configurations that are possible:
Caching of response from OSS Index
Authentication for OSS Index
Caching of OSS Index Responses
By default, caching is enabled and the cache will be stored in $HOME/.ossindex/
.
You can disable caching as follows:
ossi = OssIndex(enable_cache=False)
You can control the base directory where the cache directory .ossindex
is created by supplying a directory as follows:
ossi = OssIndex(cache_location='/my/other/directory')
In this last example, caching will be enabled and the cache will be stored in /my/other/directory/.ossindex
.
Authenticating to OSS Index
By default, this library will attempt authenticated calls to OSS Index if authentication credentials exist in
$HOME/.oss-index.config
.
.oss-index.config
is a YAML formatted file and the example below shows how a username and password can be added to
enable authenticated calls to OSS Index:
username: my-oss-index-username
password: my-oss-index-password
Support
If you run into issues utilising this library, please raise a GitHub Issue. When raising an issue please include as much detail as possible including:
Version of
ossindex-lib
you have installedInput(s)
Expected Output(s)
Actual Output(s)
Python Version Support
We endeavour to support all functionality for all current actively supported Python versions. However, some features may not be possible/present in older Python versions due to their lack of support - which are noted below.
Changelog
v1.1.1 (2022-09-12)
Fix
Relax depenency on PyYAML (``85e689b` <https://github.com/sonatype-nexus-community/ossindex-python/commit/85e689bdcb35df4b9e59b4ad1987242ccea94415>`_)
v1.1.0 (2022-07-12)
Feature
Support providing authentication directly over loading from configuration file (``1bda4a9` <https://github.com/sonatype-nexus-community/ossindex-python/commit/1bda4a94e00fca30cf7488f1cb1e1bfaadaf1676>`_)
Support providing authentication directly over loading from configuration file (``bcd86cb` <https://github.com/sonatype-nexus-community/ossindex-python/commit/bcd86cb70a6e889d5b34d9fdb2c58f77684f7b6d>`_)
v1.0.0 (2022-03-10)
Feature
Adopted PEP-561 #4 (``f4b8b01` <https://github.com/sonatype-nexus-community/ossindex-python/commit/f4b8b0172fabfb55362450487d9cddaeaed3dc92>`_)
Added support for authentication to OSS Index #1 (``aa26387` <https://github.com/sonatype-nexus-community/ossindex-python/commit/aa263872aeeb0ce3aa6c93de11107397f72cfb0b>`_)
Re-worked how we use TinyDB to attempt to resolve #2 (``d5564da` <https://github.com/sonatype-nexus-community/ossindex-python/commit/d5564da8aaa207806e4a04db94c247ceec5fec2b>`_)
Fix
Typo in
requirements.lowest.txt
(``696f770` <https://github.com/sonatype-nexus-community/ossindex-python/commit/696f770052486fcc194a686f06ca5b47ff1f1a23>`_)Potential fix for #2 (``46f705d` <https://github.com/sonatype-nexus-community/ossindex-python/commit/46f705d117de799443902c2cb312f03b61a1ab44>`_)
Bug in deserialisation from cache database resolved (``e3b9a9d` <https://github.com/sonatype-nexus-community/ossindex-python/commit/e3b9a9d74c541dead24aad90a0046fae078affca>`_)
Typing and imports (``31a7e37` <https://github.com/sonatype-nexus-community/ossindex-python/commit/31a7e37e334301896f8275fb3e4f90119c05185b>`_)
Breaking
v0.2.1 (2021-09-16)
Fix
Typo in README (``a260e91` <https://github.com/sonatype-nexus-community/ossindex-python/commit/a260e912227895d42b01a4775e36e7124fbc6f0b>`_)
v0.2.0 (2021-09-15)
Feature
Added accessor methods to Vulnerability class + helper method on OssIndexComponent to get the overriding maximum CVSS Score (``15870a1` <https://github.com/sonatype-nexus-community/ossindex-python/commit/15870a19c7e62efb7f1c10f8f785f9d272152fc9>`_)
Fix
Test corrected as was wrong (``669ec24` <https://github.com/sonatype-nexus-community/ossindex-python/commit/669ec2481e6bbf46337e10149086c2b1fbba10e3>`_)
Corrected typing for OSS Index URL (``813e593` <https://github.com/sonatype-nexus-community/ossindex-python/commit/813e593ef940cb27430590f80e2ad8628333fb2a>`_)
Removed garbage typo (``23e7425` <https://github.com/sonatype-nexus-community/ossindex-python/commit/23e7425fddf104b332865f4382a9e4d857e76c04>`_)
Correct logic for determining which Vulnerability has the highest CVS score (``37e5aed` <https://github.com/sonatype-nexus-community/ossindex-python/commit/37e5aed6424594f6efff136c7037d1e5db28ccd5>`_)
Added support for cwe being optional and added support for optional cve being present (``3efafa9` <https://github.com/sonatype-nexus-community/ossindex-python/commit/3efafa978a2c9af647b760b34e4900917372a8d9>`_)
Support for OSS Index not returning descriptions for components (``8244735` <https://github.com/sonatype-nexus-community/ossindex-python/commit/82447357188ee9c4f0a8c046b9d6a00ea556c7fc>`_)
v0.1.1 (2021-09-13)
Fix
Deployment GH action (``1d403b5` <https://github.com/sonatype-nexus-community/ossindex-python/commit/1d403b565cc61ac100e7b8fc53a9f18c55e3c793>`_)
doc: Updated documentation to reflect usage and todos. (``0078668` <https://github.com/sonatype-nexus-community/ossindex-python/commit/0078668a76f1911b349dccd0c21cbdcfb7dc5097>`_)
API Reference
This page contains auto-generated API reference documentation 1.
ossindex
Submodules
ossindex.exception
Module Contents
- exception ossindex.exception.OssIndexException[source]
Bases:
Exception
Base exception which all exceptions raised by this library extend.
- exception ossindex.exception.AccessDeniedException[source]
Bases:
OssIndexException
Raised if supplied credentials for Oss Index are invalid.
ossindex.model
Module Contents
Model class that represents a Vulnerability as received back from OSS Index. |
|
Model class that represents a Component Report as received back from OSS Index. |
- class ossindex.model.Vulnerability(*, id_: str, display_name: str, title: str, description: str, cvss_score: Optional[float] = None, cvss_vector: Optional[str] = None, cve: Optional[str] = None, cwe: Optional[str] = None, version_ranges: Optional[Iterable[str]] = None, reference: str, external_references: Optional[Iterable[str]] = None)[source]
Model class that represents a Vulnerability as received back from OSS Index.
- property cvss_score Optional[float] [source]
CVSS Score returned from OSS Index.
- Returns:
float if set else None
- property cvss_vector Optional[str] [source]
CVSS Vector returned from OSS Index
- Returns:
str if set else None
- property version_ranges Set[str] [source]
Range of versions which are impacted by this Vulnerability.
- Returns:
Set of str
- class ossindex.model.OssIndexComponent(*, coordinates: str, description: Optional[str] = None, reference: str, vulnerabilities: Optional[Iterable[Vulnerability]] = None)[source]
Model class that represents a Component Report as received back from OSS Index.
- property description Optional[str] [source]
Description of the Component from OSS Index.
- Returns:
str if set else None
- property vulnerabilities Set[Vulnerability] [source]
Known vulnerabilities that relate to this Component.
- Returns:
Set of Vulnerability
- get_package_url() packageurl.PackageURL [source]
Get a PURL representation of this components coordinates.
- Returns:
PackageURL
- get_max_cvss_score() float [source]
Get the maximum CVSS Score across all Vulnerabilities known for this Component.
- Returns:
float
- static _reduce_on_max_cvss_score(v: Vulnerability, current_max: float) float [source]
ossindex.ossindex
Module Contents
- class ossindex.ossindex.OssIndex(*, enable_cache: bool = True, cache_location: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None)[source]
-
- get_component_report(packages: List[packageurl.PackageURL]) List[ossindex.model.OssIndexComponent] [source]
- _chunk_packages_for_oss_index(packages: List[packageurl.PackageURL]) List[List[packageurl.PackageURL]] [source]
Splits up the list of packages into lists that are of a size consumable by OSS Index APIs.
- Parameters
packages – List[PackageURL]
- Returns
List[List[PackageURL]]
- _get_cached_results(packages: List[packageurl.PackageURL]) Tuple[List[packageurl.PackageURL], List[ossindex.model.OssIndexComponent]] [source]
- Takes a list of packages and returns two Lists:
Packages without cached results
Cached results for those packages where they exist
- Parameters
packages – List[PackageURL]
- Returns
(List[PackageURL], List[OssIndexComponent])
- _get_results(packages: List[packageurl.PackageURL]) List[ossindex.model.OssIndexComponent] [source]
- _make_oss_index_component_report_call(packages: List[packageurl.PackageURL]) List[ossindex.model.OssIndexComponent] [source]
- _upsert_cache_with_oss_index_responses(oss_components: List[ossindex.model.OssIndexComponent]) None [source]
ossindex.serializer
Module Contents
Extensible JSON <http://json.org> encoder for Python data structures. |
|
|
|
- class ossindex.serializer.OssIndexJsonEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Bases:
json.JSONEncoder
Extensible JSON <http://json.org> encoder for Python data structures.
Supports the following objects and types by default:
Python
JSON
dict
object
list, tuple
array
str
string
int, float
number
True
true
False
false
None
null
To extend this to recognize other objects, subclass and implement a
.default()
method with another method that returns a serializable object foro
if possible, otherwise it should call the superclass implementation (to raiseTypeError
).- default(o: Any) Any [source]
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
Package Contents
- 1
Created with sphinx-autoapi