Esempio n. 1
0
    def PostObjectJSON(self, provider, object_type, payload):
        """ Used by web services interface for pushing objects to a service gateway.

		Expects a payload as a JSON dictionary, where the keys are the appropriate fields of <object_type>
		This method converts the dictionary to a native object and pushes it through the PRISONER pipe for sanitisation and publication
		"""
        dumb_social = SocialObjects.SocialObject()
        payload = json.loads(payload)
        for key, value in payload.items():
            setattr(dumb_social, key, value)

        self.PostObject(provider, object_type, dumb_social)
Esempio n. 2
0
    def GetObjectJSON(self,
                      provider,
                      object_type,
                      payload,
                      criteria,
                      extra_args=None):
        """ Interface for retrieving objects from a service gateway, for
		consumption by web services.

		This differs from GetObject in some fundamental ways. GetObject
		is more pythonic - you request objects by supplying relevant SocialObjects, and
		you get SocialObject instances in return. This method however, receives
		plain-text responses, and returns
		JSON objects. Whereas GetObject expects a
		semantically-appropriate SocialObject as the payload (eg. supply an instance of Person to
		receive objects of a given type owned by that Person), this method expects a
		payload expressed as a query string, using the namespaced syntax found in the
		privacy policy spec. For example, a payload of "session:Lastfm.id" will
		be evaluated as "get objects authored by the user ID in the Last.fm session.
		"literal:lukeweb", similarly, returns objects owned by that literal user.
		JSON objects are returned, with the same fields as the Pythonic counterparts. A
		key difference is that the returned object has an additional attribute injected
		- prisoner_id. This is a unique identifier for the returned object *that is
		  valid for the duration of this session*. Rather than passing around full
		instances of objects, subsequent queries, or publication of experimental
		responses, need only refer to this ID to ensure PRISONER is able to relate your
		requests back to the full representation of the data. Note that subsequent
		attempts to retrieve the cached object are subject to the privacy policy
		sanitisation process of the *original* request.
		"""
        # evaluate payload
        eval_payload = self.policy_processor._infer_object(payload)
        eval_payload_obj = SocialObjects.SocialObject()
        eval_payload_obj.id = eval_payload

        # use this to passthrough original object, not wrapped
        # as a dumb SocialObject
        eval_payload_obj = eval_payload

        # call getobject with cleaned object
        ret_object = self.GetObject(provider, object_type, eval_payload_obj,
                                    True, criteria, extra_args)
        # cache the object under a unique id, JSONify, return
        if ret_object != None:
            ident = self.cache_object(ret_object)
            try:
                return jsonpickle.encode(self.cached_objects[ident])
            except:
                return None
        else:
            return None