def retrieve_agent_profile_ids(self, agent, since=None): """Retrieve agent profile id(s) with the specified parameters :param agent: Agent object of desired agent profiles :type agent: :class:`tincan.agent.Agent` :param since: Retrieve agent profile id's since this time :type since: str | unicode :return: LRS Response object with list of retrieved agent profile id's as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(agent, Agent): agent = Agent(agent) request = HTTPRequest(method="GET", resource="agents/profile") request.query_params["agent"] = agent.to_json(self.version) if since is not None: request.query_params["since"] = since lrs_response = self._send_request(request) if lrs_response.success: lrs_response.content = json.loads(lrs_response.data) return lrs_response
def retrieve_agent_profile(self, agent, profile_id): """Retrieve agent profile with the specified parameters :param agent: Agent object of the desired agent profile :type agent: :class:`tincan.agent.Agent` :param profile_id: UUID of the desired agent profile :type profile_id: str | unicode :return: LRS Response object with an agent profile doc as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(agent, Agent): agent = Agent(agent) request = HTTPRequest(method="GET", resource="agents/profile", ignore404=True) request.query_params = { "profileId": profile_id, "agent": agent.to_json(self.version) } lrs_response = self._send_request(request) if lrs_response.success: doc = AgentProfileDocument(id=profile_id, content=lrs_response.data, agent=agent) headers = lrs_response.response.getheaders() if "lastModified" in headers and headers[ "lastModified"] is not None: doc.timestamp = headers["lastModified"] if "contentType" in headers and headers["contentType"] is not None: doc.content_type = headers["contentType"] if "etag" in headers and headers["etag"] is not None: doc.etag = headers["etag"] lrs_response.content = doc return lrs_response
def retrieve_agent_profile_ids(self, agent, since=None): """Retrieve agent profile id(s) with the specified parameters :param agent: Agent object of desired agent profiles :type agent: :class:`tincan.agent.Agent` :param since: Retrieve agent profile id's since this time :type since: str | unicode :return: LRS Response object with list of retrieved agent profile id's as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(agent, Agent): agent = Agent(agent) request = HTTPRequest( method="GET", resource="agents/profile" ) request.query_params["agent"] = agent.to_json(self.version) if since is not None: request.query_params["since"] = since lrs_response = self._send_request(request) if lrs_response.success: lrs_response.content = json.loads(lrs_response.data) return lrs_response
def retrieve_state_ids(self, activity, agent, registration=None, since=None): """Retrieve state id's from the LRS with the provided parameters :param activity: Activity object of desired states :type activity: :class:`tincan.activity.Activity` :param agent: Agent object of desired states :type agent: :class:`tincan.agent.Agent` :param registration: Registration UUID of desired states :type registration: str | unicode :param since: Retrieve state id's since this time :type since: str | unicode :return: LRS Response object with the retrieved state id's as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(activity, Activity): activity = Activity(activity) if not isinstance(agent, Agent): agent = Agent(agent) request = HTTPRequest(method="GET", resource="activities/state") request.query_params = { "activityId": activity.id, "agent": agent.to_json(self.version) } if registration is not None: request.query_params["registration"] = registration if since is not None: request.query_params["since"] = since lrs_response = self._send_request(request) if lrs_response.success: lrs_response.content = json.loads(lrs_response.data) return lrs_response
def retrieve_state(self, activity, agent, state_id, registration=None): """Retrieve state from LRS with the provided parameters :param activity: Activity object of desired state :type activity: :class:`tincan.activity.Activity` :param agent: Agent object of desired state :type agent: :class:`tincan.agent.Agent` :param state_id: UUID of desired state :type state_id: str | unicode :param registration: registration UUID of desired state :type registration: str | unicode :return: LRS Response object with retrieved state document as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(activity, Activity): activity = Activity(activity) if not isinstance(agent, Agent): agent = Agent(agent) request = HTTPRequest( method="GET", resource="activities/state", ignore404=True ) request.query_params = { "activityId": activity.id, "agent": agent.to_json(self.version), "stateId": state_id } if registration is not None: request.query_params["registration"] = registration lrs_response = self._send_request(request) if lrs_response.success: doc = StateDocument( id=state_id, content=lrs_response.data, activity=activity, agent=agent ) if registration is not None: doc.registration = registration headers = lrs_response.response.getheaders() if "lastModified" in headers and headers["lastModified"] is not None: doc.timestamp = headers["lastModified"] if "contentType" in headers and headers["contentType"] is not None: doc.content_type = headers["contentType"] if "etag" in headers and headers["etag"] is not None: doc.etag = headers["etag"] lrs_response.content = doc return lrs_response
def _delete_state(self, activity, agent, state_id=None, registration=None, etag=None): """Private method to delete a specified state from the LRS :param activity: Activity object of state to be deleted :type activity: :class:`tincan.activity.Activity` :param agent: Agent object of state to be deleted :type agent: :class:`tincan.agent.Agent` :param state_id: UUID of state to be deleted :type state_id: str | unicode :param registration: registration UUID of state to be deleted :type registration: str | unicode :param etag: etag of state to be deleted :type etag: str | unicode :return: LRS Response object with deleted state as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(activity, Activity): activity = Activity(activity) if not isinstance(agent, Agent): agent = Agent(agent) request = HTTPRequest(method="DELETE", resource="activities/state") if etag is not None: request.headers["If-Match"] = etag request.query_params = { "activityId": activity.id, "agent": agent.to_json(self.version) } if state_id is not None: request.query_params["stateId"] = state_id if registration is not None: request.query_params["registration"] = registration lrs_response = self._send_request(request) return lrs_response
def _delete_state(self, activity, agent, state_id=None, registration=None, etag=None): """Private method to delete a specified state from the LRS :param activity: Activity object of state to be deleted :type activity: :class:`tincan.activity.Activity` :param agent: Agent object of state to be deleted :type agent: :class:`tincan.agent.Agent` :param state_id: UUID of state to be deleted :type state_id: str | unicode :param registration: registration UUID of state to be deleted :type registration: str | unicode :param etag: etag of state to be deleted :type etag: str | unicode :return: LRS Response object with deleted state as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(activity, Activity): activity = Activity(activity) if not isinstance(agent, Agent): agent = Agent(agent) request = HTTPRequest( method="DELETE", resource="activities/state" ) if etag is not None: request.headers["If-Match"] = etag request.query_params = { "activityId": activity.id, "agent": agent.to_json(self.version) } if state_id is not None: request.query_params["stateId"] = state_id if registration is not None: request.query_params["registration"] = registration lrs_response = self._send_request(request) return lrs_response
def retrieve_agent_profile(self, agent, profile_id): """Retrieve agent profile with the specified parameters :param agent: Agent object of the desired agent profile :type agent: :class:`tincan.agent.Agent` :param profile_id: UUID of the desired agent profile :type profile_id: str | unicode :return: LRS Response object with an agent profile doc as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(agent, Agent): agent = Agent(agent) request = HTTPRequest( method="GET", resource="agents/profile", ignore404=True ) request.query_params = { "profileId": profile_id, "agent": agent.to_json(self.version) } lrs_response = self._send_request(request) if lrs_response.success: doc = AgentProfileDocument( id=profile_id, content=lrs_response.data, agent=agent ) headers = lrs_response.response.getheaders() if "lastModified" in headers and headers["lastModified"] is not None: doc.timestamp = headers["lastModified"] if "contentType" in headers and headers["contentType"] is not None: doc.content_type = headers["contentType"] if "etag" in headers and headers["etag"] is not None: doc.etag = headers["etag"] lrs_response.content = doc return lrs_response
def retrieve_state_ids(self, activity, agent, registration=None, since=None): """Retrieve state id's from the LRS with the provided parameters :param activity: Activity object of desired states :type activity: :class:`tincan.activity.Activity` :param agent: Agent object of desired states :type agent: :class:`tincan.agent.Agent` :param registration: Registration UUID of desired states :type registration: str | unicode :param since: Retrieve state id's since this time :type since: str | unicode :return: LRS Response object with the retrieved state id's as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(activity, Activity): activity = Activity(activity) if not isinstance(agent, Agent): agent = Agent(agent) request = HTTPRequest( method="GET", resource="activities/state" ) request.query_params = { "activityId": activity.id, "agent": agent.to_json(self.version) } if registration is not None: request.query_params["registration"] = registration if since is not None: request.query_params["since"] = since lrs_response = self._send_request(request) if lrs_response.success: lrs_response.content = json.loads(lrs_response.data) return lrs_response