-
Notifications
You must be signed in to change notification settings - Fork 6
/
dss-api
executable file
·50 lines (41 loc) · 1.95 KB
/
dss-api
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
"""
Entry point for starting a local test HCA DSS API server.
"""
import os
import sys
import logging
import argparse
from chalice.cli import CLIFactory, run_local_server
import dss
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", default="")
parser.add_argument("--port", type=int, default=5000)
parser.add_argument("--no-debug", dest="debug", action="store_false",
help="Disable Chalice/Connexion/Flask debug mode")
parser.add_argument("--project-dir", help=argparse.SUPPRESS,
default=os.path.join(os.path.dirname(__file__), "chalice"))
parser.add_argument("--log-level",
help=str([logging.getLevelName(i) for i in range(0, 60, 10)]),
choices={logging.getLevelName(i) for i in range(0, 60, 10)},
default=logging.DEBUG)
args = parser.parse_args()
if "DSS_HOME" not in os.environ:
parser.exit('Please run "source environment" in the data-store repo root directory')
logging.basicConfig(level=args.log_level, stream=sys.stderr)
factory = CLIFactory(project_dir=args.project_dir, debug=args.debug)
# The following code snippet is basically stolen from chalice/__init__py:run_local_server
config = factory.create_config_obj(
chalice_stage_name=os.environ["DSS_DEPLOYMENT_STAGE"]
)
app_obj = factory.load_chalice_app()
# When running `chalice local`, a stdout logger is configured
# so you'll see the same stdout logging as you would when
# running in lambda. This is configuring the root logger.
# The app-specific logger (app.log) will still continue
# to work.
# FIXME: (hannes) I don't think this works. basicConfig() only does anything if there aren't any handlers, so a second
# invocation is usually pointless unless something removed all handlers in between.
logging.basicConfig(stream=sys.stdout)
server = factory.create_local_server(app_obj=app_obj, config=config, host=args.host, port=args.port)
server.serve_forever()