Fossology¶
The initialization class, used to create a session with the FOSSology server and get user relevant information.
-
class
fossology.
Fossology
(url, token, name)¶ Main Fossology API class
Authentication against a running Fossology instance is performed using an API token.
- Example
>>> from fossology import Fossology >>> foss = Fossology(FOSS_URL, FOSS_TOKEN, username)
Note
The class instantiation exits if the session with the Fossology server can’t be established
- Parameters
url (str) – URL of the Fossology instance
token (str) – The API token generated using the Fossology UI
name (str) – The name of the token owner
- Raises
AuthenticationError – if the user couldn’t be found
-
delete_user
(user)¶ Delete a Fossology user.
API Endpoint: DELETE /users/{id}
- Parameters
user (User) – the user to be deleted
- Raises
FossologyApiError – if the REST call failed
-
detail_user
(user_id)¶ Get details of Fossology user.
API Endpoint: GET /users/{id}
- Parameters
id (int) – the ID of the user
- Returns
the requested user’s details
- Return type
- Raises
FossologyApiError – if the REST call failed
-
filesearch
(filelist: List = [], group: Optional[str] = None)¶ Search for files from hash sum
API Endpoint: POST /filesearch
The response does not generate Python objects yet, the plain JSON data is simply returned.
- Parameters
filelist (list) – the list of files (or containers) hashes to search for (default: [])
group (string) – the group name to choose while performing search (default: None)
- Returns
list of items corresponding to the search criteria
- Return type
JSON
- Raises
FossologyApiError – if the REST call failed
AuthorizationError – if the user can’t access the group
-
get_version
()¶ Get API version from the server
API endpoint: GET /version
- Returns
the API version string
- Return type
string
- Raises
FossologyApiError – if the REST call failed
-
list_users
()¶ List all users from the Fossology instance
API Endpoint: GET /users
- Returns
the list of users
- Return type
list of User
- Raises
FossologyApiError – if the REST call failed
-
search
(searchType: fossology.obj.SearchTypes = <SearchTypes.ALLFILES: 'allfiles'>, upload: Optional[fossology.obj.Upload] = None, filename: Optional[str] = None, tag: Optional[str] = None, filesizemin: Optional[int] = None, filesizemax: Optional[int] = None, license: Optional[str] = None, copyright: Optional[str] = None, group: Optional[str] = None)¶ Search for a specific file
API Endpoint: GET /search
- Parameters
searchType (one of SearchTypes Enum) – Limit search to: directory, allfiles (default), containers
upload (Upload) – Limit search to a specific upload
filename (string) – Filename to find, can contain % as wild-card
tag (string) – tag to find
filesizemin (int) – Min filesize in bytes
filesizemax (int) – Max filesize in bytes
license (string) – License search filter
copyright (string) – Copyright search filter
group (string) – the group name to choose while performing search (default: None)
- Returns
list of items corresponding to the search criteria
- Return type
JSON
- Raises
FossologyApiError – if the REST call failed
AuthorizationError – if the user can’t access the group
-
fossology.
fossology_token
(url, username, password, token_name, token_scope=<TokenScope.READ: 'read'>, token_expire=None)¶ Generate an API token using username/password
API endpoint: POST /tokens
- Example
>>> from fossology import fossology_token >>> from fossology.obj import TokenScope >>> token = fossology_token("https://fossology.example.com", "Me", "MyPassword", "MyToken")
- Parameters
url (string) – the URL of the Fossology server
username (string) – name of the user the token will be generated for
password (string) – the password of the user
name (string) – the name of the token
scope (TokenScope (default: TokenScope.READ)) – the scope of the token (default: READ)
expire (string, e.g. 2019-12-25) – the expire date of the token (default: max. 30 days)
- Returns
the new token
- Return type
string
- Raises
AuthenticationError – if the username or password is incorrect
FossologyApiError – if another error occurs