Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Add some config stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
vrde committed May 5, 2017
1 parent b0a5892 commit 4543c19
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
9 changes: 7 additions & 2 deletions .env_template
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ API_HOST=localhost
API_PORT=3000

# Settings for the BigchainDB node that the API server should connect to
BDB_NODE_HOST=
BDB_NODE_PORT=
OMI_ORG_NAME=
OMI_PUBLIC_KEY=
OMI_PRIVATE_KEY=
OMI_BDB_NODE_HOST=
OMI_BDB_NODE_PORT=
OMI_MDB_NODE_HOST=
OMI_MDB_NODE_PORT=

##### Docker settings #####
# Externally exposed port for accessing BigchainDB's API
Expand Down
23 changes: 21 additions & 2 deletions omi_api/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import os

import click
from bigchaindb_driver.crypto import generate_keypair

from omi_api.server import create_server


def main():
@click.group()
def cli():
pass


@cli.command()
def keypair():
keypair = generate_keypair()
click.echo(click.style('Copy paste those values in your env file:', fg='white'))
click.echo(click.style('OMI_PUBLIC_KEY={}'.format(keypair.public_key), fg='green'))
click.echo(click.style('OMI_PRIVATE_KEY={}'.format(keypair.private_key), fg='green'))



@cli.command()
def run():
# Double check in case the environment variable is sent via Docker,
# which will send empty strings for missing environment variables
hostname = os.environ.get('API_HOST', None)
Expand All @@ -27,4 +46,4 @@ def main():


if __name__ == '__main__':
main()
run()
17 changes: 17 additions & 0 deletions omi_api/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

def get(key, default):
# Double check in case the environment variable is sent via Docker,
# which will send empty strings for missing environment variables
value = os.environ.get(key)
if not value:
return default


ORG_NAME = get('OMI_ORG_NAME')
PUBLIC_KEY = get('OMI_PUBLIC_KEY')
PRIVATE_KEY = get('OMI_PRIVATE_KEY')
BDB_HOST = get('OMI_BDB_NODE_HOST', 'localhost')
BDB_PORT = get('OMI_BDB_NODE_PORT', '9984')
MDB_HOST = get('OMI_MDB_NODE_HOST', 'localhost')
MDB_PORT = get('OMI_MDB_NODE_PORT', '27017')
5 changes: 0 additions & 5 deletions omi_api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,3 @@ def create_server(settings):
app = create_app(settings)
standalone = StandaloneApplication(app, settings)
return standalone


if __name__ == '__main__':
from omi_api import cli
cli.main()
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
'flask>=0.11.1',
'flask-restful>=0.3.5',
'gunicorn>=19.6.0',
'flask-cors==3.0.2'
'flask-cors==3.0.2',
'colorama~=0.3.0'
]

tests_require = [
Expand Down Expand Up @@ -62,5 +63,5 @@
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
entry_points={'console_scripts': ['omi-http=omi_api.cli:main']}
entry_points={'console_scripts': ['omi-http=omi_api.cli:cli']}
)

0 comments on commit 4543c19

Please sign in to comment.