Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
c7b0120
Cleanup unused imports && added role definition and security
Oct 18, 2022
a700ef2
Simple api role checking
dmytrotsko Oct 18, 2022
75509cb
Render api key warnings
dmytrotsko Oct 18, 2022
a796e2c
Move tests
dmytrotsko Oct 18, 2022
8d48b20
Add api user ddl
dmytrotsko Oct 18, 2022
c753f73
tests
dmytrotsko Oct 18, 2022
a15a36e
improve dockerignore
dmytrotsko Oct 18, 2022
4fc210d
support api date via env
dmytrotsko Oct 18, 2022
ee0c087
start with admin interface
dmytrotsko Oct 18, 2022
0446ea9
start with simple admin interface
dmytrotsko Oct 18, 2022
c7ca927
very basic admin interface
dmytrotsko Oct 18, 2022
d066a90
list all known roles
dmytrotsko Oct 18, 2022
8b09387
remove log statement
dmytrotsko Oct 18, 2022
e940f8b
fixup tests
dmytrotsko Oct 18, 2022
8bb2789
add record flag to user
dmytrotsko Oct 18, 2022
3161d2e
basic record based on flag logging
dmytrotsko Oct 18, 2022
9ab8978
rename column to tracking
dmytrotsko Oct 18, 2022
54dc83c
add webhook endpoint for google forms and simplify table
dmytrotsko Oct 18, 2022
62122cf
tests for simplified api_user
dmytrotsko Oct 18, 2022
32096ac
prepare for sending mails with mailgun
dmytrotsko Oct 18, 2022
45414bc
disable security check for test setup
dmytrotsko Oct 18, 2022
60f7cd6
fix tests
dmytrotsko Oct 18, 2022
dac3fcb
add registered flag
dmytrotsko Oct 18, 2022
d880795
request a simple api key form with recaptcha check
dmytrotsko Oct 18, 2022
e76cde4
implement rate limiting
dmytrotsko Oct 18, 2022
f1f008e
registered flag not saved
dmytrotsko Oct 18, 2022
98315c6
mark all tests no rate limit
dmytrotsko Oct 18, 2022
f897e28
add link to registration form within api key form
dmytrotsko Oct 18, 2022
b345f76
elevate sqlalchemy log level to ERROR for test purpose
dmytrotsko Oct 18, 2022
5ce96bd
add structlog to requirements
dmytrotsko Oct 18, 2022
f851d5b
add structured logging module
dmytrotsko Oct 18, 2022
38abd83
implement api key scrubbing logs and getter functions for User class
dmytrotsko Oct 18, 2022
d65acb8
minor commenting change
dmytrotsko Oct 18, 2022
5aee08f
change logging to kward format and add a get function for API key
dmytrotsko Oct 18, 2022
7378e8d
move mask_apikey function out of User class
dmytrotsko Oct 18, 2022
02a535b
minor change in variable name
dmytrotsko Oct 18, 2022
c18a122
Fixed test
dmytrotsko Oct 18, 2022
da947fd
added missing import
dmytrotsko Oct 18, 2022
4732467
Fixed _is_public_route method. Added URL_PREFIX to list of routes
dmytrotsko Oct 24, 2022
ae1e6a1
Merge pull request #2 from dmytrotsko/fix_admin_endpoint_access
dmytrotsko Oct 24, 2022
16a154c
Added email column to User table
dmytrotsko Oct 25, 2022
4b5fa65
Merge branch 'api_key' of github.com:dmytrotsko/delphi-epidata into a…
dmytrotsko Oct 25, 2022
a8011fd
Fixed tests
dmytrotsko Oct 25, 2022
6775384
Added Dockerfile for Redis
dmytrotsko Oct 25, 2022
7e11435
Made email optional
dmytrotsko Oct 25, 2022
74fd290
Added email address validaiton
dmytrotsko Oct 26, 2022
8d496ba
Fixed API key creation via /create_key endpoint
dmytrotsko Oct 27, 2022
3bc7095
Fixed /register endpoint after google script refactoring
dmytrotsko Oct 27, 2022
e39c82a
Fixed registration
dmytrotsko Oct 28, 2022
be80550
Reverted some changes in _config.py
dmytrotsko Oct 28, 2022
8f21122
Reverted changes in .env.example
dmytrotsko Nov 2, 2022
71bb186
Code refactoring
dmytrotsko Nov 2, 2022
aea77eb
Removed unused variables
dmytrotsko Nov 2, 2022
b7a6078
Code cleaning
dmytrotsko Nov 2, 2022
635be31
Removed unused variables
dmytrotsko Nov 3, 2022
93b056e
Removed default redis configuration file (it is not needed for now)
dmytrotsko Nov 3, 2022
df11183
Moved BASE_URL and auth to setUP, formatted code
dmytrotsko Nov 3, 2022
b63faa3
Moved BASE_URL and auth to setUP(), formatted code
dmytrotsko Nov 3, 2022
9ed758b
Revert "Moved BASE_URL and auth to setUP(), formatted code"
dmytrotsko Nov 3, 2022
02083a0
Formatted code & removed unused imports.
dmytrotsko Nov 4, 2022
99f75a6
Created staticmethod _make_rqeuest() and reused it in test_caching() …
dmytrotsko Nov 7, 2022
f94ec4d
Returned BASE_URL and auth back, because if we use default BASE_URL f…
dmytrotsko Nov 7, 2022
0480172
Completely removed patch_flask_config() function as it is useless. Th…
dmytrotsko Nov 7, 2022
3586bcf
Removed duplicated _logger.py file (this is exact copy of src/acquisi…
dmytrotsko Nov 7, 2022
1ee16f7
Fixed test
dmytrotsko Nov 8, 2022
7ce411b
Removed unused method
dmytrotsko Nov 8, 2022
68240ca
Added missing changes in Dockerfiles for copying logger
dmytrotsko Nov 8, 2022
d350347
Fixed misspelled filename
dmytrotsko Nov 9, 2022
4bca6b4
Added missing variable in CSVPrinter
dmytrotsko Nov 9, 2022
3cf15da
Formatted code
dmytrotsko Nov 9, 2022
ad00db5
Removed tests for admin endpoint for now
dmytrotsko Nov 9, 2022
4285b87
Moved config variables from _security to _config. Removed duplicated …
dmytrotsko Nov 9, 2022
ec67149
Added missing changes
dmytrotsko Nov 15, 2022
7a364d9
Replaced db.execute delete and update with built-it sqlalchemy functi…
dmytrotsko Nov 15, 2022
e4ae70c
Removed email field. Edited google form link to prefill tracking cons…
dmytrotsko Nov 15, 2022
c21689d
Removed api_user ddl
dmytrotsko Nov 24, 2022
1ebff22
Changed user roles to use m2m table instead of string in api_user table
dmytrotsko Nov 28, 2022
c49c1f8
Added new variable for api key expiration date
dmytrotsko Nov 28, 2022
c54412c
Updated admin endpoint. Removed email from user details and added cre…
dmytrotsko Nov 28, 2022
6c50703
Updated integration tests
dmytrotsko Nov 28, 2022
3e34e3c
Updated endpoints to register user role on endpoint load
dmytrotsko Nov 28, 2022
8fbae7d
Removed user_role FK in api_user table.
dmytrotsko Nov 30, 2022
95507c2
Updated according to new structure
dmytrotsko Nov 30, 2022
597eeb4
Removed API_KEY_EXPIRE_AFTER variable
dmytrotsko Nov 30, 2022
08bd2b6
Removed creation_date, expiration_date and last_api_access_date from …
dmytrotsko Nov 30, 2022
c436b0a
Added roles registraion on endpoints load
dmytrotsko Nov 30, 2022
199d434
Removed role registration statement
dmytrotsko Nov 30, 2022
4422a5e
Fixed integration tests. Actually reverted latest changes as api_user…
dmytrotsko Nov 30, 2022
806d6e4
Added new ddls
dmytrotsko Nov 30, 2022
82a0e25
Merge branch 'dev' into api_key
dmytrotsko Nov 30, 2022
58f715d
Fixed wrong import
dmytrotsko Dec 1, 2022
73efe70
Fixed issue after resolving conflicts
dmytrotsko Dec 1, 2022
d291f61
Moved admin endpoint to another file into endpoints folder
dmytrotsko Dec 27, 2022
efe545f
Removed from _security.py all unnecessary functions
dmytrotsko Dec 27, 2022
7433cf2
Changed roles registration process. Now we have only necessary roles.…
dmytrotsko Dec 27, 2022
c1947c3
Added IF NOT EXISTS to table creation statement
dmytrotsko Dec 27, 2022
466adfb
Added missing import
dmytrotsko Dec 27, 2022
16c4dec
Moved admin models to the separate file. Now we have only 1 User clas…
dmytrotsko Dec 27, 2022
007be57
Added declarative_base and session objects to the _db.py file. To hav…
dmytrotsko Dec 27, 2022
a2de0c7
Updated tests to use statement in order to clean api_user table afte…
dmytrotsko Dec 27, 2022
835d602
Reverted formatting
dmytrotsko Feb 24, 2023
0913051
Reverted formatting
dmytrotsko Feb 28, 2023
0c5f12a
Removed copying of _logger.py
dmytrotsko Feb 28, 2023
0e9c7c8
Fixed auth props
dmytrotsko Feb 28, 2023
e212abe
Added missing requirements
dmytrotsko Feb 28, 2023
56c8cbb
Added authentication params
dmytrotsko Feb 28, 2023
d3ec9a6
Removed unused imports
dmytrotsko Feb 28, 2023
db9d87b
Added new columns to api_user table
dmytrotsko Mar 21, 2023
4c6d84a
Added placeholder to handle api key last usage update
dmytrotsko Mar 21, 2023
2f2398a
Added Redis host variable
dmytrotsko Mar 22, 2023
c75f0ea
Uncommented @after_reqeust function to update last API key usage in R…
dmytrotsko Mar 22, 2023
8b41263
Added Redis to ci.yaml. Added several more env variables for delphi_w…
dmytrotsko Mar 28, 2023
7a890b4
Merge branch 'api-keys' into api_key_v2
krivard Mar 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/delphi-epidata
/.mypy_cache
**/.mypy_cache
/.github
/docs
__pycache__
/node_modules
**/__pycache__
**/.pytest_cache
**/node_modules
20 changes: 5 additions & 15 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
FLASK_DEBUG=True
SQLALCHEMY_DATABASE_URI=sqlite:///test.db
FLASK_SECRET=abc
SECRET_TWITTER=abc
SECRET_GHT=abc
SECRET_FLUVIEW=abc
SECRET_CDC=abc
SECRET_SENSORS=abc
SECRET_SENSOR_TWTR=abc
SECRET_SENSOR_GFT=abc
SECRET_SENSOR_GHT=abc
SECRET_SENSOR_GHTJ=abc
SECRET_SENSOR_CDC=abc
SECRET_SENSOR_QUID=abc
SECRET_SENSOR_WIKI=abc
SECRET_QUIDEL=abc
SECRET_NOROSTAT=abc
SECRET_AFHSB=abc
#API_REQUIRED_STARTING_AT=2021-07-30
API_KEY_ADMIN_PASSWORD=abc
API_KEY_REGISTER_WEBHOOK_TOKEN=abc
RECAPTCHA_SITE_KEY
RECAPTCHA_SECRET_KEY
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
run: |
docker build -t delphi_database_epidata -f ./repos/delphi/delphi-epidata/dev/docker/database/epidata/Dockerfile .
docker build -t delphi_web_python -f repos/delphi/delphi-epidata/dev/docker/python/Dockerfile .
sudo docker build -t delphi_redis_instance -f repos/delphi/delphi-epidata/dev/docker/redis/Dockerfile .
cd ./repos/delphi/delphi-epidata
docker build -t delphi_web_epidata -f ./devops/Dockerfile .
cd ../../../
Expand All @@ -63,7 +64,8 @@ jobs:
run: |
docker network create --driver bridge delphi-net
docker run --rm -d -p 13306:3306 --network delphi-net --name delphi_database_epidata --cap-add=sys_nice delphi_database_epidata
docker run --rm -d -p 10080:80 --env "MODULE_NAME=delphi.epidata.server.main" --env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb://user:pass@delphi_database_epidata:3306/epidata" --env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --network delphi-net --name delphi_web_epidata delphi_web_epidata
docker run --rm -d -p 10080:80 --env "MODULE_NAME=delphi.epidata.server.main" --env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb://user:pass@delphi_database_epidata:3306/epidata" --env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --env "RATELIMIT_STORAGE_URL=redis://delphi_redis_instance:6379" --env "API_KEY_REGISTER_WEBHOOK_TOKEN=abc" --env "API_KEY_ADMIN_PASSWORD=test_admin_password" --network delphi-net --name delphi_web_epidata delphi_web_epidata
docker run --rm -p 6379:6379 --network delphi-net --name delphi_redis_instance delphi_redis_instance
docker ps

- run: |
Expand Down
1 change: 1 addition & 0 deletions dev/docker/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ WORKDIR /usr/src/app
COPY repos repos
COPY repos/delphi/delphi-epidata/dev/docker/python/setup.sh .


RUN ln -s -f /usr/share/zoneinfo/America/New_York /etc/localtime && \
chmod -R o+r repos/ && \
bash setup.sh && \
Expand Down
3 changes: 3 additions & 0 deletions dev/docker/redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM redis

CMD ["redis-server"]
1 change: 0 additions & 1 deletion devops/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ RUN ln -s -f /usr/share/zoneinfo/America/New_York /etc/localtime \
# the file /tmp/requirements.txt is created in the parent docker definition. (see:
# https://github.com/tiangolo/meinheld-gunicorn-docker/blob/master/docker-images/python3.8.dockerfile#L5 )
# this combined requirements installation ensures all version constrants are accounted for.

# disable python stdout buffering
ENV PYTHONUNBUFFERED 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setUp(self):

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Epidata.auth = ('epidata', 'key')

# use the local instance of the epidata database
secrets.db.host = 'delphi_database_epidata'
Expand All @@ -40,6 +41,8 @@ def setUp(self):
cur.execute('truncate table covid_hosp_facility')
cur.execute('truncate table covid_hosp_facility_key')
cur.execute('truncate table covid_hosp_meta')
cur.execute('delete from api_user')
cur.execute('insert into api_user(api_key, tracking, registered) values ("key", 1, 1)')

@freeze_time("2021-03-16")
def test_acquire_dataset(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def setUp(self):

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Epidata.auth = ('epidata', 'key')

# use the local instance of the epidata database
secrets.db.host = 'delphi_database_epidata'
Expand All @@ -43,6 +44,8 @@ def setUp(self):
with db.new_cursor() as cur:
cur.execute('truncate table covid_hosp_state_timeseries')
cur.execute('truncate table covid_hosp_meta')
cur.execute('delete from api_user')
cur.execute('insert into api_user(api_key, tracking, registered) values("key", 1, 1)')

@freeze_time("2021-03-16")
def test_acquire_dataset(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setUp(self):

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Epidata.auth = ('epidata', 'key')

# use the local instance of the epidata database
secrets.db.host = 'delphi_database_epidata'
Expand All @@ -39,6 +40,8 @@ def setUp(self):
with db.new_cursor() as cur:
cur.execute('truncate table covid_hosp_state_timeseries')
cur.execute('truncate table covid_hosp_meta')
cur.execute('delete from api_user')
cur.execute('insert into api_user(api_key, tracking, registered) values ("key", 1, 1)')

@freeze_time("2021-03-17")
def test_acquire_dataset(self):
Expand Down
18 changes: 10 additions & 8 deletions integrations/acquisition/covidcast/test_covidcast_meta_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,20 @@ def setUp(self):

# use the local instance of the Epidata API
Epidata.BASE_URL = BASE_URL
Epidata.auth = ('epidata', 'key')

def tearDown(self):
"""Perform per-test teardown."""
self.cur.close()
self.cnx.close()

@staticmethod
def _make_request():
params = {'endpoint': 'covidcast_meta', 'cached': 'true'}
response = requests.get(Epidata.BASE_URL, params=params, auth=Epidata.auth)
response.raise_for_status()
return response.json()

def test_caching(self):
"""Populate, query, cache, query, and verify the cache."""

Expand Down Expand Up @@ -147,10 +155,7 @@ def test_caching(self):
self.cnx.commit()

# fetch the cached version (manually)
params = {'endpoint': 'covidcast_meta', 'cached': 'true'}
response = requests.get(BASE_URL, params=params)
response.raise_for_status()
epidata4 = response.json()
epidata4 = self._make_request()

# make sure the cache was actually served
self.assertEqual(epidata4, {
Expand All @@ -170,10 +175,7 @@ def test_caching(self):
self.cnx.commit()

# fetch the cached version (manually)
params = {'endpoint': 'covidcast_meta', 'cached': 'true'}
response = requests.get(BASE_URL, params=params)
response.raise_for_status()
epidata5 = response.json()
epidata5 = self._make_request()

# make sure the cache was returned anyhow
self.assertEqual(epidata4, epidata5)
1 change: 1 addition & 0 deletions integrations/acquisition/covidcast/test_csv_uploading.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def setUp(self):

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Epidata.auth = ('epidata', 'key')

def tearDown(self):
"""Perform per-test teardown."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def setUp(self):
database='epidata')
cur = cnx.cursor()
cur.execute('truncate table covidcast_nowcast')
cur.execute('delete from api_user')
cur.execute('insert into api_user(api_key, tracking, registered) values ("key", 1, 1)')
cnx.commit()
cur.close()

Expand All @@ -54,6 +56,7 @@ def setUp(self):

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Epidata.auth = ('epidata', 'key')

def tearDown(self):
"""Perform per-test teardown."""
Expand Down
1 change: 1 addition & 0 deletions integrations/client/test_delphi_epidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def localSetUp(self):

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Epidata.auth = ('epidata', 'key')

# use the local instance of the epidata database
secrets.db.host = 'delphi_database_epidata'
Expand Down
3 changes: 3 additions & 0 deletions integrations/client/test_nowcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def setUp(self):
cur = cnx.cursor()

cur.execute('truncate table covidcast_nowcast')
cur.execute('delete from api_user')
cur.execute('insert into api_user(api_key, tracking, registered) values ("key", 1, 1)')

cnx.commit()
cur.close()
Expand All @@ -38,6 +40,7 @@ def setUp(self):

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Epidata.auth = ('epidata', 'key')

# use the local instance of the epidata database
secrets.db.host = 'delphi_database_epidata'
Expand Down
3 changes: 3 additions & 0 deletions integrations/server/test_covid_hosp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def setUp(self):

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Epidata.auth = ('epidata', 'key')

# use the local instance of the epidata database
secrets.db.host = 'delphi_database_epidata'
Expand All @@ -27,6 +28,8 @@ def setUp(self):
with db.new_cursor() as cur:
cur.execute('truncate table covid_hosp_state_timeseries')
cur.execute('truncate table covid_hosp_meta')
cur.execute('delete from api_user')
cur.execute('insert into api_user(api_key, tracking, registered) values ("key", 1, 1)')


def insert_issue(self, cur, issue, value, record_type):
Expand Down
7 changes: 3 additions & 4 deletions integrations/server/test_covidcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

# third party
import mysql.connector
import requests

# first party
from delphi_utils import Nans
from delphi.epidata.acquisition.covidcast.test_utils import CovidcastBase, CovidcastTestRow
from delphi.epidata.client.delphi_epidata import Epidata

# use the local instance of the Epidata API
BASE_URL = 'http://delphi_web_epidata/epidata/api.php'

class CovidcastTests(CovidcastBase):
"""Tests the `covidcast` endpoint."""
Expand All @@ -25,7 +22,9 @@ def localSetUp(self):

def request_based_on_row(self, row: CovidcastTestRow, **kwargs):
params = self.params_from_row(row, endpoint='covidcast', **kwargs)
Epidata.BASE_URL = BASE_URL
# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Epidata.auth = ('epidata', 'key')
response = Epidata.covidcast(**params)

return response
Expand Down
3 changes: 2 additions & 1 deletion integrations/server/test_covidcast_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# use the local instance of the Epidata API
BASE_URL = "http://delphi_web_epidata/epidata/covidcast"
BASE_URL_OLD = "http://delphi_web_epidata/epidata/api.php"
AUTH = ('epidata', 'key')


class CovidcastEndpointTests(CovidcastBase):
Expand All @@ -36,7 +37,7 @@ def _fetch(self, endpoint="/", is_compatibility=False, **params):
params.setdefault("data_source", params.get("source"))
else:
url = f"{BASE_URL}{endpoint}"
response = requests.get(url, params=params)
response = requests.get(url, params=params, auth=AUTH)
response.raise_for_status()
return response.json()

Expand Down
Loading