Esempio n. 1
0
    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"]
Esempio n. 2
0
    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']
Esempio n. 3
0
 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
Esempio n. 4
0
 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
Esempio n. 5
0
 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
Esempio n. 6
0
 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
Esempio n. 7
0
 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
Esempio n. 8
0
 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
Esempio n. 9
0
    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"]
Esempio n. 10
0
    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"]
Esempio n. 11
0
    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']
Esempio n. 12
0
    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']