Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #21 from dataware-tools/fix/env-var-meta-store-ser…
Browse files Browse the repository at this point in the history
…vice

Add feature to specify meta-store-service from environment variables
  • Loading branch information
d-hayashi authored Jun 30, 2021
2 parents c731e9a + ad8e674 commit 167cce1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ $ docker-compose up

```

## Environment variables
- `META_STORE_SERVICE`: URL of `api-meta-store`
- `PORT`: Port to run server on.
- `API_DEBUG`: Enable debug mode if true.


## Tips

### How to set directory to store uploaded files
Expand Down
9 changes: 2 additions & 7 deletions api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import responder
from dataware_tools_api_helper import get_forward_headers, get_jwt_payload_from_request

from api.settings import METASTORE_DEV_SERVICE, METASTORE_PROD_SERVICE, UPLOADED_FILE_PATH_PREFIX
from api.settings import META_STORE_SERVICE, UPLOADED_FILE_PATH_PREFIX
from api.utils import get_valid_filename, is_file_in_directory

# Metadata
Expand Down Expand Up @@ -370,11 +370,6 @@ def _update_metastore(
(Tuple[bool, dict]): True if the post request succeeds, False otherwise.
"""
if debug:
meta_service = METASTORE_DEV_SERVICE
else:
meta_service = METASTORE_PROD_SERVICE

try:
forward_header = get_forward_headers(req)
except AttributeError:
Expand All @@ -392,7 +387,7 @@ def _update_metastore(
**file_metadata
}
try:
res = requests.post(f'{meta_service}/databases/{database_id}/files',
res = requests.post(f'{META_STORE_SERVICE}/databases/{database_id}/files',
json=request_data, headers=headers)
except Exception:
return (False, res)
Expand Down
7 changes: 4 additions & 3 deletions api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
'opt',
'uploaded_data',
)
UPLOADED_FILE_PATH_PREFIX = os.environ.get('UPLOADED_FILE_PATH_PREFIX', default_uploaded_file_path_prefix)
UPLOADED_FILE_PATH_PREFIX = os.environ.get('UPLOADED_FILE_PATH_PREFIX',
default_uploaded_file_path_prefix)

METASTORE_DEV_SERVICE = 'https://dev.tools.hdwlab.com/api/latest/meta_store'
METASTORE_PROD_SERVICE = os.environ.get("METASTORE_PROD_SERVICE", 'https://dev.tools.hdwlab.com/api/latest/meta_store')
META_STORE_SERVICE = os.environ.get('META_STORE_SERVICE',
'https://demo.dataware-tools.com/api/latest/meta_store')
12 changes: 6 additions & 6 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import requests

from api import server
from api.settings import METASTORE_DEV_SERVICE, UPLOADED_FILE_PATH_PREFIX
from api.settings import META_STORE_SERVICE, UPLOADED_FILE_PATH_PREFIX

API_TOKEN = os.environ.get('API_TOKEN', None)
skip_if_token_unset = pytest.mark.skipif(
Expand All @@ -34,13 +34,13 @@ def setup_metastore_data():
database_id = 'database_for_testing_api_file_provider'
record_id = 'record_for_testing_api_file_provider'
# Add database
requests.post(url=f'{METASTORE_DEV_SERVICE}/databases', headers=AUTH_HEADERS, json={'database_id': database_id})
requests.post(url=f'{METASTORE_DEV_SERVICE}/records', headers=AUTH_HEADERS, json={'record_id': record_id})
requests.post(url=f'{META_STORE_SERVICE}/databases', headers=AUTH_HEADERS, json={'database_id': database_id})
requests.post(url=f'{META_STORE_SERVICE}/records', headers=AUTH_HEADERS, json={'record_id': record_id})
yield {'database_id': database_id, 'record_id': record_id}

# Finalizer
requests.delete(url=f'{METASTORE_DEV_SERVICE}/databases/{database_id}', headers=AUTH_HEADERS)
requests.delete(url=f'{METASTORE_DEV_SERVICE}/records/{record_id}', headers=AUTH_HEADERS)
requests.delete(url=f'{META_STORE_SERVICE}/databases/{database_id}', headers=AUTH_HEADERS)
requests.delete(url=f'{META_STORE_SERVICE}/records/{record_id}', headers=AUTH_HEADERS)


def delete_database_directory(database_id: str):
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_upload_201_metadata_updated_properly(api, setup_metastore_data):

# Check file metadata updated in meta-store
# TODO: Fix sub-string file_path based on base dir in pydtk
url = f'{METASTORE_DEV_SERVICE}/files/{quote(save_file_path)[1:]}'
url = f'{META_STORE_SERVICE}/files/{quote(save_file_path)[1:]}'
r = requests.get(url=url, params=params, headers=AUTH_HEADERS)
assert r.status_code == 200
data = json.loads(r.text)
Expand Down

0 comments on commit 167cce1

Please sign in to comment.