diff --git a/modules/sfp_abuseipdb.py b/modules/sfp_abuseipdb.py index 8b07db3129..869fed7de6 100644 --- a/modules/sfp_abuseipdb.py +++ b/modules/sfp_abuseipdb.py @@ -142,6 +142,7 @@ def queryBlacklist(self): def parseBlacklist(self, blacklist): """Parse plaintext blacklist + Args: blacklist (str): plaintext blacklist from AbuseIPDB diff --git a/modules/sfp_hybrid_analysis.py b/modules/sfp_hybrid_analysis.py index 23bc4ce136..507f2dbd05 100644 --- a/modules/sfp_hybrid_analysis.py +++ b/modules/sfp_hybrid_analysis.py @@ -63,9 +63,6 @@ class sfp_hybrid_analysis(SpiderFootPlugin): errorState = False def setup(self, sfc, userOpts=dict()): - """ - Initialize module and module options - """ self.sf = sfc self.results = self.tempStorage() self.errorState = False @@ -74,21 +71,19 @@ def setup(self, sfc, userOpts=dict()): self.opts[opt] = userOpts[opt] def watchedEvents(self): - """ - What events is this module interested in for input - """ return ["IP_ADDRESS", "DOMAIN_NAME"] def producedEvents(self): - """ - What events this module produces - """ return ["RAW_RIR_DATA", "INTERNET_NAME", "DOMAIN_NAME", "LINKED_URL_INTERNAL"] def queryDomain(self, qry): - """ - Query domain - https://www.hybrid-analysis.com/docs/api/v2 + """Query a domain + + Args: + qry (str): domain + + Returns: + str: API response as JSON """ params = { @@ -111,9 +106,13 @@ def queryDomain(self, qry): return self.parseAPIResponse(res) def queryHost(self, qry): - """ - Query host - https://www.hybrid-analysis.com/docs/api/v2 + """Query a host + + Args: + qry (str): host + + Returns: + str: API response as JSON """ params = { @@ -136,9 +135,13 @@ def queryHost(self, qry): return self.parseAPIResponse(res) def queryHash(self, qry): - """ - Query hash - https://www.hybrid-analysis.com/docs/api/v2 + """Query a hash + + Args: + qry (str): hash + + Returns: + str: API response as JSON """ params = { @@ -161,8 +164,13 @@ def queryHash(self, qry): return self.parseAPIResponse(res) def parseAPIResponse(self, res): - """ - Parse API response + """Parse HTTP response from API + + Args: + res (dict): HTTP response from SpiderFoot.fetchUrl() + + Returns: + str: API response as JSON """ if res['code'] == '400': @@ -194,10 +202,6 @@ def parseAPIResponse(self, res): return data def handleEvent(self, event): - """ - Handle events sent to this module - """ - eventName = event.eventType srcModuleName = event.module eventData = event.data diff --git a/modules/sfp_recondev.py b/modules/sfp_recondev.py index fa97c66dd2..c5b4e242aa 100644 --- a/modules/sfp_recondev.py +++ b/modules/sfp_recondev.py @@ -66,7 +66,14 @@ def producedEvents(self): return ["RAW_RIR_DATA", "INTERNET_NAME"] def queryDomain(self, qry): - """https://recon.dev/api/docs""" + """Query a domain + + Args: + qry (str): domain + + Returns: + str: API response as JSON + """ headers = { "Accept": "application/json" diff --git a/setup.cfg b/setup.cfg index 6d83bcee82..62a328abe3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,14 @@ [flake8] flake8-max-line-length = 120 max-complexity = 100 -select = C,E,F,W,B,DUO -ignore = E501 W503 B006 DUO130 D +select = C,E,F,W,B,DUO,D +ignore = E501 W503 B006 DUO130 per-file-ignores = spiderfoot/__init__.py:F401 + sfcli.py:D + sflib.py:D + sfscan.py:D + sfwebui.py:D [darglint] docstring_style=google diff --git a/sf.py b/sf.py index 3d2fc40de9..c6308480a3 100755 --- a/sf.py +++ b/sf.py @@ -422,7 +422,12 @@ def start_scan(sfConfig, sfModules, args): def start_web_server(sfWebUiConfig, sfConfig): - """Start the web server so you can start looking at results""" + """Start the web server so you can start looking at results + + Args: + sfWebUiConfig (dict): web server options + sfConfig (dict): SpiderFoot config options + """ web_host = sfWebUiConfig.get('host', '127.0.0.1') web_port = sfWebUiConfig.get('port', 5001) @@ -531,7 +536,12 @@ def start_web_server(sfWebUiConfig, sfConfig): def handle_abort(signal, frame): - """Handle interrupt and abort scan.""" + """Handle interrupt and abort scan. + + Args: + signal: TBD + frame: TBD + """ global dbh global scanId diff --git a/sfscan.py b/sfscan.py index edb746162c..651db6ca32 100644 --- a/sfscan.py +++ b/sfscan.py @@ -188,12 +188,10 @@ def __init__(self, scanName, scanId, targetValue, targetType, moduleList, global @property def scanId(self): - """Unique identifier for this scan""" return self.__scanId @property def status(self): - """Status of this scan""" return self.__status def __setStatus(self, status, started=None, ended=None): @@ -204,9 +202,6 @@ def __setStatus(self, status, started=None, ended=None): started (float): timestamp at start of scan ended (float): timestamp at end of scan - Returns: - None - Raises: TypeError: arg type was invalid ValueError: arg value was invalid diff --git a/spiderfoot/db.py b/spiderfoot/db.py index 92cbd4e9b3..ac0df557cf 100644 --- a/spiderfoot/db.py +++ b/spiderfoot/db.py @@ -252,9 +252,6 @@ def __init__(self, opts, init=False): init (bool): initialise the database schema. if the database file does not exist this option will be ignored. - Returns: - None: success - Raises: TypeError: arg type was invalid ValueError: arg value was invalid @@ -329,9 +326,6 @@ def __dbregex__(qry, data): def create(self): """Create the database schema. - Returns: - None: success - Raises: IOError: database I/O failed """ @@ -348,11 +342,7 @@ def create(self): raise IOError(f"SQL error encountered when setting up database: {e.args[0]}") def close(self): - """Close the database handle - - Returns: - None: success - """ + """Close the database handle.""" with self.dbhLock: self.dbh.close() @@ -467,10 +457,8 @@ def scanLogEvent(self, instanceId, classification, message, component=None): message (str): TBD component (str): TBD - Returns: - None: success - Raises: + TypeError: arg type was invalid IOError: database I/O failed Todo: @@ -515,9 +503,6 @@ def scanInstanceCreate(self, instanceId, scanName, scanTarget): scanName(str): scan name scanTarget (str): scan target - Returns: - None: success - Raises: TypeError: arg type was invalid IOError: database I/O failed @@ -554,9 +539,6 @@ def scanInstanceSet(self, instanceId, started=None, ended=None, status=None): ended (str): scan end time status (str): scan status - Returns: - None: success - Raises: TypeError: arg type was invalid IOError: database I/O failed @@ -854,9 +836,6 @@ def scanInstanceDelete(self, instanceId): Args: instanceId (str): scan instance ID - Returns: - None: success - Raises: TypeError: arg type was invalid IOError: database I/O failed @@ -926,9 +905,6 @@ def configSet(self, optMap=dict()): Args: optMap (dict): config options - Returns: - None: success - Raises: TypeError: arg type was invalid ValueError: arg value was invalid @@ -993,9 +969,6 @@ def configClear(self): """Reset the config to default. Clears the config from the database and lets the hard-coded settings in the code take effect. - Returns: - None: success - Raises: IOError: database I/O failed """ @@ -1015,9 +988,6 @@ def scanConfigSet(self, id, optMap=dict()): id (int): scan instance ID optMap (dict): config options - Returns: - None: success - Raises: TypeError: arg type was invalid ValueError: arg value was invalid @@ -1095,9 +1065,6 @@ def scanEventStore(self, instanceId, sfEvent, truncateSize=0): sfEvent (SpiderFootEvent): event to be stored in the database truncateSize (int): truncate size for event data - Returns: - None: success - Raises: TypeError: arg type was invalid ValueError: arg value was invalid @@ -1225,6 +1192,9 @@ def scanInstanceList(self): def scanResultHistory(self, instanceId): """History of data from the scan. + Args: + instanceId (str): scan instance ID + Returns: list: scan data history @@ -1361,7 +1331,7 @@ def scanElementSourcesAll(self, instanceId, childData): Raises: TypeError: arg type was invalid - IOError: database I/O failed + ValueError: arg value was invalid """ if not isinstance(instanceId, str): @@ -1432,7 +1402,6 @@ def scanElementChildrenAll(self, instanceId, parentIds): Raises: TypeError: arg type was invalid - IOError: database I/O failed Note: This function is not the same as the scanElementParent* functions. This function returns only ids. diff --git a/spiderfoot/event.py b/spiderfoot/event.py index b6335c5707..ba6c00b914 100644 --- a/spiderfoot/event.py +++ b/spiderfoot/event.py @@ -46,10 +46,6 @@ def __init__(self, eventType, data, module, sourceEvent, confidence=100, visibil confidence (int): how sure are we of this data's validity, 0-100 visibility (int): how 'visible' was this data, 0-100 risk (int): how much risk does this data represent, 0-100 - - Raises: - TypeError: arg type was invalid - ValueError: arg value was invalid """ self._generated = time.time() @@ -116,12 +112,10 @@ def sourceEventHash(self): @property def actualSource(self): - """actual source""" return self._actualSource @property def moduleDataSource(self): - """module data source""" return self._moduleDataSource @property @@ -216,6 +210,9 @@ def risk(self, risk): @module.setter def module(self, module): """ + Args: + module (str): module + Raises: TypeError: module type was invalid ValueError: module value was invalid @@ -232,7 +229,11 @@ def module(self, module): @data.setter def data(self, data): - """ + """Event data + + Args: + data (str): data + Raises: TypeError: data type was invalid ValueError: data value was invalid @@ -248,7 +249,11 @@ def data(self, data): @sourceEvent.setter def sourceEvent(self, sourceEvent): - """ + """source event + + Args: + sourceEvent (SpiderFootEvent): source event + Raises: TypeError: sourceEvent type was invalid """ @@ -295,7 +300,13 @@ def asDict(self): return evtDict def getHash(self): - """Required for SpiderFoot HX compatibility of modules""" + """Event hash + + Note: required for SpiderFoot HX compatibility of modules. + + Returns: + str: event hash + """ return self.hash # end of SpiderFootEvent class diff --git a/spiderfoot/plugin.py b/spiderfoot/plugin.py index 1303375569..43acdc5a88 100644 --- a/spiderfoot/plugin.py +++ b/spiderfoot/plugin.py @@ -54,7 +54,11 @@ def __init__(self): def _updateSocket(self, socksProxy): """Hack to override module's use of socket, replacing it with - one that uses the supplied SOCKS server.""" + one that uses the supplied SOCKS server. + + Args: + socksProxy (str): SOCKS proxy + """ self.socksProxy = socksProxy def clearListeners(self): @@ -65,12 +69,22 @@ def clearListeners(self): self._stopScanning = False def setup(self, sf, userOpts={}): - """Will always be overriden by the implementer.""" + """Will always be overriden by the implementer. + + Args: + sf (SpiderFoot): SpiderFoot object + userOpts (dict): TBD + """ pass def enrichTarget(self, target): - """Rarely used, only in special cases where a module can find - aliases for a target.""" + """Find aliases for a target. + + Note: rarely used in special cases + + Args: + target (str): TBD + """ pass def setTarget(self, target): @@ -78,6 +92,9 @@ def setTarget(self, target): Args: target (SpiderFootTarget): target + + Raises: + TypeError: target argument was invalid type """ from spiderfoot import SpiderFootTarget @@ -99,7 +116,10 @@ def setScanId(self, scanId): """Set the scan ID. Args: - id (str): scan ID + scanId (str): scan instance ID + + Raises: + TypeError: scanId argument was invalid type """ if not isinstance(scanId, str): raise TypeError(f"scanId is {type(scanId)}; expected str") @@ -111,6 +131,9 @@ def getScanId(self): Returns: str: scan ID + + Raises: + TypeError: Module called getScanId() but no scanId is set. """ if not self.__scanId__: raise TypeError("Module called getScanId() but no scanId is set.") @@ -118,7 +141,14 @@ def getScanId(self): return self.__scanId__ def getTarget(self): - """Gets the current target this module is acting against.""" + """Gets the current target this module is acting against. + + Returns: + str: current target + + Raises: + TypeError: Module called getTarget() but no target is set. + """ if not self._currentTarget: raise TypeError("Module called getTarget() but no target is set.") @@ -160,6 +190,12 @@ def notifyListeners(self, sfEvent): Args: sfEvent (SpiderFootEvent): event + + Returns: + None + + Raises: + TypeError: sfEvent argument was invalid type """ from spiderfoot import SpiderFootEvent diff --git a/spiderfoot/target.py b/spiderfoot/target.py index 73a5b84dea..5af9d48dcb 100644 --- a/spiderfoot/target.py +++ b/spiderfoot/target.py @@ -24,11 +24,6 @@ def __init__(self, targetValue, typeName): Args: targetValue (str): target value typeName (str): target type - - Raises: - TypeError: targetValue type was invalid - ValueError: targetValue value was empty - ValueError: typeName value was an invalid target type """ self.targetType = typeName @@ -106,6 +101,9 @@ def setAlias(self, value, typeName): def _getEquivalents(self, typeName): """TBD + Args: + typeName (str): event type + Returns: list: target aliases """ diff --git a/test/unit/test_spiderfoot_module_loading.py b/test/unit/test_spiderfoot_module_loading.py index b2605ef425..577683ba53 100644 --- a/test/unit/test_spiderfoot_module_loading.py +++ b/test/unit/test_spiderfoot_module_loading.py @@ -33,9 +33,6 @@ class TestSpiderFootModuleLoading(unittest.TestCase): } def test_module_loading(self): - """ - Test module loading - """ sf = SpiderFoot(self.default_options) # Go through each module in the modules directory with a .py extension