def getresolvers(self):
     '''Return a list of the available resolver names'''
     if self.authType == 'app':
         self.auth = self.app + ":" + Personis_base.generate_app_signature(
             self.app, self.key)
     return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "getresolvers", {'modelname':self.modelname,\
              'authType':self.authType, 'auth':self.auth})
def MkModel(model=None,
            modelserver=None,
            user=None,
            password=None,
            description=None,
            debug=0,
            ca_certs_file="ca_certs/ca.pem"):
    if modelserver == None:
        raise ValueError, "modelserver is None"
    if ':' in modelserver:
        modelserver, modelport = modelserver.split(":")
    else:
        modelport = 2005  # default port for personis server
    modelname = model
    auth = user + ":" + password
    ok = False
    try:
        ok = jsoncall.do_call(modelserver, modelport, ca_certs_file, "mkmodel", {'modelname':modelname,\
               'descripion':description,\
               'authType':'user',\
               'auth':auth})
    except:
        if debug > 0:
            traceback.print_exc()
        raise ValueError, "cannot create model '%s', server '%s'" % (
            modelname, modelserver)
    if not ok:
        raise ValueError, "server '%s' cannot create model '%s'" % (
            modelserver, modelname)
示例#3
0
	def __init__(self, model=None, modelserver=None, user=None, password=None, debug=0):
		if modelserver == None:
			raise ValueError, "modelserver is None"
		if ':' in modelserver:
			self.modelserver, self.modelport = modelserver.split(":")
		else:
			self.modelserver = modelserver
			self.modelport = 2005 # default port for personis server
		self.modelname = model
		self.user = user
		self.password = password
		self.debug =debug
		ok = False
		try:
			if self.debug != 0:
				print "jsondocall:", self.modelserver, self.modelport, self.modelname, self.user, self.password
			ok = jsoncall.do_call(self.modelserver, self.modelport, "access", {'modelname':self.modelname,\
										'user':self.user,\
										'password':self.password})
			if self.debug != 0:
				print "---------------------- result returned", ok
		except:
			if debug >0:
				traceback.print_exc()
			raise ValueError, "cannot access model '%s', server '%s'" % (self.modelname, self.modelserver)
		if not ok:
			raise ValueError, "server '%s' cannot access model '%s'" % (self.modelserver, self.modelname)
示例#4
0
	def listapps(self):
		"""
			returns array of registered app names
		"""
		return jsoncall.do_call(self.modelserver, self.modelport, "listapps", {'modelname':self.modelname,\
										'user':self.user,\
										'password':self.password})
def AppRequestAuth(model=None,
                   modelserver=None,
                   app=None,
                   key=None,
                   description=None,
                   debug=0,
                   ca_certs_file="ca_certs/ca.pem"):
    if modelserver == None:
        raise ValueError, "modelserver is None"
    if ':' in modelserver:
        modelserver, modelport = modelserver.split(":")
    else:
        modelport = 2005  # default port for personis server
    modelname = model
    ok = False
    try:
        ok = jsoncall.do_call(modelserver, modelport, ca_certs_file, "apprequestauth", {'modelname':modelname,\
               'description':description,\
               'app':app,\
               'key':key})
    except:
        if debug > 0:
            traceback.print_exc()
        raise ValueError, "cannot request authorisation for app '%s', server '%s'" % (
            app, modelserver)
    if not ok:
        raise ValueError, "server '%s' cannot process authorisation request for app '%s'" % (
            modelserver, app)
 def delcontext(self, context=[]):
     if self.authType == 'app':
         self.auth = self.app + ":" + Personis_base.generate_app_signature(
             self.app, self.key)
     return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "delcontext", {'modelname':self.modelname,\
                  'authType':self.authType,\
                  'auth':self.auth,\
                  'context':context})
示例#7
0
 def listapps(self):
     """
             returns array of registered app names
     """
     return jsoncall.do_call("listapps", {'modelname':self.modelname,\
                                                                     'user':self.user,\
                                                                     'password':self.password},
                                                                     self.connection)
    def listapps(self):
        """
			returns array of registered app names
		"""
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "listapps", {'modelname':self.modelname,\
                 'authType':self.authType,\
                 'auth':self.auth})
示例#9
0
	def deleteapp(self, app=None):
                """
                        deletes an app
                """
 		if app == None:
			raise ValueError, "deleteapp: app is None"
		return jsoncall.do_call(self.modelserver, self.modelport, "deleteapp", {'modelname':self.modelname,\
                                                                                'user':self.user,\
                                                                                'password':self.password,\
                                                                                'app':app})
    def listrequests(self):
        """
			returns array of apps requesting authorisation
		"""
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "listrequests", {'modelname':self.modelname,\
                 'authType':self.authType,\
                 'auth':self.auth})
示例#11
0
	def getpermission(self, context=None, componentid=None, app=None):
                """
                        gets permissions for a context (if componentid is None) or
                                a component
                        returns a tuple (ask,tell)
                """
		return jsoncall.do_call(self.modelserver, self.modelport, "getpermission", {'modelname':self.modelname,\
                                                                                'user':self.user,\
                                                                                'password':self.password,\
                                                                                'context': context,\
                                                                                'componentid': componentid,\
                                                                                'app': app})
示例#12
0
        def setpermission(self, context=None, componentid=None, app=None, permissions={}):
                """
                        sets ask/tell permission for a context (if componentid is None) or
                                a component
                """
 		return jsoncall.do_call(self.modelserver, self.modelport, "setpermission", {'modelname':self.modelname,\
										'user':self.user,\
										'password':self.password,\
										'context': context,\
										'componentid': componentid,\
										'app': app,\
										'permissions': permissions})
示例#13
0
        def registerapp(self, app=None, desc="", password=None):
                """
                        registers a password for an app
                        app name is a string (needs checking TODO)
                        app passwords are stored at the top level .model db
                """
		return jsoncall.do_call(self.modelserver, self.modelport, "registerapp", {'modelname':self.modelname,\
                                                                                'user':self.user,\
										'password':self.password,\
										'app':app,\
										'description':desc,\
										'apppassword':password})
 def registerapp(self, app=None, desc="", fingerprint=None):
     """
                     registers an app as being authorised to access this user model
                     app name is a string (needs checking TODO)
                     app passwords are stored at the top level .model db
             """
     # Only users can register apps
     return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "registerapp", {'modelname':self.modelname,\
                  'authType':'user',\
                  'auth':self.auth,\
                  'app':app,\
                  'description':desc,\
                  'fingerprint':fingerprint})
 def deleteapp(self, app=None):
     """
                     deletes an app
             """
     if app == None:
         raise ValueError, "deleteapp: app is None"
     if self.authType == 'app':
         self.auth = self.app + ":" + Personis_base.generate_app_signature(
             self.app, self.key)
     return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "deleteapp", {'modelname':self.modelname,\
                  'authType':self.authType,\
                  'auth':self.auth,\
                  'app':app})
示例#16
0
	def list_subs(self,
		context=[],
		componentid=None):
		"""
	arguments:
		context is a list giving the path of context identifiers
		componentid designates the component with subscriptions attached
		"""
		return  jsoncall.do_call(self.modelserver, self.modelport, "list_subs", {'modelname':self.modelname,\
										'user':self.user,\
										'password':self.password,\
										'context':context,\
										'componentid':componentid})
示例#17
0
	def import_model(self,
		context=[],
		partial_model=None):
		"""
	arguments:
		context is the context to import into
		partial_model is a json encoded string containing the partial model
		"""
		return jsoncall.do_call(self.modelserver, self.modelport, "import_model", {'modelname':self.modelname,\
										'user':self.user,\
										'password':self.password,\
										'context':context,\
										'partial_model':partial_model})
示例#18
0
	def export_model(self,
		context=[],
		evidence_filter=None):
		"""
	arguments:
		context is the context to export
		evidence_filter determines what evidence to export, None means none.
		"""
		return jsoncall.do_call(self.modelserver, self.modelport, "export_model", {'modelname':self.modelname,\
										'user':self.user,\
										'password':self.password,\
										'context':context,\
										'evidence_filter':evidence_filter})
    def import_model(self, context=[], partial_model=None):
        """
	arguments:
		context is the context to import into
		partial_model is a json encoded string containing the partial model
		"""
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "import_model", {'modelname':self.modelname,\
                     'authType':self.authType,\
                     'auth':self.auth,\
                     'context':context,\
                     'partial_model':partial_model})
    def list_subs(self, context=[], componentid=None):
        """
	arguments:
		context is a list giving the path of context identifiers
		componentid designates the component with subscriptions attached
		"""
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return  jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file,  "list_subs", {'modelname':self.modelname,\
                     'authType':self.authType,\
                     'auth':self.auth,\
                     'context':context,\
                     'componentid':componentid})
示例#21
0
    def getcontext(self,
            context=[],
            getsize=False):
        """
Get context information
arguments:
        context - a list giving the path to the required context
        getsize - True if the size in bytes of the context subtree is required
        """
        return jsoncall.do_call("getcontext", {'modelname':self.modelname,\
                                                                        'user':self.user,\
                                                                        'password':self.password,\
                                                                        'context':context,\
                                                                        'getsize':getsize},
                                                                        self.connection)
    def getcontext(self, context=[], getsize=False):
        """
	Get context information
	arguments:
		context - a list giving the path to the required context
		getsize - True if the size in bytes of the context subtree is required
		"""
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "getcontext", {'modelname':self.modelname,\
                 'authType':self.authType,\
                 'auth':self.auth,\
                 'context':context,\
                 'getsize':getsize})
 def getpermission(self, context=None, componentid=None, app=None):
     """
                     gets permissions for a context (if componentid is None) or
                             a component
                     returns a tuple (ask,tell)
             """
     if self.authType == 'app':
         self.auth = self.app + ":" + Personis_base.generate_app_signature(
             self.app, self.key)
     return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "getpermission", {'modelname':self.modelname,\
                  'authType':self.authType,\
                  'auth':self.auth,\
                  'context': context,\
                  'componentid': componentid,\
                  'app': app})
示例#24
0
	def mkcontext(self, 
		context= [],
		contextobj=None):
		"""
	Make a new context in a given context
	arguments:
		context - a list giving the path to the required context 
		contextobj - a Context object
		"""
		if contextobj == None:
			raise ValueError, "mkcontext: contextobj is None"
		return jsoncall.do_call(self.modelserver, self.modelport, "mkcontext", {'modelname':self.modelname,\
										'user':self.user,\
                                                                                'password':self.password,\
                                                                                'context':context,\
                                                                                'contextobj':contextobj.__dict__})
示例#25
0
	def delcontext(self,
		context=[]):
                """
        Delete an existing context
        arguments:
                context - a list giving the path to the required context
        returns:
                None on success
                a string error message on error
                """
		if context == None:
			raise ValueError, "delcontext: context is None"
		return jsoncall.do_call(self.modelserver, self.modelport, "delcontext", {'modelname':self.modelname,\
										'user':self.user,\
                                                                                'password':self.password,\
                                                                                'context':context})
示例#26
0
	def delete_sub(self,
		context=[],
		componentid=None,
		subname=None):
		"""
	arguments:
		context is a list giving the path of context identifiers
		componentid designates the component subscribed to
		subname is the subscription name
		"""
		return  jsoncall.do_call(self.modelserver, self.modelport, "delete_sub", {'modelname':self.modelname,\
										'user':self.user,\
										'password':self.password,\
										'context':context,\
										'componentid':componentid,\
										'subname':subname})
    def delete_sub(self, context=[], componentid=None, subname=None):
        """
	arguments:
		context is a list giving the path of context identifiers
		componentid designates the component subscribed to
		subname is the subscription name
		"""
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return  jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file,  "delete_sub", {'modelname':self.modelname,\
                 'authType':self.authType,\
                 'auth':self.auth,\
                 'context':context,\
                 'componentid':componentid,\
                 'subname':subname})
    def mkcontext(self, context=[], contextobj=None):
        """
	Make a new context in a given context
	arguments:
		context - a list giving the path to the required context 
		contextobj - a Context object
		"""
        if contextobj == None:
            raise ValueError, "mkcontext: contextobj is None"
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "mkcontext", {'modelname':self.modelname,\
                     'authType':self.authType,\
                     'auth':self.auth,\
                     'context':context,\
                     'contextobj':contextobj.__dict__})
示例#29
0
	def set_goals(self,
		context=[],
		componentid=None,
		goals=None):
		"""
	arguments:
		context is a list giving the path of context identifiers
		componentid designates the component with subscriptions attached
		goals is a list of paths to components that are:
			goals for this componentid if it is not of type goal
			components that contribute to this componentid if it is of type goal
		"""
		return  jsoncall.do_call(self.modelserver, self.modelport, "set_goals", {'modelname':self.modelname,\
										'user':self.user,\
										'password':self.password,\
										'context':context,\
										'componentid':componentid,\
										'goals':goals})
示例#30
0
	def delview(self,
		context=[],
		viewid=None):
                """
        Delete an existing view in a given context
        arguments:
                context - a list giving the path to the required context
                viewid - the id for the view
        returns:
                None on success
                """
		if viewid == None:
			raise ValueError, "delview: viewid is None"
		return jsoncall.do_call(self.modelserver, self.modelport, "delview", {'modelname':self.modelname,\
										'user':self.user,\
                                                                                'password':self.password,\
                                                                                'context':context,\
                                                                                'viewid':viewid})
    def set_goals(self, context=[], componentid=None, goals=None):
        """
	arguments:
		context is a list giving the path of context identifiers
		componentid designates the component with subscriptions attached
		goals is a list of paths to components that are:
			goals for this componentid if it is not of type goal
			components that contribute to this componentid if it is of type goal
		"""
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return  jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "set_goals", {'modelname':self.modelname,\
                     'authType':self.authType,\
                     'auth':self.auth,\
                     'context':context,\
                     'componentid':componentid,\
                     'goals':goals})
    def ask(self, context=[], view=None, resolver=None, showcontexts=None):
        """
	arguments: (see Personis_base for details)
		context is a list giving the path of context identifiers
		view is either:
			an identifier of a view in the context specified
			a list of component identifiers or full path lists
			None indicating that the values of all components in
				the context be returned
		resolver specifies a resolver, default is the builtin resolver

	returns a list of component objects
		"""
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        reslist = jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "ask", {'modelname':self.modelname,\
                  'authType':self.authType,\
                  'auth':self.auth,\
                  'context':context,\
                  'view':view,\
                  'resolver':resolver,\
                  'showcontexts':showcontexts})
        complist = []
        if showcontexts:
            cobjlist, contexts, theviews, thesubs = reslist
            for c in cobjlist:
                comp = Personis_base.Component(**c)
                if c["evidencelist"]:
                    comp.evidencelist = [
                        Personis_base.Evidence(**e) for e in c["evidencelist"]
                    ]
                complist.append(comp)
            reslist = [complist, contexts, theviews, thesubs]
        else:
            for c in reslist:
                comp = Personis_base.Component(**c)
                if c["evidencelist"]:
                    comp.evidencelist = [
                        Personis_base.Evidence(**e) for e in c["evidencelist"]
                    ]
                complist.append(comp)
            reslist = complist
        return reslist
示例#33
0
	def mkview(self,
		context=[],
		viewobj=None):
                """
        Make a new view in a given context
        arguments:
                context - a list giving the path to the required context
                viewobj - a View object
        returns:
                None on success
                a string error message on error
                """
		if viewobj == None:
			raise ValueError, "mkview: viewobj is None"
		return jsoncall.do_call(self.modelserver, self.modelport, "mkview", {'modelname':self.modelname,\
										'user':self.user,\
                                                                                'password':self.password,\
                                                                                'context':context,\
                                                                                'viewobj':viewobj.__dict__})
 def setpermission(self,
                   context=None,
                   componentid=None,
                   app=None,
                   permissions={}):
     """
                     sets ask/tell permission for a context (if componentid is None) or
                             a component
             """
     if self.authType == 'app':
         self.auth = self.app + ":" + Personis_base.generate_app_signature(
             self.app, self.key)
     return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "setpermission", {'modelname':self.modelname,\
                 'authType':self.authType,\
                 'auth':self.auth,\
                 'context': context,\
                 'componentid': componentid,\
                 'app': app,\
                 'permissions': permissions})
 def delview(self, context=[], viewid=None):
     """
     Delete an existing view in a given context
     arguments:
             context - a list giving the path to the required context
             viewid - the id for the view
     returns:
             None on success
             """
     if viewid == None:
         raise ValueError, "delview: viewid is None"
     if self.authType == 'app':
         self.auth = self.app + ":" + Personis_base.generate_app_signature(
             self.app, self.key)
     return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "delview", {'modelname':self.modelname,\
                  'authType':self.authType,\
                  'auth':self.auth,\
                  'context':context,\
                  'viewid':viewid})
示例#36
0
    def ask(self,
            context=[],
            view=None,
            resolver=None,
            showcontexts=None):
        """
arguments: (see Personis_base for details)
        context is a list giving the path of context identifiers
        view is either:
                an identifier of a view in the context specified
                a list of component identifiers or full path lists
                None indicating that the values of all components in
                        the context be returned
        resolver specifies a resolver, default is the builtin resolver

returns a list of component objects
        """
        reslist = jsoncall.do_call("ask", {'modelname':self.modelname,\
                                                                        'user':self.user,\
                                                                        'password':self.password,\
                                                                        'context':context,\
                                                                        'view':view,\
                                                                        'resolver':resolver,\
                                                                        'showcontexts':showcontexts},
                                                                        self.connection)
        complist = []
        if showcontexts:
            cobjlist, contexts, theviews, thesubs = reslist
            for c in cobjlist:
                comp = Personis_base.Component(**c)
                if c["evidencelist"]:
                    comp.evidencelist = [Personis_base.Evidence(**e) for e in c["evidencelist"]]
                complist.append(comp)
            reslist = [complist, contexts, theviews, thesubs]
        else:
            for c in reslist:
                comp = Personis_base.Component(**c)
                if c["evidencelist"]:
                    comp.evidencelist = [Personis_base.Evidence(**e) for e in c["evidencelist"]]
                complist.append(comp)
            reslist = complist
        return reslist
示例#37
0
    def mkcomponent(self,
            context=[],
            componentobj=None):
        """
Make a new component in a given context
arguments:
        context - a list giving the path to the required context
        componentobj - a Component object
returns:
        None on success
        a string error message on error
        """
        if componentobj == None:
            raise ValueError, "mkcomponent: componentobj is None"
        return jsoncall.do_call("mkcomponent", {'modelname':self.modelname,\
                                                                        'user':self.user,\
                                                                        'password':self.password,\
                                                                        'context':context,\
                                                                        'componentobj':componentobj.__dict__},
                                                                        self.connection)
    def subscribe(self, context=[], view=None, subscription=None):
        """
	arguments:
		context is a list giving the path of context identifiers
		view is either:
			an identifier of a view in the context specified
			a list of component identifiers or full path lists
			None indicating that the values of all components in
				the context be returned
			subscription is a Subscription object
		"""
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return  jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "subscribe", {'modelname':self.modelname,\
                     'authType':self.authType,\
                     'auth':self.auth,\
                     'context':context,\
                     'view':view,\
                     'subscription':subscription})
示例#39
0
def MkModel( model=None, modelserver=None, user=None, password=None, description=None, debug=0):
    if modelserver == None:
        raise ValueError, "modelserver is None"
    if ':' in modelserver:
        modelserver, modelport = modelserver.split(":")
    else:
        modelport = 2005 # default port for personis server
    modelname = model
    ok = False
    try:
        ok = jsoncall.do_call(modelserver, modelport, "mkmodel", {'modelname':modelname,\
                                                                'descripion':description,\
                                                                'user':user,\
                                                                'password':password})
    except:
        if debug >0:
            traceback.print_exc()
        raise ValueError, "cannot create model '%s', server '%s'" % (modelname, modelserver)
    if not ok:
        raise ValueError, "server '%s' cannot create model '%s'" % (modelserver, modelname)
示例#40
0
	def subscribe(self,
		context=[],
		view=None,
		subscription=None):
		"""
	arguments:
		context is a list giving the path of context identifiers
		view is either:
			an identifier of a view in the context specified
			a list of component identifiers or full path lists
			None indicating that the values of all components in
				the context be returned
			subscription is a Subscription object
		"""
		return  jsoncall.do_call(self.modelserver, self.modelport, "subscribe", {'modelname':self.modelname,\
										'user':self.user,\
										'password':self.password,\
										'context':context,\
										'view':view,\
										'subscription':subscription})
 def mkview(self, context=[], viewobj=None):
     """
     Make a new view in a given context
     arguments:
             context - a list giving the path to the required context
             viewobj - a View object
     returns:
             None on success
             a string error message on error
             """
     if viewobj == None:
         raise ValueError, "mkview: viewobj is None"
     if self.authType == 'app':
         self.auth = self.app + ":" + Personis_base.generate_app_signature(
             self.app, self.key)
     return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "mkview", {'modelname':self.modelname,\
                  'authType':self.authType,\
                  'auth':self.auth,\
                  'context':context,\
                  'viewobj':viewobj.__dict__})
示例#42
0
    def delcomponent(self,
            context=[],
            componentid=None):
        """
Delete an existing component in a given context
arguments:
        context - a list giving the path to the required context
        id - the id for a componen
returns:
        None on success
        a string error message on error
        """
        if componentid == None:
            raise ValueError, "delcomponent: componentid is None"
        return jsoncall.do_call("delcomponent", {'modelname':self.modelname,\
                                                                        'user':self.user,\
                                                                        'password':self.password,\
                                                                        'context':context,\
                                                                        'componentid':componentid},
                                                                        self.connection)
示例#43
0
    def __init__(self, connection=None, debug=0):
        self.debug =debug
        self.modelname = '-'
        self.user = ''
        self.password = ''
        self.connection = connection
        ok = False

        try:
            if self.debug != 0:
                print "jsondocall:", connection
            ok = jsoncall.do_call("access", {}, self.connection)
            if self.debug != 0:
                print "---------------------- result returned", ok
        except:
            if debug >0:
                traceback.print_exc()
            raise ValueError, "cannot access model"
        if not ok:
            raise ValueError, "server cannot access model"
示例#44
0
	def tell(self, 
		context=[],
		componentid=None,
		evidence=None):   # evidence obj
		"""
	arguments:
		context - a list giving the path to the required context
		componentid - identifier of the component
		evidence - evidence object to add to the component
		"""
		if componentid == None:
			raise ValueError, "tell: componentid is None"
		if evidence == None:
			raise ValueError, "tell: no evidence provided"
	
		return jsoncall.do_call(self.modelserver, self.modelport, "tell", {'modelname':self.modelname,\
										'user':self.user,\
										'password':self.password,\
										'context':context,\
										'componentid':componentid,\
										'evidence':evidence.__dict__})
示例#45
0
    def export_model(self,
            context=[],
            resolver=None):
        """
arguments:
        context is the context to export
        resolver is a string containing the name of a resolver
                or
        resolver is a dictionary containing information about resolver(s) to be used and arguments
                the "resolver" key gives the name of a resolver to use, if not present the default resolver is used
                the "evidence_filter" key specifies an evidence filter
                eg 'evidence_filter' =  "all" returns all evidence,
                                        "last10" returns last 10 evidence items,
                                        "last1" returns most recent evidence item,
                                        None returns no evidence
        """
        return jsoncall.do_call("export_model", {'modelname':self.modelname,\
                                                                        'user':self.user,\
                                                                        'password':self.password,\
                                                                        'context':context,\
                                                                        'resolver':resolver},
                                                                        self.connection)
示例#46
0
	def setresolver(self,
		context,
		componentid,
		resolver):
                """
        set the resolver for a given component in a given context
        arguments:
                context - a list giving the path to the required context
		componentid - the id for a given component
                resolver - the id of the resolver
        returns:
                None on success
                a string error message on error
                """
		if componentid == None:
			raise ValueError, "setresolver: componentid is None"
		return jsoncall.do_call(self.modelserver, self.modelport, "setresolver", {'modelname':self.modelname,\
										'user':self.user,\
                                                                                'password':self.password,\
                                                                                'context':context,\
                                                                                'componentid':componentid, \
										'resolver':resolver})
    def setresolver(self, context, componentid, resolver):
        """
        set the resolver for a given component in a given context
        arguments:
                context - a list giving the path to the required context
		componentid - the id for a given component
                resolver - the id of the resolver
        returns:
                None on success
                a string error message on error
                """
        if componentid == None:
            raise ValueError, "setresolver: componentid is None"
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "setresolver", {'modelname':self.modelname,\
                 'authType':self.authType,\
                 'auth':self.auth,\
                 'context':context,\
                 'componentid':componentid, \
                 'resolver':resolver})
    def tell(self,
             context=[],
             componentid=None,
             evidence=None):  # evidence obj
        """
	arguments:
		context - a list giving the path to the required context
		componentid - identifier of the component
		evidence - evidence object to add to the component
		"""
        if componentid == None:
            raise ValueError, "tell: componentid is None"
        if evidence == None:
            raise ValueError, "tell: no evidence provided"
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "tell", {'modelname':self.modelname,\
                  'authType':self.authType,\
                  'auth':self.auth,\
                  'context':context,\
                  'componentid':componentid,\
                  'evidence':evidence.__dict__})
    def export_model(self, context=[], level=None, resolver=None):
        """
	arguments:
		context is the context to export
                resolver is a string containing the name of a resolver
                        or
                resolver is a dictionary containing information about resolver(s) to be used and arguments
                        the "resolver" key gives the name of a resolver to use, if not present the default resolver is used
                        the "evidence_filter" key specifies an evidence filter
                        eg 'evidence_filter' =  "all" returns all evidence,
                                                "last10" returns last 10 evidence items,
                                                "last1" returns most recent evidence item,
                                                None returns no evidence
		"""
        if self.authType == 'app':
            self.auth = self.app + ":" + Personis_base.generate_app_signature(
                self.app, self.key)
        return jsoncall.do_call(self.modelserver, self.modelport, self.ca_certs_file, "export_model", {'modelname':self.modelname,\
                 'authType':self.authType,\
                 'auth':self.auth,\
                 'context':context,\
                 'level':level,\
                 'resolver':resolver})
示例#50
0
 def getresolvers(self):
     '''Return a list of the available resolver names'''
     return jsoncall.do_call("getresolvers", {'modelname':self.modelname,\
                                                                     'user':self.user, 'password':self.password},
                                                                     self.connection)
    def __init__(self,
                 model=None,
                 modelserver=None,
                 user=None,
                 password=None,
                 app=None,
                 description="",
                 debug=0,
                 ca_certs_file="ca_certs/ca.pem"):
        if modelserver == None:
            raise ValueError, "modelserver is None"
        if ':' in modelserver:
            self.modelserver, self.modelport = modelserver.split(":")
        else:
            self.modelserver = modelserver
            self.modelport = 2005  # default port for personis server
        self.modelname = model
        self.user = user
        self.password = password
        self.app = app
        self.description = description
        self.debug = debug
        self.key = None
        self.ca_certs_file = ca_certs_file
        if self.app == None:
            self.auth = user + ":" + password
            self.authType = "user"
        else:
            self.authType = "app"
            try:
                self.key = Personis_base.import_app_key(app)
            except Personis_exceptions.KeyFileNotFoundError:
                self.key = Personis_base.generate_app_key(self.app)
                fingerprint = Personis_base.generate_app_fingerprint(self.key)
                AppRequestAuth(model=self.modelname,
                               modelserver=self.modelserver,
                               app=self.app,
                               key=self.key.publickey().exportKey(),
                               description=self.description)
                message = "Authorisation has been requested for app " + self.app + " to access model " + self.model + " on server " + self.modelserver + ".\n"
                message += "Key fingerprint: %s\n" % (fingerprint)
                raise Personis_exceptions.AuthRequestedError(message)

        ok = False
        try:
            command = "access"
            args = {'modelname': self.modelname}
            if self.app != None:
                self.auth = self.app + ":" + Personis_base.generate_app_signature(
                    self.app, self.key)
                args['authType'] = 'app'
            else:
                args['authType'] = 'user'
            args['auth'] = self.auth
            if self.debug != 0:
                print "jsondocall:", self.modelserver, self.modelport, self.ca_certs_file, self.modelname, self.authType, self.auth

            ok = jsoncall.do_call(self.modelserver, self.modelport,
                                  self.ca_certs_file, command, args)
            if self.debug != 0:
                print "---------------------- result returned", ok
        except:
            if debug > 0:
                traceback.print_exc()
            raise
            raise ValueError, "cannot access model '%s', server '%s'" % (
                self.modelname, self.modelserver)
        if not ok:
            raise ValueError, "server '%s' cannot access model '%s'" % (
                self.modelserver, self.modelname)