Esempio n. 1
0
    def download_file(self, path: str, stream: io.BufferedWriter) -> Response:
        """
        Calls the gRPC DownloadFile function

        :param path: (str) The location of the file which needs to be downloaded
        :param stream: (io.BufferedWriter) A BufferedWriter to write to
        :return: (Response) The response object containing values corresponding to the request
        """
        meta = self._make_meta()
        download_file_request = server_pb2.DownloadFileRequest(path=path,
                                                               meta=meta)
        for response in self.stub.DownloadFile(download_file_request):
            if response.status == 200:
                stream.write(response.payload)
            else:
                return Response(
                    server_pb2.Response(status=response.status,
                                        error=response.error))
        return Response(server_pb2.Response(status=200))
Esempio n. 2
0
    def list_files(self, path: str) -> Response:
        """
        Calls the gRPC ListFiles function

        :param path: (str) The path of the folder to be searched
        :return: (Response) The response object containing values corresponding to the request
        """
        meta = self._make_meta()
        list_files_request = server_pb2.ListFilesRequest(path=path, meta=meta)
        return Response(self.stub.ListFiles(list_files_request))
Esempio n. 3
0
    def profiles(self, db_type: str) -> Response:
        """
        Calls the gRPC Profiles function

        :param db_type: (str) The database type
        :return: (Response) The response object containing values corresponding to the request
        """
        meta = self._make_meta(db_type=db_type)
        profiles_request = server_pb2.ProfilesRequest(meta=meta)
        return Response(self.stub.Profiles(profiles_request))
Esempio n. 4
0
    def delete_file(self, path: str) -> Response:
        """
        Calls the gRPC DeleteFile function

        :param path: (str) The location of the file to be deleted
        :return: (Response) The response object containing values corresponding to the request
        """
        meta = self._make_meta()
        delete_file_request = server_pb2.DeleteFileRequest(path=path,
                                                           meta=meta)
        return Response(self.stub.DeleteFile(delete_file_request))
Esempio n. 5
0
    def create_folder(self, path: str, name: str) -> Response:
        """
        Calls the gRPC CreateFolder function

        :param path: (str) The location in which the folder is to be added
        :param name: (str) The name of the folder
        :return: (Response) The response object containing values corresponding to the request
        """
        meta = self._make_meta()
        create_folder_request = server_pb2.CreateFolderRequest(path=path,
                                                               name=name,
                                                               meta=meta)
        return Response(self.stub.CreateFolder(create_folder_request))
Esempio n. 6
0
    def batch(self, all_requests: List[server_pb2.AllRequest],
              db_type: str) -> Response:
        """
        Calls the gRPC Batch function

        :param all_requests: (List) A list of gRPC AllRequest objects
        :param db_type: (str) The database type
        :return: (Response) The response object containing values corresponding to the request
        """
        meta = self._make_meta(db_type)
        batch_request = server_pb2.BatchRequest(meta=meta,
                                                batchrequest=all_requests)
        return Response(self.stub.Batch(batch_request))
Esempio n. 7
0
    def pubsub_publish(self, subject: str, msg) -> Response:
        """
        Calls the gRPC PubsubPublish function

        :param subject: (str) The subject to publish to
        :param msg: The message to be published
        :return: (Response) The response object containing values corresponding to the request
        """
        msg = obj_to_utf8_bytes(msg)
        meta = self._make_meta()
        publish_request = server_pb2.PubsubPublishRequest(subject=subject,
                                                          msg=msg,
                                                          meta=meta)
        return Response(self.stub.PubsubPublish(publish_request))
Esempio n. 8
0
    def sign_in(self, email: str, password: str, db_type: str) -> Response:
        """
        Calls the gRPC SignIn function

        :param email: (str) The user's email id
        :param password: (str) The user's password
        :param db_type: (str) The database type
        :return: (Response) The response object containing values corresponding to the request
        """
        meta = self._make_meta(db_type=db_type)
        sign_in_request = server_pb2.SignInRequest(email=email,
                                                   password=password,
                                                   meta=meta)
        return Response(self.stub.SignIn(sign_in_request))
Esempio n. 9
0
    def delete(self, find, operation: str, db_type: str, col: str) -> Response:
        """
        Calls the gRPC Delete function

        :param find: The find parameters
        :param operation: (str) The operation to perform
        :param db_type: (str) The database type
        :param col: (str) The (optional) collection name
        :return: (Response) The response object containing values corresponding to the request
        """
        find = obj_to_utf8_bytes(find)
        meta = self._make_meta(db_type, col)
        delete_request = server_pb2.DeleteRequest(find=find,
                                                  operation=operation,
                                                  meta=meta)
        return Response(self.stub.Delete(delete_request))
Esempio n. 10
0
    def aggregate(self, pipeline, operation: str, db_type: str,
                  col: str) -> Response:
        """
        Calls the gRPC Aggregate function

        :param pipeline: The pipeline parameters
        :param operation: (str) The operation to perform
        :param db_type: (str) The database type
        :param col: (str) The (optional) collection name
        :return: (Response) The response object containing values corresponding to the request
        """
        pipeline = obj_to_utf8_bytes(pipeline)
        meta = self._make_meta(db_type, col)
        aggregate_request = server_pb2.AggregateRequest(pipeline=pipeline,
                                                        operation=operation,
                                                        meta=meta)
        return Response(self.stub.Aggregate(aggregate_request))
Esempio n. 11
0
    def create(self, document, operation: str, db_type: str,
               col: str) -> Response:
        """
        Calls the gRPC Create function

        :param document: The document to create
        :param operation: (str) The operation to perform
        :param db_type: (str) The database type
        :param col: (str) The (optional) collection name
        :return: (Response) The response object containing values corresponding to the request
        """
        document = obj_to_utf8_bytes(document)
        meta = self._make_meta(db_type, col)
        create_request = server_pb2.CreateRequest(document=document,
                                                  operation=operation,
                                                  meta=meta)
        return Response(self.stub.Create(create_request))
Esempio n. 12
0
    def upload_file(self, path: str, name: str,
                    stream: io.BufferedReader) -> Response:
        """
        Calls the gRPC UploadFile function

        :param path: (str) The location in which the file needs to be uploaded
        :param name: (str) The name of the file to be created
        :param stream: (io.BufferedReader) A BufferedReader to read from
        :return: (Response) The response object containing values corresponding to the request
        """
        meta = self._make_meta()

        def iterator():
            yield server_pb2.UploadFileRequest(path=path, name=name, meta=meta)
            for chunk in iter(lambda: stream.read(constants.PayloadSize), b''):
                yield server_pb2.UploadFileRequest(payload=chunk)

        return Response(self.stub.UploadFile(iterator()))
Esempio n. 13
0
    def faas(self, service: str, function: str, params,
             timeout: int) -> Response:
        """
        Calls the gRPC Call function

        :param service: (str) The name of service(engine) with which the function is registered
        :param function: (str) The name of function to be called
        :param params: The params for the function
        :param timeout: (int) The timeout in milliseconds
        :return: (Response) The response object containing values corresponding to the request
        """
        params = obj_to_utf8_bytes(params)
        functions_request = server_pb2.FunctionsRequest(
            params=params,
            timeout=timeout // 1000,
            service=service,
            function=function,
            token=self.token,
            project=self.project_id)
        return Response(self.stub.Call(functions_request))
Esempio n. 14
0
    def edit_profile(self, _id: str, email: str, name: str, password: str,
                     db_type: str) -> Response:
        """
        Calls the gRPC EditProfile function

        :param _id: (str) The user's id
        :param email: (str) The (optional) new email id
        :param name: (str) Then (optional) new name
        :param password: (str) The (optional) new password
        :param db_type: (str) The database type
        :return: (Response) The response object containing values corresponding to the request
        """
        meta = self._make_meta(db_type=db_type)
        edit_profile_request = server_pb2.EditProfileRequest(id=_id, meta=meta)
        if email is not None:
            edit_profile_request.email = email
        if name is not None:
            edit_profile_request.name = name
        if password is not None:
            edit_profile_request.password = password
        return Response(self.stub.EditProfile(edit_profile_request))