astrosat / django-astrosat-core

Common backend library for Astrosat projects' core functionality
GNU General Public License v3.0
0 stars 0 forks source link

proxy view should escape characters #15

Closed allynt closed 4 years ago

allynt commented 4 years ago

Checklist

Is your feature request related to a problem? Please describe

The API can proxy GET requests to S3 Buckets. However, if the object names in the bucket being requested have special characters in them (such as "&") they must first be escaped.

Describe the solution you'd like

Escape the key parameter prior to calling client.get_object(key) in ProxyS3View (in django-astrosat-core).

Describe alternatives you've considered

Just rename the objects to not have characters that require escaping.

allynt commented 4 years ago

So this is a feature not a bug. The ampersand character is used as the separator between different query parameters, so obviously escaping it is not very straightforward. By the time we get to the ProxyView it's already gone.

I can instead, escape it before it gets to the view. For example, in THERMCERT the LayersView builds a URL to send to the ProxyView. The key value can be escaped while it's being generated:

from urllib import parse
client = DataClient()
objs = client.get_objects(key, metadata_only=True)
for obj in objs:
  obj_key = parse.quote(obj.metadata["key"]) 
  obj_url = f"/api/proxy/s3?key={obj_key}"