ifxlookup/servicebase.py

60 lines
1.8 KiB
Python
Raw Normal View History

import sys
class ServiceBase :
config = {}
namespace = {}
data = {}
error = []
warn = []
_status = "Ready"
def __init__(self,hints={},config={}):
self.config = config
self.error = []
self.warn = []
self.hints = hints
pass
def _set_config(self,config) :
"""Allows for post-initialization configuration"""
self.config = config
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-11 18:48:31 +00:00
def debug(self,message,verbosity_level) :
"""Prints the submitted message if the environment's verbosity level matches or is surpassed by the submitted level."""
if self.config['_namespace']['debug'] and self.config['_namespace']['debug'] >= verbosity_level :
print(message,file=sys.stderr)
@classmethod
def get_arguments(cls) :
"""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' ]
return None
def startup(self) :
"""Perform any setup that is needed to perform lookups, such as logging in or obtaining auth sessions."""
pass
def lookup(self,subject) :
"""Returns a dictionary with lookup information about the given subject."""
# Note: You should only return arrays and dictionaries with strings as keys so the information
# serializes correctly.
return None
def shutdown(self) :
"""Perform any cleanup that is needed, such as logging out of auth sessions."""
pass
def reset(self) :
"""Reinitialize the plugin, performing any involved operations."""
self.shutdown()
self.startup()