IMAP-Science-Operations-Center / imap-data-access

Package to download, query, and upload files from the IMAP Science Data Center.
MIT License
0 stars 7 forks source link

BUG - Download not working without full file path #23

Closed maxinelasp closed 1 month ago

maxinelasp commented 4 months ago

Description of the issue

The download method in the CLI doesn't work properly if a file is requested via filename (as opposed to full file path.) The CLI attempts to add IMAP_DATA_DIR to the front of the filename.

Steps to reproduce the issue

    1. 3.
  1. Run imap-data-access download imap_mag_l1a_raw-norm_20240221_20240221_v01-00.cdf

Code Snippet:

# in io.py
destination = imap_data_access.config["DATA_DIR"]
if isinstance(file_path, str) and "/" not in file_path:
    # Construct the directory structure from the filename
    # This is for science files that contain the directory structure in the filename
    # Otherwise, we assume the full path to the file was given

    # ERROR IS HERE: file_path is never updated with full expected path
    science_file_path = imap_data_access.ScienceFilePath(file_path)

    destination = science_file_path.construct_path()
else:
    destination /= file_path

Expected behavior (What should happen)

File should be able to be downloaded from just the filename

Actual behavior (What does happen)

404 Error

Additional notes

No response

Affected areas (code, data, or process)

io.py

Suggested fix?

set file_path = science_file_path.construct_filepath()

greglucas commented 3 months ago

Does this actually need to be updated on the API/backend side? I think we had discussed allowing /download/imap_mag_l1a_raw-norm_20240221_20240221_v01-00.cdf in the past and not requiring the full path to the file? So it might need to be reworked in the APIs and not in this repository, depending on how we want to fix this.

tech3371 commented 3 months ago

Now I know why this ticket was created and what we need to fix.

Download API lambda handler expects this event input:

   event = {
        "resource": "/download/{proxy+}",
        "path": "/download/file_path=imap/mag/l0/2023/12/imap_mag_l0_raw_20231212_v001.pkts",
        "httpMethod": "GET",
        .....
        "pathParameters": {
            "proxy": "imap/mag/l0/2023/12/imap_mag_l0_raw_20231212_v001.pkts"
        },
       ....
    }

But it get's this input from download call from this package.

   event = {
        "resource": "/download/{proxy+}",
        "path": "/download/file_path=imap/mag/l0/2023/12/imap_mag_l0_raw_20231212_v001.pkts",
        "httpMethod": "GET",
        .....
        "pathParameters": {
            "proxy": "file_path=imap/mag/l0/2023/12/imap_mag_l0_raw_20231212_v001.pkts"
        },
       ....
    }

Based on how we want API to look, looks like we either need to update here to not send file_path= in the API call or update lambda to remove this prefix.