(
env: Environment,
repo: str | None,
sync: bool,
output_accounts: str | None,
unsafe_tar_extract: bool,
)
| 287 | @pass_env |
| 288 | @handle_api_exception(logger) |
| 289 | def dump( |
| 290 | env: Environment, |
| 291 | repo: str | None, |
| 292 | sync: bool, |
| 293 | output_accounts: str | None, |
| 294 | unsafe_tar_extract: bool, |
| 295 | ): |
| 296 | if not hasattr(tarfile, "data_filter") and not unsafe_tar_extract: |
| 297 | logger.error( |
| 298 | "You need to use Python >= 3.11 in order to safely unpack the downloaded tar file, or you need to pass " |
| 299 | "in --unsafe-tar-extract argument to allow unsafe tar file extracting" |
| 300 | ) |
| 301 | sys.exit(-1) |
| 302 | config = ensure_auth_config(api_base_url=env.api_base_url, repo=repo) |
| 303 | if sync: |
| 304 | run_sync(env, config) |
| 305 | |
| 306 | private_key = PrivateKey.generate() |
| 307 | public_key = private_key.public_key.encode(URLSafeBase64Encoder).decode("ascii") |
| 308 | |
| 309 | with make_auth_client(base_url=env.api_base_url, token=config.token) as client: |
| 310 | client.raise_on_unexpected_status = True |
| 311 | resp: CreateDumpRequestResponse = create_dump_request.sync( |
| 312 | body=CreateDumpRequestRequest( |
| 313 | public_key=public_key, output_accounts=output_accounts is not None |
| 314 | ), |
| 315 | username=config.username, |
| 316 | repo_name=config.repo, |
| 317 | client=client, |
| 318 | ) |
| 319 | dump_id = resp.id |
| 320 | logger.info( |
| 321 | "Created dump [green]%s[/] with public_key [green]%s[/], waiting for updates ...", |
| 322 | dump_id, |
| 323 | public_key, |
| 324 | extra={"markup": True, "highlighter": None}, |
| 325 | ) |
| 326 | |
| 327 | while True: |
| 328 | time.sleep(5) |
| 329 | resp: GetDumpRequestResponse = get_dump_request.sync( |
| 330 | dump_request_id=dump_id, |
| 331 | username=config.username, |
| 332 | repo_name=config.repo, |
| 333 | client=client, |
| 334 | ) |
| 335 | if resp.state == DumpRequestState.FAILED: |
| 336 | logger.error("Failed to dump with error: %s", resp.error_message) |
| 337 | sys.exit(-1) |
| 338 | elif resp.state == DumpRequestState.COMPLETE: |
| 339 | break |
| 340 | else: |
| 341 | logger.debug("State is %s, keep polling...", resp.state) |
| 342 | |
| 343 | download_url = resp.download_url |
| 344 | sealed_box = SealedBox(private_key) |
| 345 | encryption_key = json.loads( |
| 346 | sealed_box.decrypt(URLSafeBase64Encoder.decode(resp.encryption_key)) |
nothing calls this directly
no test coverage detected