Skip to content

Commit 274897f

Browse files
authored
Merge pull request #207 from descarteslabs/update
Remove Deprecated Endpoints
2 parents ada6d31 + 0013184 commit 274897f

File tree

13 files changed

+64
-225
lines changed

13 files changed

+64
-225
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ Changelog
3636
=========
3737

3838
## [Unreleased]
39-
## [0.7.0] - 2018-01-2
39+
## [0.8.0] - 2018-02-08
40+
### Changed
41+
- Removed deprecated searching by const_id
42+
- Removed deprecated raster band methods
43+
44+
## [0.7.0] - 2018-01-24
4045
### Changed
4146
- Reorganization into a client submodule
4247

@@ -188,7 +193,8 @@ metadata.features for iterating over large search results
188193
### Added
189194
- Initial release of client library
190195

191-
[Unreleased]: https://github.com/descarteslabs/descarteslabs-python/compare/v0.7.0...HEAD
196+
[Unreleased]: https://github.com/descarteslabs/descarteslabs-python/compare/v0.8.0...HEAD
197+
[0.8.0]: https://github.com/descarteslabs/descarteslabs-python/compare/v0.7.0...v0.8.0
192198
[0.7.0]: https://github.com/descarteslabs/descarteslabs-python/compare/v0.6.2...v0.7.0
193199
[0.6.2]: https://github.com/descarteslabs/descarteslabs-python/compare/v0.6.1...v0.6.2
194200
[0.6.1]: https://github.com/descarteslabs/descarteslabs-python/compare/v0.6.0...v0.6.1

descarteslabs/client/auth/auth.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,26 @@ def __init__(self, domain="https://iam.descarteslabs.com",
7474
self.token_info_path = token_info_path
7575

7676
token_info = {}
77-
try:
78-
if self.token_info_path:
77+
if self.token_info_path:
78+
try:
7979
with open(self.token_info_path) as fp:
8080
token_info = json.load(fp)
81-
except (IOError, ValueError):
82-
pass
81+
except (IOError, ValueError):
82+
pass
8383

8484
self.client_id = client_id if client_id else os.environ.get('CLIENT_ID', token_info.get('client_id', None))
8585
self.client_secret = client_secret if client_secret else os.environ.get('CLIENT_SECRET', token_info.get(
8686
'client_secret', None))
8787
self._token = jwt_token if jwt_token else os.environ.get('JWT_TOKEN', token_info.get('jwt_token', None))
8888

89-
client_id_changed = token_info.get('client_id', None) != self.client_id
90-
client_secret_changed = token_info.get('client_secret', None) != self.client_secret
89+
if token_info:
90+
# If the token was read from a path but environment variables were set, we may need
91+
# to reset the token.
92+
client_id_changed = token_info.get('client_id', None) != self.client_id
93+
client_secret_changed = token_info.get('client_secret', None) != self.client_secret
9194

92-
if client_id_changed or client_secret_changed:
93-
self._token = None
95+
if client_id_changed or client_secret_changed:
96+
self._token = None
9497

9598
self._namespace = None
9699

descarteslabs/client/auth/tests/test_auth.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
import json
1919

2020

21+
# flake8: noqa
22+
anon_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJncm91cHMiOlsicHVibGljIl0sImlzcyI6Imh0dHBzOi8vZGVzY2FydGVzbGFicy5hdXRoMC5jb20vIiwic3ViIjoiZGVzY2FydGVzfGFub24tdG9rZW4iLCJhdWQiOiJaT0JBaTRVUk9sNWdLWklweHhsd09FZng4S3BxWGYyYyIsImV4cCI6OTk5OTk5OTk5OSwiaWF0IjoxNDc4MjAxNDE5fQ.QL9zq5SkpO7skIy0niIxI0B92uOzZT5t1abuiJaspRI"
23+
24+
2125
class TestAuth(unittest.TestCase):
2226
def test_get_token(self):
2327
# get a jwt
@@ -35,6 +39,10 @@ def test_get_namespace(self):
3539
auth = Auth.from_environment_or_token_json()
3640
self.assertIsNotNone(auth.namespace)
3741

42+
def test_init_token_no_path(self):
43+
auth = Auth(jwt_token=anon_token, token_info_path=None, client_id="foo")
44+
self.assertEquals(anon_token, auth._token)
45+
3846

3947
if __name__ == '__main__':
4048
unittest.main()

descarteslabs/client/scripts/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
metadata_parser.add_argument('argument', nargs='?')
4141
metadata_parser.add_argument('-url', help='The url of the service')
4242
metadata_parser.add_argument('-place', help='A slug for a named place')
43-
metadata_parser.add_argument('-const_id', default=None, help='Constellation ID', nargs='+')
4443
metadata_parser.add_argument('-start_time', help='Start of valid date/time range (inclusive)')
4544
metadata_parser.add_argument('-end_time', help='End of valid date/time range (inclusive)')
4645
metadata_parser.add_argument('-geom', help='Region of interest as GeoJSON or WKT')

descarteslabs/client/services/metadata/cli.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ def metadata_handler(args):
3535
if args.command == 'summary':
3636
if args.place:
3737
kwargs['place'] = args.place
38-
if args.const_id:
39-
kwargs['const_id'] = args.const_id
4038
if args.start_time:
4139
kwargs['start_time'] = args.start_time
4240
if args.end_time:
@@ -53,8 +51,6 @@ def metadata_handler(args):
5351
if args.command == 'search':
5452
if args.place:
5553
kwargs['place'] = args.place
56-
if args.const_id:
57-
kwargs['const_id'] = args.const_id
5854
if args.start_time:
5955
kwargs['start_time'] = args.start_time
6056
if args.end_time:
@@ -75,8 +71,6 @@ def metadata_handler(args):
7571
if args.command == 'keys':
7672
if args.place:
7773
kwargs['place'] = args.place
78-
if args.const_id:
79-
kwargs['const_id'] = args.const_id
8074
if args.start_time:
8175
kwargs['start_time'] = args.start_time
8276
if args.end_time:

descarteslabs/client/services/metadata/metadata.py

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
from descarteslabs.client.services.raster import Raster
2323
from descarteslabs.client.services.metadata.metadata_filtering import AndExpression
2424

25-
CONST_ID_DEPRECATION_MESSAGE = (
26-
"Keyword arg `const_id' has been deprecated and will be removed in "
27-
"future versions of the library. Use the `products` "
28-
"argument instead. Product identifiers can be found with the "
29-
" products() method."
30-
)
3125

3226
OFFSET_DEPRECATION_MESSAGE = (
3327
"Keyword arg `offset` has been deprecated and will be removed in "
@@ -145,28 +139,18 @@ def get_bands_by_key(self, key):
145139

146140
return r.json()
147141

148-
def get_bands_by_constellation(self, const):
149-
"""
150-
For a given constellation id, return the available bands.
151-
152-
:param str const: A constellation name/abbreviation.
153-
154-
:return: A dictionary of band entries and their metadata.
155-
"""
156-
r = self.session.get('/bands/constellation/%s' % const)
157-
return r.json()
158-
159-
def products(self, bands=None, limit=None, offset=None, owner=None, **kwargs):
142+
def products(self, bands=None, limit=None, offset=None, owner=None, text=None, **kwargs):
160143
"""Search products that are available on the platform.
161144
162145
:param list(str) bands: Band name(s) e.g ["red", "nir"] to filter products by.
163146
Note that products must match all bands that are passed.
164147
:param int limit: Number of results to return.
165148
:param int offset: Index to start at when returning results.
166149
:param str owner: Filter products by the owner's uuid.
150+
:param str text: Filter products by string match.
167151
168152
"""
169-
params = ['limit', 'offset', 'bands', 'owner']
153+
params = ['limit', 'offset', 'bands', 'owner', 'text']
170154

171155
args = locals()
172156
kwargs = dict(kwargs, **{
@@ -194,25 +178,13 @@ def available_products(self):
194178

195179
return r.json()
196180

197-
def translate(self, const_id):
198-
"""Translate a deprecated constellation identifier
199-
into a new-style product identifier.
200-
201-
:param string const_id: The constellation identifier to translate.
202-
"""
203-
204-
r = self.session.get('/products/translate/{}'.format(const_id))
205-
206-
return r.json()
207-
208-
def summary(self, products=None, const_id=None, sat_id=None, date='acquired', part=None,
181+
def summary(self, products=None, sat_id=None, date='acquired', part=None,
209182
place=None, geom=None, start_time=None, end_time=None, cloud_fraction=None,
210183
cloud_fraction_0=None, fill_fraction=None, q=None, pixels=None,
211184
dltile=None):
212185
"""Get a summary of the results for the specified spatio-temporal query.
213186
214187
:param list(str) products: Product identifier(s).
215-
:param list(str) const_id: Constellation identifier(s).
216188
:param list(str) sat_id: Satellite identifier(s).
217189
:param str date: The date field to use for search (e.g. `acquired`).
218190
:param str part: Part of the date to aggregate over (e.g. `day`).
@@ -273,13 +245,6 @@ def summary(self, products=None, const_id=None, sat_id=None, date='acquired', pa
273245

274246
kwargs['products'] = products
275247

276-
if const_id:
277-
warn(CONST_ID_DEPRECATION_MESSAGE, DeprecationWarning)
278-
if isinstance(const_id, string_types):
279-
const_id = [const_id]
280-
281-
kwargs['const_id'] = const_id
282-
283248
if date:
284249
kwargs['date'] = date
285250

@@ -315,7 +280,7 @@ def summary(self, products=None, const_id=None, sat_id=None, date='acquired', pa
315280
r = self.session.post('/summary', json=kwargs)
316281
return r.json()
317282

318-
def search(self, products=None, const_id=None, sat_id=None, date='acquired', place=None,
283+
def search(self, products=None, sat_id=None, date='acquired', place=None,
319284
geom=None, start_time=None, end_time=None, cloud_fraction=None,
320285
cloud_fraction_0=None, fill_fraction=None, q=None, limit=100, offset=0,
321286
fields=None, dltile=None, sort_field=None, sort_order="asc", randomize=None,
@@ -324,7 +289,6 @@ def search(self, products=None, const_id=None, sat_id=None, date='acquired', pla
324289
optional. For accessing more than 10000 results, see :py:func:`features`.
325290
326291
:param list(str) products: Product Identifier(s).
327-
:param list(str) const_id: Constellation Identifier(s).
328292
:param list(str) sat_id: Satellite identifier(s).
329293
:param str date: The date field to use for search (e.g. `acquired`).
330294
:param str place: A slug identifier to be used as a region of interest.
@@ -388,14 +352,6 @@ def search(self, products=None, const_id=None, sat_id=None, date='acquired', pla
388352

389353
kwargs['products'] = products
390354

391-
if const_id:
392-
warn(CONST_ID_DEPRECATION_MESSAGE, DeprecationWarning)
393-
394-
if isinstance(const_id, string_types):
395-
const_id = [const_id]
396-
397-
kwargs['const_id'] = const_id
398-
399355
if geom:
400356
kwargs['geom'] = geom
401357

@@ -444,15 +400,14 @@ def search(self, products=None, const_id=None, sat_id=None, date='acquired', pla
444400

445401
return fc
446402

447-
def ids(self, products=None, const_id=None, sat_id=None, date='acquired', place=None,
403+
def ids(self, products=None, sat_id=None, date='acquired', place=None,
448404
geom=None, start_time=None, end_time=None, cloud_fraction=None,
449405
cloud_fraction_0=None, fill_fraction=None, q=None, limit=100, offset=None,
450406
dltile=None, sort_field=None, sort_order=None, randomize=None):
451407
"""Search metadata given a spatio-temporal query. All parameters are
452408
optional.
453409
454410
:param list(str) products: Products identifier(s).
455-
:param list(str) const_id: Constellation identifier(s).
456411
:param list(str) sat_id: Satellite identifier(s).
457412
:param str date: The date field to use for search (e.g. `acquired`).
458413
:param str place: A slug identifier to be used as a region of interest.
@@ -486,7 +441,7 @@ def ids(self, products=None, const_id=None, sat_id=None, date='acquired', place=
486441
['landsat:LC08:PRE:TOAR:meta_LC80270312016188_v1']
487442
488443
"""
489-
result = self.search(sat_id=sat_id, products=products, const_id=const_id, date=date,
444+
result = self.search(sat_id=sat_id, products=products, date=date,
490445
place=place, geom=geom, start_time=start_time,
491446
end_time=end_time, cloud_fraction=cloud_fraction,
492447
cloud_fraction_0=cloud_fraction_0, fill_fraction=fill_fraction,
@@ -495,15 +450,14 @@ def ids(self, products=None, const_id=None, sat_id=None, date='acquired', place=
495450

496451
return [feature['id'] for feature in result['features']]
497452

498-
def keys(self, products=None, const_id=None, sat_id=None, date='acquired', place=None,
453+
def keys(self, products=None, sat_id=None, date='acquired', place=None,
499454
geom=None, start_time=None, end_time=None, cloud_fraction=None,
500455
cloud_fraction_0=None, fill_fraction=None, q=None, limit=100, offset=0,
501456
dltile=None, sort_field=None, sort_order='asc', randomize=None):
502457
"""Search metadata given a spatio-temporal query. All parameters are
503458
optional. Results are paged using limit/offset.
504459
505460
:param list(str) products: Products identifier(s).
506-
:param list(str) const_id: Constellation identifier(s).
507461
:param list(str) sat_id: Satellite identifier(s).
508462
:param str date: The date field to use for search (e.g. `acquired`).
509463
:param str place: A slug identifier to be used as a region of interest.
@@ -537,7 +491,7 @@ def keys(self, products=None, const_id=None, sat_id=None, date='acquired', place
537491
['meta_LC80270312016188_v1']
538492
539493
"""
540-
result = self.search(sat_id=sat_id, products=products, const_id=const_id, date=date,
494+
result = self.search(sat_id=sat_id, products=products, date=date,
541495
place=place, geom=geom, start_time=start_time,
542496
end_time=end_time, cloud_fraction=cloud_fraction,
543497
cloud_fraction_0=cloud_fraction_0, fill_fraction=fill_fraction,
@@ -547,7 +501,7 @@ def keys(self, products=None, const_id=None, sat_id=None, date='acquired', place
547501

548502
return [feature['key'] for feature in result['features']]
549503

550-
def features(self, products=None, const_id=None, sat_id=None, date='acquired', place=None,
504+
def features(self, products=None, sat_id=None, date='acquired', place=None,
551505
geom=None, start_time=None, end_time=None, cloud_fraction=None,
552506
cloud_fraction_0=None, fill_fraction=None, q=None, fields=None,
553507
batch_size=1000, dltile=None, sort_field=None, sort_order='asc',
@@ -575,7 +529,7 @@ def features(self, products=None, const_id=None, sat_id=None, date='acquired', p
575529
continuation_token = None
576530

577531
while True:
578-
result = self.search(sat_id=sat_id, products=products, const_id=None,
532+
result = self.search(sat_id=sat_id, products=products,
579533
date=date, place=place, geom=geom,
580534
start_time=start_time, end_time=end_time,
581535
cloud_fraction=cloud_fraction,

descarteslabs/client/services/metadata/tests/test_metadata.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import itertools
1616
import unittest
17-
from warnings import catch_warnings
1817

1918
from descarteslabs.client.services.metadata import Metadata, properties as p
2019
from descarteslabs.client.exceptions import NotFoundError
@@ -61,10 +60,6 @@ def test_cloud_fraction(self):
6160
for feature in r['features']:
6261
self.assertEqual(feature['properties']['cloud_fraction'], 0.0)
6362

64-
def test_translate_to_product(self):
65-
r = self.instance.translate('l8')
66-
self.assertEqual(r['product'], 'landsat:LC08:PRE:TOAR')
67-
6863
def test_search_by_product(self):
6964
r = self.instance.search(start_time='2016-07-06', end_time='2016-07-07', products=['landsat:LC08:PRE:TOAR'])
7065
self.assertGreater(len(r['features']), 0)
@@ -102,13 +97,6 @@ def test_fields(self):
10297
for feature in r['features']:
10398
self.assertEqual(sorted(feature['properties'].keys()), sorted(fields))
10499

105-
def test_const_id_search_deprecation(self):
106-
with catch_warnings(record=True) as w:
107-
r = self.instance.search(start_time='2016-07-06', end_time='2016-07-07', const_id=['l8'])
108-
self.assertGreater(len(r['features']), 0)
109-
self.assertEqual(len(w), 1)
110-
self.assertIn('deprecated', str(w[0].message))
111-
112100
def test_multiple_products_search(self):
113101
r = self.instance.search(
114102
start_time='2016-07-06',
@@ -134,23 +122,6 @@ def test_summary(self):
134122
self.assertIn('bytes', r)
135123
self.assertGreater(r['count'], 0)
136124

137-
def test_const_id_summary_deprecation(self):
138-
with catch_warnings(record=True) as w:
139-
r = self.instance.summary(
140-
start_time='2016-07-06',
141-
end_time='2016-07-07',
142-
const_id=['l8'],
143-
pixels=True
144-
)
145-
self.assertEqual(len(w), 1)
146-
self.assertIn('deprecated', str(w[0].message))
147-
148-
self.assertIn('products', r)
149-
self.assertIn('count', r)
150-
self.assertIn('pixels', r)
151-
self.assertIn('bytes', r)
152-
self.assertGreater(r['count'], 0)
153-
154125
def test_summary_part(self):
155126
r = self.instance.summary(
156127
start_time='2016-07-06',
@@ -216,9 +187,6 @@ def test_derived_bands_search(self):
216187
def test_get_bands_by_key(self):
217188
self.instance.get_bands_by_key('meta_LC80270312016188_v1')
218189

219-
def test_get_bands_by_const(self):
220-
self.instance.get_bands_by_constellation('L8')
221-
222190
def test_expr_serialization(self):
223191
q = ((0.1 < p.cloud_fraction <= 0.2) & (p.sat_id == "f00b")) | (p.sat_id == "usa-245")
224192
expected_q = {"or": [

0 commit comments

Comments
 (0)