diff --git a/docs/quickstart/index.rst b/docs/quickstart/index.rst index f291ba8c..2e39a645 100644 --- a/docs/quickstart/index.rst +++ b/docs/quickstart/index.rst @@ -100,6 +100,10 @@ used by Lemur to help associate certificates that do not currently have an owner Lemur has discovered certificates from a third party resource. This is also a default user that can be used to administer Lemur. +.. code-block:: bash + + $ lemur db init + .. code-block:: bash $ lemur init diff --git a/lemur/__init__.py b/lemur/__init__.py index 3eb69e3b..39432438 100644 --- a/lemur/__init__.py +++ b/lemur/__init__.py @@ -62,8 +62,3 @@ def configure_hook(app): response.status_code = 403 return response - - - - - diff --git a/lemur/default.conf.py b/lemur/default.conf.py new file mode 100644 index 00000000..1ca0cc72 --- /dev/null +++ b/lemur/default.conf.py @@ -0,0 +1,24 @@ +# This is just Python which means you can inherit and tweak settings + +import os +_basedir = os.path.abspath(os.path.dirname(__file__)) + +ADMINS = frozenset(['']) + +THREADS_PER_PAGE = 8 + +############# +## General ## +############# + +# These will need to be set to `True` if you are developing locally +CORS = False +debug = False + +############# +## Logging ## +############# + +LOG_LEVEL = "DEBUG" +LOG_FILE = "lemur.log" + diff --git a/lemur/factory.py b/lemur/factory.py index 9730ebaa..63d4f428 100644 --- a/lemur/factory.py +++ b/lemur/factory.py @@ -94,11 +94,10 @@ def configure_app(app, config=None): except RuntimeError: if config and config != 'None': app.config.from_object(from_file(config)) - else: + elif os.path.isfile(os.path.expanduser("~/.lemur/lemur.conf.py")): app.config.from_object(from_file(os.path.expanduser("~/.lemur/lemur.conf.py"))) - - if not app.config.get('ENCRYPTION_KEY'): - raise NoEncryptionKeyFound + else: + app.config.from_object(from_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'default.conf.py'))) def configure_extensions(app): diff --git a/lemur/manage.py b/lemur/manage.py old mode 100644 new mode 100755 index 4c54ebe4..1680ed2f --- a/lemur/manage.py +++ b/lemur/manage.py @@ -333,14 +333,15 @@ class InitializeApp(Command): else: sys.stdout.write("[-] Default user has already been created, skipping...!\n") - for account_name, account_number in current_app.config.get('AWS_ACCOUNT_MAPPINGS').items(): - account = account_service.get_by_account_number(account_number) + if current_app.config.get('AWS_ACCOUNT_MAPPINGS'): + for account_name, account_number in current_app.config.get('AWS_ACCOUNT_MAPPINGS').items(): + account = account_service.get_by_account_number(account_number) - if not account: - account_service.create(account_number, label=account_name) - sys.stdout.write("[+] Added new account {0}:{1}!\n".format(account_number, account_name)) - else: - sys.stdout.write("[-] Account already exists, skipping...!\n") + if not account: + account_service.create(account_number, label=account_name) + sys.stdout.write("[+] Added new account {0}:{1}!\n".format(account_number, account_name)) + else: + sys.stdout.write("[-] Account already exists, skipping...!\n") sys.stdout.write("[/] Done!\n") @@ -439,26 +440,6 @@ class CreateRole(Command): sys.stdout.write("[+] Created new role: {0}".format(name)) -@manager.command -def create_config(config_path=None): - """ - Creates a new configuration file if one does not already exist - """ - if not config_path: - config_path = DEFAULT_CONFIG_PATH - - config_path = os.path.expanduser(config_path) - dir = os.path.dirname(config_path) - if not os.path.exists(dir): - os.makedirs(dir) - - config = generate_settings() - with open(config_path, 'w') as f: - f.write(config) - - sys.stdout.write("Created a new configuration file {0}\n".format(config_path)) - - class LemurServer(Command): """ This is the main Lemur server, it runs the flask app with gunicorn and @@ -494,6 +475,26 @@ class LemurServer(Command): return app.run() +@manager.command +def create_config(config_path=None): + """ + Creates a new configuration file if one does not already exist + """ + if not config_path: + config_path = DEFAULT_CONFIG_PATH + + config_path = os.path.expanduser(config_path) + dir = os.path.dirname(config_path) + if not os.path.exists(dir): + os.makedirs(dir) + + config = generate_settings() + with open(config_path, 'w') as f: + f.write(config) + + sys.stdout.write("Created a new configuration file {0}\n".format(config_path)) + + def main(): manager.add_command("start", LemurServer()) manager.add_command("runserver", Server(host='127.0.0.1')) @@ -505,3 +506,7 @@ def main(): manager.add_command('create_role', CreateRole()) manager.add_command("sync", Sync()) manager.run() + + +if __name__ == "__main__": + main()