Skip to content

Commit 092d6c2

Browse files
authored
Merge pull request #16 from nasa/release/0.8.0
Release/0.8.0
2 parents 58d3f48 + bbea35f commit 092d6c2

File tree

14 files changed

+327
-168
lines changed

14 files changed

+327
-168
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ jobs:
3939

4040
steps:
4141
- name: Checkout repository
42-
uses: actions/checkout@v2
42+
uses: actions/checkout@v3
4343

4444
# Initializes the CodeQL tools for scanning.
4545
- name: Initialize CodeQL
46-
uses: github/codeql-action/init@v1
46+
uses: github/codeql-action/init@v2
4747
with:
4848
languages: ${{ matrix.language }}
4949
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -54,7 +54,7 @@ jobs:
5454
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5555
# If this step fails, then you should remove it and run the build manually (see below)
5656
- name: Autobuild
57-
uses: github/codeql-action/autobuild@v1
57+
uses: github/codeql-action/autobuild@v2
5858

5959
# ℹ️ Command-line programs to run using the OS shell.
6060
# 📚 https://git.io/JvXDl
@@ -68,4 +68,4 @@ jobs:
6868
# make release
6969

7070
- name: Perform CodeQL Analysis
71-
uses: github/codeql-action/analyze@v1
71+
uses: github/codeql-action/analyze@v2

.github/workflows/python-app.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ on:
77
push:
88
branches: [ develop ]
99
pull_request:
10-
branches: [ develop ]
10+
branches: [ develop, main ]
1111

1212
jobs:
1313
build:
1414

1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
1919
- name: Set up Python 3.10
20-
uses: actions/setup-python@v2
20+
uses: actions/setup-python@v4
2121
with:
2222
python-version: "3.10"
2323
- name: Install Poetry
24-
uses: abatilo/actions-poetry@v2.0.0
24+
uses: abatilo/actions-poetry@v2
2525
with:
26-
poetry-version: 1.1.11
26+
poetry-version: 1.5.1
2727
- name: Install dependencies
2828
run: |
2929
poetry run python -m pip install --upgrade pip

.github/workflows/python-publish.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ jobs:
1818
runs-on: ubuntu-latest
1919

2020
steps:
21-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v3
2222
- name: Set up Python
23-
uses: actions/setup-python@v2
23+
uses: actions/setup-python@v4
2424
with:
2525
python-version: '3.x'
2626
- name: Install Poetry
27-
uses: abatilo/actions-poetry@v2.0.0
27+
uses: abatilo/actions-poetry@v2
2828
with:
29-
poetry-version: 1.1.11
29+
poetry-version: 1.5.1
3030
- name: Build package
3131
run: poetry build
3232
- name: Publish to pypi.org

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
## [0.8.0]
11+
### Added
12+
- [pull/15](https://github.com/nasa/python_cmr/pull/15): New feature added to filter by granules within the circle around lat/lon
13+
- [pull/12](https://github.com/nasa/python_cmr/pull/12): Added environments to module level to simplify imports to `from cmr import CMR_UAT`
14+
### Changed
15+
- Changed token url to being tokens in authorization headers.
16+
- Add in bearer token function for use of EDL bearer token in authorization headers.
1017

1118
## [0.7.0]
1219
### Added
@@ -31,8 +38,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
3138
## [Older]
3239
- Prior releases of this software originated from https://github.com/jddeal/python-cmr/releases
3340

34-
[Unreleased]: https://github.com/nasa/python_cmr/compare/v0.7.0...HEAD
35-
[0.7.0]: https://github.com/nasa/python_cmr/compare/v0.6.0...0.7.0
41+
[Unreleased]: https://github.com/nasa/python_cmr/compare/v0.8.0...HEAD
42+
[0.8.0]: https://github.com/nasa/python_cmr/compare/v0.7.0...v0.8.0
43+
[0.7.0]: https://github.com/nasa/python_cmr/compare/v0.6.0...v0.7.0
3644
[0.6.0]: https://github.com/nasa/python_cmr/compare/v0.5.0...v0.6.0
3745
[0.5.0]: https://github.com/nasa/python_cmr/compare/ef0f9e7d67ce99d342a568bd6a098c3462df16d2...v0.5.0
38-
[Older]: https://github.com/jddeal/python-cmr/releases
46+
[Older]: https://github.com/jddeal/python-cmr/releases

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ The following methods are available to both collecton and granule queries:
9999

100100
# search by provider
101101
>>> api.provider('POCLOUD')
102+
103+
# search non-ops CMR environment
104+
>>> from cmr import CMR_UAT
105+
>>> api.mode(CMR_UAT)
102106

103107
Granule searches support these methods (in addition to the shared methods above):
104108

@@ -211,6 +215,14 @@ specified before making the request:
211215

212216
>>> granules = api.format("echo10").get(100)
213217

218+
We can add token to the api calls by setting headers using the following functions:
219+
220+
# Use token function for EDL echo-token or launchpad token
221+
>>> api.token(token)
222+
223+
# Use bearer token function for EDL bearer tokens
224+
>>> api.bearer_token(token)
225+
214226
The following formats are supported for both granule and collection queries:
215227

216228
- json (default)
@@ -280,4 +292,4 @@ poetry run flake8
280292

281293
```shell
282294
poetry run pytest
283-
```
295+
```

cmr/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .queries import GranuleQuery, CollectionQuery, ToolQuery, ServiceQuery, VariableQuery
1+
from .queries import GranuleQuery, CollectionQuery, ToolQuery, ServiceQuery, VariableQuery, CMR_OPS, CMR_UAT, CMR_SIT
22

3-
__all__ = ["GranuleQuery", "CollectionQuery", "ToolQuery", "ServiceQuery", "VariableQuery"]
3+
__all__ = ["GranuleQuery", "CollectionQuery", "ToolQuery", "ServiceQuery", "VariableQuery", "CMR_OPS", "CMR_UAT", "CMR_SIT"]

cmr/queries.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, route, mode=CMR_OPS):
3737
self._route = route
3838
self.mode(mode)
3939
self.concept_id_chars = []
40+
self.headers = None
4041

4142
def get(self, limit=2000):
4243
"""
@@ -53,7 +54,7 @@ def get(self, limit=2000):
5354
page = 1
5455
while len(results) < limit:
5556

56-
response = get(url, params={'page_size': page_size, 'page_num': page})
57+
response = get(url, headers=self.headers, params={'page_size': page_size, 'page_num': page})
5758

5859
try:
5960
response.raise_for_status()
@@ -83,7 +84,7 @@ def hits(self):
8384

8485
url = self._build_url()
8586

86-
response = get(url, params={'page_size': 0})
87+
response = get(url, headers=self.headers, params={'page_size': 0})
8788

8889
try:
8990
response.raise_for_status()
@@ -273,18 +274,35 @@ def mode(self, mode=CMR_OPS):
273274

274275
def token(self, token):
275276
"""
276-
Add token into url request.
277+
Add token into authorization headers.
277278
278-
:param token: Token from EDL.
279+
:param token: Token from EDL Echo-Token or NASA Launchpad token.
279280
:returns: Query instance
280281
"""
281282

282283
if not token:
283284
return self
284285

285-
self.params['token'] = token
286+
self.headers = {'Authorization': token}
287+
286288
return self
287289

290+
def bearer_token(self, bearer_token):
291+
"""
292+
Add token into authorization headers.
293+
294+
:param token: Token from EDL token.
295+
:returns: Query instance
296+
"""
297+
298+
if not bearer_token:
299+
return self
300+
301+
self.headers = {'Authorization': 'Bearer ' + bearer_token}
302+
303+
return self
304+
305+
288306
class GranuleCollectionBaseQuery(Query):
289307
"""
290308
Base class for Granule and Collection CMR queries.
@@ -417,6 +435,18 @@ def point(self, lon, lat):
417435

418436
return self
419437

438+
def circle(self, lon: float, lat: float, dist: int):
439+
"""Filter by granules within the circle around lat/lon
440+
441+
:param lon: longitude of geographic point
442+
:param lat: latitude of geographic point
443+
:param dist: distance in meters around waypoint (lat,lon)
444+
:returns: Query instance
445+
"""
446+
self.params['circle'] = f"{lon},{lat},{dist}"
447+
448+
return self
449+
420450
def polygon(self, coordinates):
421451
"""
422452
Filter by granules that overlap a polygonal area. Must be used in combination with a

0 commit comments

Comments
 (0)