API

API connection

API connection

class CveXplore.api.connection.api_db.ApiDatabaseCollection(address, collname, api_path=None, proxies=None, protocol='https', user_agent='CveXplore')[source]

Bases: object

The ApiDatabaseCollection mimics the behaviour of the CveSearchCollection

__init__(address, collname, api_path=None, proxies=None, protocol='https', user_agent='CveXplore')[source]

Create a new ApiDatabaseCollection.

Parameters
  • address (tuple) – Tuple with host ip/name and port

  • collname (str) – Collection name

  • api_path (str) – The api_path parameter needs to be provided if the API runs on a non-root path. So if the API is reachable at: https://localhost/api, this parameter needs to be set to ‘api’. So it is needed to connect to api resources, defaults to ‘None’

  • proxies (dict) – If you need to use a proxy, you can configure individual requests with the proxies argument to any request method

  • protocol (str) – Protocol to use when connecting to api; defaults to ‘https’

  • user_agent (str) – User agent to use when connecting; defaults to CveXplore:<<version>>

__repr__()[source]

return a string representation of the obj ApiDatabaseCollection

find(filter=None)[source]

Query the api endpoint as you would do so with a pymongo Collection.

Returns

Reference to the CveSearchApi

Return type

CveSearchApi

find_one(filter=None)[source]

Query the api endpoint as you would do so with a pymongo Collection.

Returns

Data or None

Return type

object

class CveXplore.api.connection.api_db.ApiDatabaseSource(address, api_path=None, proxies=None, protocol='https', user_agent='CveXplore')[source]

Bases: object

The ApiDatabaseSource mimics the behaviour of the MongoDBConnection.

__init__(address, api_path=None, proxies=None, protocol='https', user_agent='CveXplore')[source]

Create new instance of the ApiDatabaseSource

Parameters
  • address (tuple) – Tuple with host ip/name and port

  • api_path (str) – The api_path parameter needs to be provided if the API runs on a non-root path. So if the API is reachable at: https://localhost/api, this parameter needs to be set to ‘api’. So it is needed to connect to api resources, defaults to ‘None’

  • proxies (dict) – If you need to use a proxy, you can configure individual requests with the proxies argument to any request method

  • protocol (str) – Protocol to use when connecting to api; defaults to ‘https’

  • user_agent (str) – User agent to use when connecting; defaults to CveXplore:<<version>>

__repr__()[source]

return a string representation of the obj ApiDatabaseSource

API helpers

Cve Search API

class CveXplore.api.helpers.cve_search_api.CveSearchApi(db_collection, filter=None, limit=None, skip=None, sort=None)[source]

Bases: GenericApi

The CveSearchApi handles the different arguments in order to perform a query to a specific Cve Search api endpoint. It mimics the pymongo cursor’s behaviour to provide an ambiguous way to talk to either an API or a mongodb.

__init__(db_collection, filter=None, limit=None, skip=None, sort=None)[source]

Create a new CveSearchApi object.

Parameters
  • db_collection (ApiDatabaseCollection) – ApiDatabaseCollection object

  • filter (dict) – Filter to be used when querying data

  • limit (int) – Limit value

  • skip (int) – Skip value

  • sort (tuple) – Sort value

__iter__()[source]

Make this class an iterator

__next__()

Iterate to the results and return database objects

__repr__()[source]

return a string representation of the obj GenericApi

limit(value)[source]

Method to limit the amount of returned data

Parameters

value (int) – Limit

Returns

CveSearchApi object

Return type

CveSearchApi

next()[source]

Iterate to the results and return database objects

query()[source]

Endpoint for free query to cve search data

skip(value)[source]

Method to skip the given amount of records before returning the data

Parameters

value (int) – Skip

Returns

CveSearchApi object

Return type

CveSearchApi

sort(field, direction)[source]

Method to sort the returned data

Parameters
  • field (str) – Field to sort on

  • direction (int) – The direction to sort in; e.g. pymongo.DESCENDING

Returns

CveSearchApi object

Return type

CveSearchApi