Skip to content

Commit

Permalink
Updated AWS reads to allow anon access for datasets such as NASA TOPS
Browse files Browse the repository at this point in the history
  • Loading branch information
sandyfreelance committed Oct 17, 2024
1 parent 88ba11e commit ec2988c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cdflib/cdfread.py
Original file line number Diff line number Diff line change
Expand Up @@ -2042,20 +2042,31 @@ def _file_or_url_or_s3_handler(
elif filetype == "s3":
try:
import boto3
from botocore.handlers import disable_signing
from botocore.client import Config
from botocore import UNSIGNED
except:
raise ImportError("boto3 package not installed")
raise ImportError("boto3/botocore package not installed")
s3parts = filename.split("/") # 0-1=s3://, 2=bucket, 3+=key
mybucket = s3parts[2]
mykey = "/".join(s3parts[3:])
if s3_read_method == 3:
# read in-place
s3c = boto3.resource("s3")
obj = s3c.Object(bucket_name=mybucket, key=mykey)
try:
obj = s3c.Object(bucket_name=mybucket, key=mykey)
except:
s3c.meta.client.meta.events.register('choose-signer.s3.*',disable_signing)
obj = s3c.Object(bucket_name=mybucket, key=mykey)
bdata = S3object(obj) # type: ignore
else:
# for store in memory or as temp copy
s3c = boto3.client("s3")
obj = s3c.get_object(Bucket=mybucket, Key=mykey)
try:
obj = s3c.get_object(Bucket=mybucket, Key=mykey)
except:
s3c = boto3.client('s3', config=Config(signature_version=UNSIGNED))
obj = s3c.get_object(Bucket=mybucket, Key=mykey)
bdata = s3_fetchall(obj)
return bdata
else:
Expand Down

0 comments on commit ec2988c

Please sign in to comment.