Skip to content

API keys, local PR edition #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 260 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 178 commits
Commits
Show all changes
260 commits
Select commit Hold shift + click to select a range
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
96b4363
Build image from api-keys branch
korlaxxalrok Mar 22, 2023
0d81699
Updates TODO with issue
korlaxxalrok 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
717a189
Merge pull request #1061 from dmytrotsko/api_key_v2
krivard Mar 29, 2023
f3e331f
Added Redis to the Makefile
dmytrotsko Apr 12, 2023
719e52a
Changed ratelimit handling
dmytrotsko Apr 19, 2023
b8ac78c
Added default admin password, changed rate limit
dmytrotsko Apr 20, 2023
6164285
Merge pull request #1142 from dmytrotsko/api_key_v2
dmytrotsko Apr 20, 2023
57ff3ad
Updated ci.yaml
dmytrotsko Apr 20, 2023
fcd7794
Merge pull request #1143 from dmytrotsko/api_key_v2
dmytrotsko Apr 20, 2023
b3cbba5
Changed wrong redis host name
dmytrotsko Apr 20, 2023
38c8448
Merge pull request #1144 from dmytrotsko/api_key_v2
dmytrotsko Apr 20, 2023
8abf476
Added -d to redis container run command
dmytrotsko Apr 20, 2023
2fe9797
Merge pull request #1145 from dmytrotsko/api_key_v2
dmytrotsko Apr 20, 2023
2eb2d5d
Removed tailing colon
dmytrotsko Apr 20, 2023
39033f4
Merge pull request #1146 from dmytrotsko/api_key_v2
dmytrotsko Apr 20, 2023
2ff2616
Fixed get_multiples_count method
dmytrotsko Apr 21, 2023
87823ab
Merge pull request #1147 from dmytrotsko/api_key_v2
dmytrotsko Apr 21, 2023
2712c98
Temporary changed port
dmytrotsko Apr 21, 2023
c7f8a72
Merge pull request #1148 from dmytrotsko/api_key_v2
dmytrotsko Apr 21, 2023
1b1df1d
Added check container status step + check delphi_web_epidata logs. Mu…
dmytrotsko Apr 21, 2023
6e98968
Merge pull request #1149 from dmytrotsko/api_key_v2
dmytrotsko Apr 21, 2023
67594b9
Removed --rm flag from delphi_web_epidata run command
dmytrotsko Apr 21, 2023
2767bfb
Merge pull request #1150 from dmytrotsko/api_key_v2
dmytrotsko Apr 21, 2023
d4cfe43
Added check db logs step to ci.yaml
dmytrotsko Apr 21, 2023
70a893e
Added delphi_redis to clean up step
dmytrotsko Apr 21, 2023
3ac7da9
Reverted test changes
dmytrotsko Apr 21, 2023
8cac85e
Moved docker run delphi_web_epidata below wait command.
dmytrotsko Apr 21, 2023
0809371
Added name to run delphi_web_epidata step
dmytrotsko Apr 21, 2023
d8d10b0
Fixed issue with parsing allowed singals, removed unnecessary if/else…
dmytrotsko Apr 25, 2023
64700d2
Added Redis auth options (set default password)
dmytrotsko Apr 26, 2023
89a121e
adding dashboard signals module, plus requirements cleanup
melange396 Apr 26, 2023
5d19c51
updated _security.py:check_signals_allowlist() to use new DashboardSi…
melange396 Apr 27, 2023
28ac426
debugging w/ headers
melange396 Apr 27, 2023
048bdeb
better ip address logging and accounting
melange396 Apr 27, 2023
717edf9
Added admin folder to setup.cfg
dmytrotsko Apr 28, 2023
b8665bb
Upgraded Flask-Limiter version
dmytrotsko Apr 28, 2023
13c1a86
Moved Flask-Limiter code to a separate file. Made limit to be host ba…
dmytrotsko Apr 28, 2023
e0996c2
Little refactoring, replaced MissingAPIKey exception by Unauthorized
dmytrotsko Apr 28, 2023
c16ddfc
Fixed limits for allowed signals
dmytrotsko May 2, 2023
eadad38
Merge branch 'api-keys' into dashboard_signals_sync
dmytrotsko May 2, 2023
4bda66f
Merge pull request #1155 from cmu-delphi/dashboard_signals_sync
dmytrotsko May 2, 2023
f212adc
Added necessary changes
dmytrotsko May 2, 2023
894fca6
Removed redundant user variable
dmytrotsko May 3, 2023
faa50c7
Update dev/local/Makefile wrt redis log file
melange396 May 4, 2023
47dc13e
reset dev/docker/python/Dockerfile
melange396 May 4, 2023
5fb9541
remove unused import in src/server/main.py
melange396 May 4, 2023
ebfeccd
alpha-order argument keys in get_multiples_count()
melange396 May 4, 2023
2464416
Removed API Key registration form
dmytrotsko May 4, 2023
106908b
Removed recaptcha secrets from _config.py
dmytrotsko May 4, 2023
55500b0
Added 'stop container if running' and option to redis entry
dmytrotsko May 5, 2023
c8b82db
Moved Flask-Limiter belov Flask to keep everyting sorted properly
dmytrotsko May 5, 2023
d2e39fd
Added missing newline
dmytrotsko May 5, 2023
117b500
Added proper Epidata.auth handling for aiohttp ClientSession
dmytrotsko May 5, 2023
8398bcc
Added missing request arg for require_all()
dmytrotsko May 5, 2023
f2bf4b7
Merged api-keys related ddls into 1 file, added constraints
dmytrotsko May 5, 2023
b6b53f6
Removed tracking and registered fields
dmytrotsko May 5, 2023
8c671de
Removed usage of removed fields (tracking, registered). Added logging.
dmytrotsko May 5, 2023
864dc1e
Adjusted flask-limiter with comms
dmytrotsko May 5, 2023
95ce40d
Fixed tests
dmytrotsko May 5, 2023
b4e8030
Added templates folder
dmytrotsko May 5, 2023
34c453f
Removed _db.py and moved all needed code to the _common.py
dmytrotsko May 5, 2023
9538b8f
Exempted public routes from update_key_last_time_used function
dmytrotsko May 5, 2023
786ba3e
Removed redundant tracking, registered mentions. Added email field to…
dmytrotsko May 5, 2023
cf233ec
Imported engine from _common.py instead of _db.py which was removed
dmytrotsko May 5, 2023
d70afb9
Removed leftovers of the old code
dmytrotsko May 5, 2023
84f53af
Add auth support to delphi-epidata.R
krivard Mar 23, 2023
9663f9d
Bring auth in delphi-epidata.py in line with current policy
krivard Mar 23, 2023
d449611
Embetter json decoding error message
krivard May 5, 2023
111921e
Make user agent comply with spec; explain inactive R client endpoint …
krivard May 5, 2023
17a3707
Merge pull request #1113 from cmu-delphi/krivard/apikeys-clients
krivard May 5, 2023
6647e5f
Removed api_analytics table
dmytrotsko May 8, 2023
267adf6
Added 'window' param handling in multiples. Removed hostname from lim…
dmytrotsko May 8, 2023
46b0ee1
Added TODO to remove api keys warning messages
dmytrotsko May 8, 2023
c77837a
Added issue handling when API Key is provided but doesn't exist in da…
dmytrotsko May 8, 2023
2c3ad7b
Fix
dmytrotsko May 8, 2023
71fbf73
Changed limiter
dmytrotsko May 8, 2023
02c242d
made api key rollout phase determination more consistent
melange396 May 8, 2023
8e775a0
add comment about enable_admin() method
melange396 May 8, 2023
85c7f1d
api_user table: UNSIGNED ids, removed description comments, renamed l…
melange396 May 8, 2023
14753d6
move api_key argument logging, invalid api key check, and last key us…
melange396 May 8, 2023
d502a2d
missed import for _is_public_route
melange396 May 8, 2023
833d6fb
removed TESTING_MODE and fixed unused imports
melange396 May 8, 2023
4fa390c
refactored into _db.py to remove circular import dependencies
melange396 May 8, 2023
6153f55
import for werkzeug Unauthorized exception
melange396 May 8, 2023
fc04599
removed recaptcha references
melange396 May 8, 2023
e75d613
moved missing import from _common to _db
melange396 May 8, 2023
f3833a1
distinguish config-sourced 'user roles' from db-based
melange396 May 8, 2023
a56ed19
logging additions, including experimental stuff
melange396 May 8, 2023
3501ab3
logging level change
melange396 May 8, 2023
a79c253
user object debugging during the api request/response flow
melange396 May 9, 2023
45b7f2d
fix logging case when there is no 'User'
melange396 May 9, 2023
b0cf9a7
Muted non-existing api key check
dmytrotsko May 9, 2023
c50e6a7
Formatting, added AUTH
dmytrotsko May 9, 2023
133507a
Added 'old' endpoints auth logic
dmytrotsko May 9, 2023
64eb673
Added email/api key duplicate check
dmytrotsko May 9, 2023
7f57790
remove un-slashed app route
melange396 May 9, 2023
ff558a5
change url (route) prefix to be empty instead of a bare slash
melange396 May 9, 2023
86ee097
API Keys: API Documentation (#1158)
krivard May 9, 2023
844f87f
Merge branch 'api-keys' of github.com:cmu-delphi/delphi-epidata into …
dmytrotsko May 10, 2023
e98c653
Unmuted api_key validation
dmytrotsko May 11, 2023
025feca
Removed AUTH, added TEMPORARY_API_KEY and REGISTRATION_FORM_LINK
dmytrotsko May 11, 2023
0c7d71e
Added requests_left() function to check user's remaining requests and…
dmytrotsko May 11, 2023
be0ca26
Removed old authentication, updated warning messages
dmytrotsko May 11, 2023
868d728
Added limit exceed, multiple exceed, temporary key messages to the pr…
dmytrotsko May 11, 2023
6b61aab
Fixed fluview endpoint authentication
dmytrotsko May 11, 2023
851eb10
Fluview endpoint hotfix
dmytrotsko May 11, 2023
964afd6
Added ratelimit headers to the response
dmytrotsko May 12, 2023
81e0eb9
Adjusted limiter warning messages(Messages text taken from PR#1163). …
dmytrotsko May 12, 2023
c4e17b3
Update _security.py -- checks for all 4 phases
melange396 May 15, 2023
72cf10a
solidified rate limit filter behavior
melange396 May 15, 2023
4069412
Fixed user update. Removed api_key check on phase 1
dmytrotsko May 16, 2023
ee7afdb
Added handling for data_source&signal pairs
dmytrotsko May 17, 2023
9f3d166
Fixed order of warnings
dmytrotsko May 17, 2023
c9734db
Fixed printer message
dmytrotsko May 17, 2023
069cbbd
logging changes, including rows returned and api user db CrUD operations
melange396 May 17, 2023
4d39e96
Printer messages hotfix
dmytrotsko May 17, 2023
b1e0a0e
Fixed printer warnings
dmytrotsko May 18, 2023
6cb9b47
Hotfix
dmytrotsko May 18, 2023
d29f9f4
_printer hotfix
dmytrotsko May 18, 2023
c0491bd
Fix _printer
dmytrotsko May 18, 2023
c4b1a01
reduced usages of flask.g, improved usages of _get_current_user() / c…
melange396 May 19, 2023
f91cee9
update api-keys config variables with now-announced values
melange396 May 19, 2023
cee1f39
took roles out of config (its in db now), simplified role checking in…
melange396 May 19, 2023
09c7b94
logging cleanup
melange396 May 22, 2023
fcc1f4b
force named arguments
melange396 May 22, 2023
262b391
update api-keys registration and removal links
melange396 May 22, 2023
bc3aeb3
added local redirects for gForms for registration and user deletion, …
melange396 May 22, 2023
1e35a09
fix typo in import statement
melange396 May 22, 2023
581c4d3
update api-key error messages to use local redirect to registration form
melange396 May 22, 2023
0bda3a8
fix 'multiples' detection so it recognizes date ranges as well
melange396 May 22, 2023
a01d894
fix 'multiples' detection, cant do instance checks w/ subscripted gen…
melange396 May 22, 2023
806b6b2
fix 'multiples' detection, check for list instead of Sequence)
melange396 May 22, 2023
51b0ac4
Text check for rollout (#1171)
krivard May 22, 2023
4fb920f
Fixed expired session by using new session for each User operation
dmytrotsko May 23, 2023
a62e40f
merging `dev` brach changes into `api-keys`
melange396 May 23, 2023
0bf9635
Fix environment variable and 429 output method
krivard May 22, 2023
fc21650
Propagate API key rollout env variable namechange to .env template
krivard May 23, 2023
4cb2fbc
updated docs to local forwards for google forms links
melange396 May 23, 2023
3b7a457
adding key request form script
melange396 May 23, 2023
94cea20
fix user_id logging (logged user w/ email before, which was removed c…
melange396 May 23, 2023
6f6e813
fixed scope for db_user
melange396 May 23, 2023
2a7c26d
orm/user debugging
melange396 May 23, 2023
56caf92
grrr stupid typo
melange396 May 23, 2023
b80a225
more user/role debugging
melange396 May 23, 2023
0624c72
Update usage text in src/server/admin/api_key_form_script.js
melange396 May 23, 2023
cc08722
cleaning up...
melange396 May 23, 2023
80514c1
changing sqlalchemy logging to match levels in dev
melange396 May 23, 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
18 changes: 13 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,31 @@ 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 -f repos/delphi/delphi-epidata/dev/docker/redis/Dockerfile .
cd ./repos/delphi/delphi-epidata
docker build -t delphi_web_epidata -f ./devops/Dockerfile .
cd ../../../

# MODULE_NAME specifies the location of the `app` variable, the actual WSGI application object to run.
# see https://github.com/tiangolo/meinheld-gunicorn-docker#module_name
- name: Start services
- name: Start database and Redis services
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 ps
docker run --rm -d -p 6379:6379 --network delphi-net --env "REDIS_PASSWORD=1234" --name delphi_redis delphi_redis


- run: |
wget https://raw.githubusercontent.com/eficode/wait-for/master/wait-for
chmod +x wait-for
./wait-for localhost:13306 -- echo 'ready'
sleep 10s

- name: Start delphi_web_epidata
run: |
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 "REDIS_HOST=delphi_redis" --env "REDIS_PASSWORD=1234" --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 ps

- name: Run Unit Tests
run: |
docker run --rm --network delphi-net --env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb://user:pass@delphi_database_epidata:3306/epidata" --env "FLASK_SECRET=abc" delphi_web_python python -m pytest --import-mode importlib repos/delphi/delphi-epidata/tests
Expand All @@ -81,7 +88,7 @@ jobs:

- name: Clean Up
run: |
docker stop delphi_database_epidata delphi_web_epidata
docker stop delphi_database_epidata delphi_web_epidata delphi_redis
docker network remove delphi-net

build_js_client:
Expand All @@ -108,7 +115,8 @@ jobs:
image:
needs: build
# only on main and dev branch
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
# TODO: #1112 Remove `|| github.ref == 'refs/heads/api-keys'` after transition to production status.
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/api-keys'

runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 5 additions & 0 deletions dev/docker/redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM redis

ENV REDIS_PASSWORD=$REDIS_PASSWORD

CMD ["sh", "-c", "exec redis-server --requirepass \"$REDIS_PASSWORD\""]
25 changes: 24 additions & 1 deletion dev/local/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ CWD:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
NOW:=$(shell date "+%Y-%m-%d")
LOG_WEB:=delphi_web_epidata_$(NOW).log
LOG_DB:=delphi_database_epidata_$(NOW).log
LOG_REDIS:=delphi_redis_instance_$(NOW).log
WEB_CONTAINER_ID:=$(shell docker ps -q --filter 'name=delphi_web_epidata')
DATABASE_CONTAINER_ID:=$(shell docker ps -q --filter 'name=delphi_database_epidata')
REDIS_CONTAINER_ID:=$(shell docker ps -q --filter 'name=delphi_redis')

M1=
ifeq ($(shell uname -smp), Darwin arm64 arm)
Expand Down Expand Up @@ -98,6 +100,10 @@ web:
--env "MODULE_NAME=delphi.epidata.server.main" \
--env "SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri)" \
--env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --env "LOG_DEBUG" \
--env "REDIS_HOST=delphi_redis" \
--env "REDIS_PASSWORD=1234" \
--env "API_KEY_ADMIN_PASSWORD=test_admin_password" \
--env "API_KEY_REGISTER_WEBHOOK_TOKEN=abc" \
--network delphi-net --name delphi_web_epidata \
delphi_web_epidata >$(LOG_WEB) 2>&1 &

Expand Down Expand Up @@ -136,8 +142,25 @@ py:
$(M1) \
-f repos/delphi/delphi-epidata/dev/docker/python/Dockerfile .

.PHONY=redis
redis:
@# Stop container if running
@if [ $(REDIS_CONTAINER_ID) ]; then\
docker stop $(REDIS_CONTAINER_ID);\
fi

@docker build -t delphi_redis \
$(M1) \
-f repos/delphi/delphi-epidata/dev/docker/redis/Dockerfile .

@docker run --rm -d -p 127.0.0.1:6379:6379 \
$(M1) \
--network delphi-net \
--env "REDIS_PASSWORD=1234" \
--name delphi_redis delphi_redis >$(LOG_REDIS) 2>&1 &

.PHONY=all
all: db web py
all: db web py redis

.PHONY=test
test:
Expand Down
2 changes: 2 additions & 0 deletions dev/local/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ packages =
delphi.epidata.acquisition.wiki
delphi.epidata.client
delphi.epidata.server
delphi.epidata.server.admin
delphi.epidata.server.admin.templates
delphi.epidata.server.covidcast_issues_migration
delphi.epidata.server.endpoints
delphi.epidata.server.endpoints.covidcast_utils
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, email) values ("key", "emai")')

@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, email) values("key", "email")')

@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, email) values ("key", "email")')

@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, email) values ("key", "email")')
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, email) values ("key", "email")')

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, email) values ("key", "email")')


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