Skip to content

Add Web API support for target data transfer#128

Merged
monodera merged 3 commits intomainfrom
u/monodera/transfer-via-api
Jan 9, 2026
Merged

Add Web API support for target data transfer#128
monodera merged 3 commits intomainfrom
u/monodera/transfer-via-api

Conversation

@monodera
Copy link
Contributor

@monodera monodera commented Jan 9, 2026

Summary

Add Web API support for downloading target data as an alternative to rsync-based transfer. This enables data transfer from environments without SSH access by downloading ZIP archives via HTTP/HTTPS.

Changes

  • New function: transfer_data_from_uploader_via_webapi() in utils.py

    • Downloads ZIP archives from Web API endpoints
    • Supports optional Bearer token authentication
    • SSL certificate verification control via config
    • Streams large files efficiently
    • Validates extracted directory structure
  • New CLI command: transfer-targets-api

    • Mirrors transfer-targets functionality
    • Uses Web API instead of rsync
  • Enhanced error handling:

    • HTTP errors (4xx, 5xx status codes)
    • Network timeouts and connection issues
    • Invalid ZIP files
    • Empty/invalid upload_ids
  • Configuration: New [webapi] section in config file

    [webapi]
    url = "https://example.com/get-upload/"
    api_key = ""  # Optional
    verify_ssl = false  # Optional
  • Improvements to both transfer functions:

    • Auto-create local_dir if it doesn't exist
    • Better handling of empty upload_ids
    • Improved status reporting (distinguishes skipped vs failed)

Testing

Tested with production Web API endpoint (pfs-etc.subaru.nao.ac.jp) with:

  • Fresh downloads
  • Skipping existing directories
  • Force re-download
  • Empty upload_ids
  • SSL certificate verification disabled

All transfers completed successfully with proper status reporting.

Documentation

  • Updated CLI reference documentation with new command
  • Added [webapi] configuration section examples

🤖 Generated with Claude Code

monodera and others added 3 commits January 8, 2026 23:04
Implement transfer_data_from_uploader_via_webapi function to download
target data via Web API as an alternative to rsync. This enables data
transfer from environments without SSH access.

Key features:
- Download and extract ZIP archives from Web API endpoints
- Support Bearer token authentication (optional)
- SSL certificate verification control (verify_ssl config option)
- Automatic detection and skipping of existing directories
- Proper handling of empty/invalid upload_ids
- Streaming downloads for large files
- Comprehensive error handling (HTTP, network, ZIP errors)
- Status reporting compatible with rsync version

Changes:
- Add requests dependency to pyproject.toml
- Implement transfer_data_from_uploader_via_webapi in utils.py
- Add transfer-targets-api CLI command
- Update both transfer functions to create local_dir if not exists
- Improve status reporting to distinguish skipped vs failed transfers
- Add [webapi] configuration section documentation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Break down the main function into smaller helper functions to improve
readability and reduce cyclomatic complexity (from 22 to ~7).

Changes:
- Extract _setup_webapi_config() for configuration initialization
- Extract _check_existing_directory() for directory checking logic
- Extract _download_zip_from_api() for ZIP download
- Extract _extract_and_validate_zip() for extraction and validation
- Extract _process_single_upload() to orchestrate single upload processing
- Main function now only handles setup, iteration, and status reporting

This addresses Codacy complexity warning (MC0001) while maintaining
identical functionality.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Configure markdownlint to allow patterns common in technical and
auto-generated documentation:

- MD013: Allow long lines for CLI docs and URLs
- MD014: Allow dollar signs in shell commands
- MD033: Allow inline HTML for documentation formatting
- MD034: Allow bare URLs
- MD041: Don't require first line to be a heading

These settings accommodate auto-generated CLI documentation from typer
and standard technical documentation practices.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@monodera monodera merged commit 8e7d5a2 into main Jan 9, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant