def upload_document(self, filename, encrypted_content, participants_keys, doc_id=None): """Upload a user document. :param filename: The document filename. :param encrypted_content: The document encrypted content :param participantKeys: A Mapping of the document encrypted key for each participant. """ url = self.build_url("/models/%s/records" % (config.get("document_model_id"))) data = json.dumps({"filename": filename, "content": encrypted_content, "participantsKeys": participants_keys}) if doc_id is None: r = self.session.post(url, data=data) else: url += "/%s" % doc_id r = self.session.put(url, data=data) try: r.raise_for_status() except HTTPError: print(r.json()) raise return r.json()["id"]
def upload_document(self, filename, encrypted_content, participants_keys, doc_id=None): """Upload a user document. :param filename: The document filename. :param encrypted_content: The document encrypted content :param participantKeys: A Mapping of the document encrypted key for each participant. """ url = self.build_url("/models/%s/records" % (config.get("document_model_id"))) data = json.dumps({ "filename": filename, "content": encrypted_content, "participantsKeys": participants_keys }) if doc_id is None: r = self.session.post(url, data=data) else: url += "/%s" % doc_id r = self.session.put(url, data=data) try: r.raise_for_status() except HTTPError: print(r.json()) raise return r.json()['id']
def remove_author_from_document(self, hawk_id, doc_id): url = self.build_url("/models/%s/records/%s/authors" % (config.get("document_model_id"), doc_id)) r = self.session.patch(url, data=json.dumps(["-%s" % hawk_id])) try: r.raise_for_status() except HTTPError: print(r.json()) raise
def delete_document(self, doc_id): url = self.build_url("/models/%s/records/%s" % (config.get("document_model_id"), doc_id)) r = self.session.delete(url) try: r.raise_for_status() except HTTPError: print(r.json()) raise
def update_participant_keys(self, doc_id, new_participants_keys): url = self.build_url("/models/%s/records/%s" % (config.get("document_model_id"), doc_id)) data = json.dumps({"participantsKeys": new_participants_keys}) r = self.session.patch(url, data=data) try: r.raise_for_status() except HTTPError: print(r.json()) raise
def remove_author_from_document(self, hawk_id, doc_id): url = self.build_url("/models/%s/records/%s/authors" % (config.get("document_model_id"), doc_id)) r = self.session.patch(url, data=json.dumps(['-%s' % hawk_id])) try: r.raise_for_status() except HTTPError: print(r.json()) raise
def list_documents(self): """List user documents. """ url = self.build_url("/models/%s/records" % (config.get("document_model_id"))) r = self.session.get(url) try: r.raise_for_status() except HTTPError: print(r.json()) raise return r.json()["records"]
def get_public_key(self, identifier): """Returns a public key for the given identifier. :param identifier: an email address or phone number or hawk id. """ url = self.build_url("/models/%s/records/%s" % (config.get("pubkey_store_model_id"), identifier)) r = self.session.get(url) try: r.raise_for_status() except HTTPError: raise PublicKeyNotFound(r.json()) return r.json()["pub"]
def list_documents(self): """List user documents. """ url = self.build_url("/models/%s/records" % (config.get("document_model_id"))) r = self.session.get(url) try: r.raise_for_status() except HTTPError: print(r.json()) raise return r.json()['records']
def get_public_key(self, identifier): """Returns a public key for the given identifier. :param identifier: an email address or phone number or hawk id. """ url = self.build_url("/models/%s/records/%s" % (config.get("pubkey_store_model_id"), identifier)) r = self.session.get(url) try: r.raise_for_status() except HTTPError: raise PublicKeyNotFound(r.json()) return r.json()['pub']