def call_api(self, api_client: API, session: Session) -> str: ''' Override ApiJob. Star or Unstar an user on the server ''' try: source_sdk_object = sdclientapi.Source(uuid=self.source_uuid) # TODO: Once https://github.com/freedomofpress/securedrop-client/issues/648, we will # want to pass the default request timeout to remove_star and add_star instead of # setting it on the api object directly. api_client.default_request_timeout = 5 if self.is_starred: api_client.remove_star(source_sdk_object) else: api_client.add_star(source_sdk_object) return self.source_uuid except (RequestTimeoutError, ServerConnectionError) as e: error_message = f'Failed to update star on source {self.source_uuid} due to error: {e}' raise UpdateStarJobTimeoutError(error_message, self.source_uuid) except Exception as e: error_message = f'Failed to update star on source {self.source_uuid} due to {e}' raise UpdateStarJobError(error_message, self.source_uuid)
def _make_call(self, encrypted_reply: str, api_client: API) -> sdclientapi.Reply: sdk_source = sdclientapi.Source(uuid=self.source_uuid) # TODO: Once https://github.com/freedomofpress/securedrop-client/issues/648, we will want to # pass the default request timeout to reply_source instead of setting it on the api object # directly. api_client.default_request_timeout = 5 return api_client.reply_source(sdk_source, encrypted_reply, self.reply_uuid)
def call_download_api(self, api: API, db_object: Reply) -> Tuple[str, str]: ''' Override DownloadJob. ''' sdk_object = SdkReply(uuid=db_object.uuid, filename=db_object.filename) sdk_object.source_uuid = db_object.source.uuid # TODO: Once https://github.com/freedomofpress/securedrop-sdk/issues/108 is implemented, we # will want to pass the default request timeout to download_reply instead of setting it on # the api object directly. api.default_request_timeout = 20 return api.download_reply(sdk_object)
def call_api(self, api_client: API, session: Session) -> Any: ''' Override ApiJob. Download new metadata, update the local database, import new keys, and then the success signal will let the controller know to add any new download jobs. ''' # TODO: Once https://github.com/freedomofpress/securedrop-client/issues/648, we will want to # pass the default request timeout to api calls instead of setting it on the api object # directly. api_client.default_request_timeout = 40 remote_sources, remote_submissions, remote_replies = get_remote_data( api_client) update_local_storage(session, self.gpg, remote_sources, remote_submissions, remote_replies, self.data_dir)
def call_api(self, api_client: API, session: Session) -> str: ''' Override ApiJob. Delete a source on the server ''' try: source_sdk_object = sdclientapi.Source(uuid=self.source_uuid) # TODO: After https://github.com/freedomofpress/securedrop-client/issues/648 is # merged, we will want to pass the timeout to delete_source instead of setting # it on the api object api_client.default_request_timeout = 5 api_client.delete_source(source_sdk_object) return self.source_uuid except (RequestTimeoutError, ServerConnectionError): raise except Exception as e: error_message = "Failed to delete source {uuid} due to {exception}".format( uuid=self.source_uuid, exception=repr(e)) raise DeleteSourceJobException(error_message, self.source_uuid)