2019-12-09 18:57:22 +00:00
|
|
|
import sys
|
|
|
|
|
2019-12-03 20:27:13 +00:00
|
|
|
class ServiceBase :
|
|
|
|
config = {}
|
|
|
|
namespace = {}
|
|
|
|
data = {}
|
2019-12-09 18:57:22 +00:00
|
|
|
error = []
|
|
|
|
warn = []
|
2019-12-03 20:27:13 +00:00
|
|
|
_status = "Ready"
|
|
|
|
_subjects = []
|
|
|
|
def __init__(self,config,namespace,subjects,dossiercopy):
|
|
|
|
if not config or config == {} :
|
|
|
|
self._status = "Error"
|
|
|
|
else :
|
|
|
|
self.config = config
|
|
|
|
self.data = dossiercopy
|
|
|
|
self.namespace = namespace
|
|
|
|
self._subjects = subjects
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _lookup_subjects(self) :
|
2019-12-04 20:00:55 +00:00
|
|
|
args = self.get_arguments()
|
|
|
|
if args :
|
|
|
|
args = args[1][2:]
|
|
|
|
if getattr(self.namespace,args) == False and getattr(self.namespace,'all') == False :
|
|
|
|
return None
|
2019-12-03 20:27:13 +00:00
|
|
|
finaldictionary = {}
|
2019-12-04 20:00:55 +00:00
|
|
|
self.startup()
|
2019-12-03 20:27:13 +00:00
|
|
|
for item in self._subjects :
|
|
|
|
finaldictionary.update({item:self.perform_lookup(item)})
|
2019-12-04 20:00:55 +00:00
|
|
|
self.shutdown()
|
2019-12-03 20:27:13 +00:00
|
|
|
return finaldictionary
|
|
|
|
|
2019-12-09 18:57:22 +00:00
|
|
|
def _debug(self,message,verbosity_level) :
|
|
|
|
if self.namespace.debug and self.namespace.debug >= verbosity_level :
|
|
|
|
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> ]
|
|
|
|
# Example return: [ '-n', '--net', 'store_true', "Output network information about the subject" ]
|
|
|
|
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
|
|
|
|
|
2019-12-03 20:27:13 +00:00
|
|
|
def perform_lookup(self,host_tuple) :
|
2019-12-04 20:00:55 +00:00
|
|
|
"""Returns a dictionary with lookup information about the given IP or Hostname."""
|
|
|
|
# host_tuple is a socket triple (hostname, aliaslist, ipaddrlist) where hostname is
|
2019-12-03 20:27:13 +00:00
|
|
|
# the primary host name responding to the given ip_address, aliaslist is a (possibly
|
|
|
|
# empty) tuple of alternative host names for the same address, and ipaddrlist is a tuple
|
|
|
|
# of IPv4/v6 addresses for the same interface on the same host (most likely containing
|
|
|
|
# only a single address).
|
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
|