2019-12-09 18:57:22 +00:00
|
|
|
import sys
|
|
|
|
|
2019-12-03 20:27:13 +00:00
|
|
|
class ServiceBase :
|
2020-05-26 18:26:01 +00:00
|
|
|
_config = {}
|
2019-12-09 18:57:22 +00:00
|
|
|
error = []
|
|
|
|
warn = []
|
2019-12-03 20:27:13 +00:00
|
|
|
_status = "Ready"
|
2020-05-22 02:34:56 +00:00
|
|
|
def __init__(self,hints={},config={}):
|
2020-05-26 18:26:01 +00:00
|
|
|
self._config = config
|
|
|
|
self._error = []
|
|
|
|
self._warn = []
|
2020-05-22 02:34:56 +00:00
|
|
|
self.hints = hints
|
|
|
|
pass
|
2019-12-03 20:27:13 +00:00
|
|
|
|
2020-05-22 02:34:56 +00:00
|
|
|
def _set_config(self,config) :
|
|
|
|
"""Allows for post-initialization configuration"""
|
2020-05-26 18:26:01 +00:00
|
|
|
self._config = config
|
2020-05-22 02:34:56 +00:00
|
|
|
|
|
|
|
def _set_hints(self,hints) :
|
|
|
|
"""Allows for post-initialization configuration of hint data"""
|
|
|
|
self.hints = hints
|
|
|
|
|
|
|
|
def _cache_invalid(self) :
|
|
|
|
"""Returns a boolean representing whether or not a cached value from the last lookup should be invalidated."""
|
|
|
|
return False
|
2019-12-03 20:27:13 +00:00
|
|
|
|
2019-12-11 18:48:31 +00:00
|
|
|
def debug(self,message,verbosity_level) :
|
2020-05-22 02:34:56 +00:00
|
|
|
"""Prints the submitted message if the environment's verbosity level matches or is surpassed by the submitted level."""
|
2020-05-26 18:26:01 +00:00
|
|
|
if self._config['_namespace']['debug'] and self._config['_namespace']['debug'] >= verbosity_level :
|
2019-12-09 18:57:22 +00:00
|
|
|
print(message,file=sys.stderr)
|
|
|
|
|
2019-12-04 20:00:55 +00:00
|
|
|
@classmethod
|
|
|
|
def get_arguments(cls) :
|
2019-12-03 20:27:13 +00:00
|
|
|
"""Returns an array of information used to construct an argumentparser argument."""
|
|
|
|
# [ <short flag>,<unix flag>,<arg type>,<description> ]
|
2020-05-22 18:28:13 +00:00
|
|
|
# Example return: [ '-n', '--net', 'store_true', 'Output network information about the subject' ]
|
2019-12-03 20:27:13 +00:00
|
|
|
return None
|
|
|
|
|
2019-12-04 20:00:55 +00:00
|
|
|
def startup(self) :
|
|
|
|
"""Perform any setup that is needed to perform lookups, such as logging in or obtaining auth sessions."""
|
|
|
|
pass
|
|
|
|
|
2020-05-22 02:34:56 +00:00
|
|
|
def lookup(self,subject) :
|
|
|
|
"""Returns a dictionary with lookup information about the given subject."""
|
2019-12-04 20:00:55 +00:00
|
|
|
# Note: You should only return arrays and dictionaries with strings as keys so the information
|
|
|
|
# serializes correctly.
|
|
|
|
|
2019-12-03 20:27:13 +00:00
|
|
|
return None
|
|
|
|
|
2019-12-04 20:00:55 +00:00
|
|
|
def shutdown(self) :
|
|
|
|
"""Perform any cleanup that is needed, such as logging out of auth sessions."""
|
|
|
|
pass
|
2020-05-22 02:34:56 +00:00
|
|
|
|
|
|
|
def reset(self) :
|
|
|
|
"""Reinitialize the plugin, performing any involved operations."""
|
|
|
|
self.shutdown()
|
|
|
|
self.startup()
|