Clone the Repo to your machine
git clone https://github.com/hotosm/galaxy-api.git
Navigate to repo
cd galaxy-api
Install python dependencies
pip install -r requirements.txt
Run underpass from here OR Create database "underpass" in your local postgres and insert sample dump from /tests/src/fixtures/underpass.sql
Login to OSM , Click on My Settings and register your local galaxy app to Oauth2applications
Check on read user preferences and Enter redirect URI as following
http://127.0.0.1:8000/latest/auth/callback/
Grab Client ID and Client Secret and put it inside config.txt as OAUTH Block , you can generate secret key for your application by yourself
Insert your config blocks with the database credentials where you have underpass ,insight and tm in your database
[UNDERPASS]
host=localhost
user=postgres
password=admin
database=underpass
port=5432
[OAUTH]
client_id= your client id
client_secret= your client secret
url=https://www.openstreetmap.org
scope=read_prefs
login_redirect_uri=http://127.0.0.1:8000/latest/auth/callback/
secret_key=jnfdsjkfndsjkfnsdkjfnskfn
[API_CONFIG]
env=dev
You can further customize API if you wish with API_CONFIG Block
[API_CONFIG]
api_host=http://127.0.0.1 # you can define this if you have different host
api_port=8000
to use to for psycopg2 connections
log_level=info #options are info,debug,warning,error
env=dev # default is dev , supported values are dev and prod
Setup Tasking manager from here OR Create database "tm" in your local postgres and insert sample dump from TM test dump.
(wget https://raw.githubusercontent.com/hotosm/tasking-manager/develop/tests/database/tasking-manager.sql
)
psql -U postgres -h localhost tm < tasking-manager.sql
Add those block to config.txt with the value you use in the tasking manager configuration.
[TM]
host=localhost
user=postgres
password=admin
database=tm
port=5432
You can test it with the /mapathon/detail/
endpoint and with the following input:
{"fromTimestamp":"2019-04-08 10:00:00.000000","toTimestamp":"2019-04-08 11:00:00.000000","projectIds":[1],"hashtags":[]}
uvicorn API.main:app --reload
After sucessfully running server , hit this URL on your browser
http://127.0.0.1:8000/latest/docs
- Hit /auth/login/
- Hit Url returned on response
- You will get access_token
- You can use that access_token in all endpoints that requires authentication , To check token pass token in /auth/me/ It should return your osm profile
If you get a 401 response with the detail "User is not staff member", get your OSM id using https://galaxy-api.hotosm.org/v1/docs#/default/get_user_id_osm_users_ids__post, then run the following SQL on underpass database replacing ID:
INSERT INTO users_roles VALUES (ID, 1);
Repeat the steps to get a new access_token.
Galaxy-API uses pytest for tests ,Navigate to root Dir, Install package in editable mode
pip install -e .
Make sure you have postgresql installed locally with postgis extension enabled , Now Run Pytest
py.test -v -s
Run Individual tests
py.test -k test function name
python setup.py install
Now import as :
import galaxy
For database :
from galaxy import Database
For Mapathon :
from galaxy import Mapathon
When using New Relic, save the newrelic.ini to the root of the project and run the following to start the server:
NEW_RELIC_CONFIG_FILE=newrelic.ini $PATH_TO_BIN/newrelic-admin run-program $PATH_TO_BIN/uvicorn API.main:app
Galaxy API Uses Sphinx for it's technical documentation.
To Setup :
Navigate to docs Folder and Build .rst files first
cd docs
sphinx-apidoc -o source ../src/galaxy
sphinx-apidoc -o source ../API
Or you can export it in other supported formats by Sphinx
make html
All exported html files are inside build/html