Skip to content

Commit aff411a

Browse files
author
Clara Brasseur
committed
making mast aws access anonymous
1 parent f365097 commit aff411a

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

astroquery/mast/cloud.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from astropy.logger import log
1515
from astropy.utils.console import ProgressBarOrSpinner
16+
from astropy.utils.exceptions import AstropyDeprecationWarning
1617

1718
from ..exceptions import NoResultsWarning, InvalidQueryError
1819

@@ -44,25 +45,24 @@ def __init__(self, provider="AWS", profile=None, verbose=False):
4445
Default False. Display extra info and warnings if true.
4546
"""
4647

48+
# Dealing with deprecated argument
49+
if profile is not None:
50+
warnings.warn(("MAST cloud data is now free to access and does "
51+
"not require an AWS account"), AstropyDeprecationWarning)
52+
4753
import boto3
4854
import botocore
4955

5056
self.supported_missions = ["mast:hst/product", "mast:tess/product", "mast:kepler"]
5157

52-
if profile is not None:
53-
self.boto3 = boto3.Session(profile_name=profile)
54-
else:
55-
self.boto3 = boto3
58+
self.boto3 = boto3
5659
self.botocore = botocore
60+
self.config = botocore.client.Config(signature_version=botocore.UNSIGNED)
5761

5862
self.pubdata_bucket = "stpubdata"
5963

6064
if verbose:
6165
log.info("Using the S3 STScI public dataset")
62-
log.warning("Your AWS account will be charged for access to the S3 bucket")
63-
log.info("See Request Pricing in https://aws.amazon.com/s3/pricing/ for details")
64-
log.info("If you have not configured boto3, follow the instructions here: "
65-
"https://boto3.readthedocs.io/en/latest/guide/configuration.html")
6666

6767
def is_supported(self, data_product):
6868
"""
@@ -110,7 +110,8 @@ def get_cloud_uri(self, data_product, include_bucket=True, full_url=False):
110110
found in the cloud, None is returned.
111111
"""
112112

113-
s3_client = self.boto3.client('s3')
113+
114+
s3_client = self.boto3.client('s3', config=self.config)
114115

115116
path = utils.mast_relative_path(data_product["dataURI"])
116117
if path is None:
@@ -119,7 +120,7 @@ def get_cloud_uri(self, data_product, include_bucket=True, full_url=False):
119120
path = path.lstrip("/")
120121

121122
try:
122-
s3_client.head_object(Bucket=self.pubdata_bucket, Key=path, RequestPayer='requester')
123+
s3_client.head_object(Bucket=self.pubdata_bucket, Key=path)
123124
if include_bucket:
124125
path = "s3://{}/{}".format(self.pubdata_bucket, path)
125126
elif full_url:
@@ -172,8 +173,8 @@ def download_file(self, data_product, local_path, cache=True):
172173
Default is True. If file is found on disc it will not be downloaded again.
173174
"""
174175

175-
s3 = self.boto3.resource('s3')
176-
s3_client = self.boto3.client('s3')
176+
s3 = self.boto3.resource('s3', config=self.config)
177+
s3_client = self.boto3.client('s3', config=self.config)
177178
bkt = s3.Bucket(self.pubdata_bucket)
178179
with warnings.catch_warnings():
179180
warnings.simplefilter("ignore")
@@ -182,7 +183,7 @@ def download_file(self, data_product, local_path, cache=True):
182183
raise Exception("Unable to locate file {}.".format(data_product['productFilename']))
183184

184185
# Ask the webserver (in this case S3) what the expected content length is and use that.
185-
info_lookup = s3_client.head_object(Bucket=self.pubdata_bucket, Key=bucket_path, RequestPayer='requester')
186+
info_lookup = s3_client.head_object(Bucket=self.pubdata_bucket, Key=bucket_path)
186187
length = info_lookup["ContentLength"]
187188

188189
if cache and os.path.exists(local_path):
@@ -219,5 +220,4 @@ def progress_callback(numbytes):
219220
bytes_read += numbytes
220221
pb.update(bytes_read)
221222

222-
bkt.download_file(bucket_path, local_path, ExtraArgs={"RequestPayer": "requester"},
223-
Callback=progress_callback)
223+
bkt.download_file(bucket_path, local_path, Callback=progress_callback)

astroquery/mast/observations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def download_file(self, uri, local_path=None, base_url=None, cache=True, cloud_o
539539
local_path = os.path.join(os.path.abspath('.'), filename)
540540

541541
# recreate the data_product key for cloud connection check
542-
data_product = {'dataURI': data_url}
542+
data_product = {'dataURI': uri}
543543

544544
status = "COMPLETE"
545545
msg = None

0 commit comments

Comments
 (0)