From 5c9bcc5c23eb64cc0e96eedbd126037369862fc5 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Thu, 2 Jul 2015 12:50:03 -0700 Subject: [PATCH 1/6] Ensuring that we are looking for LEMUR_ENCRYPTION_KEY configuration variable and not ENCRYPTION_KEY configuration variable. --- lemur/factory.py | 4 ++-- lemur/manage.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 lemur/manage.py diff --git a/lemur/factory.py b/lemur/factory.py index 520ee977..42afb32d 100644 --- a/lemur/factory.py +++ b/lemur/factory.py @@ -84,14 +84,14 @@ def configure_app(app, config=None): :return: """ try: - app.config.from_envvar("LEMUR_SETTINGS") + app.config.from_envvar("LEMUR_CONF") except RuntimeError: if config and config != 'None': app.config.from_object(from_file(config)) else: app.config.from_object(from_file(os.path.expanduser("~/.lemur/lemur.conf.py"))) - if not app.config.get('ENCRYPTION_KEY'): + if not app.config.get('LEMUR_ENCRYPTION_KEY'): raise NoEncryptionKeyFound diff --git a/lemur/manage.py b/lemur/manage.py old mode 100644 new mode 100755 index 4c54ebe4..5afa71c8 --- a/lemur/manage.py +++ b/lemur/manage.py @@ -494,7 +494,7 @@ class LemurServer(Command): return app.run() -def main(): +if __name__ == "__main__": manager.add_command("start", LemurServer()) manager.add_command("runserver", Server(host='127.0.0.1')) manager.add_command("clean", Clean()) From fc18e0f2bfcbd92b251abf9e1937639319aa1511 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Thu, 2 Jul 2015 13:49:31 -0700 Subject: [PATCH 2/6] Making the creation of AWS accounts optional. --- lemur/manage.py | 55 +++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/lemur/manage.py b/lemur/manage.py index 5afa71c8..c87543da 100755 --- 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.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)) + + if __name__ == "__main__": manager.add_command("start", LemurServer()) manager.add_command("runserver", Server(host='127.0.0.1')) From 2856d13a4e137d0962d4b6288d2d8cccf802dc7b Mon Sep 17 00:00:00 2001 From: kevgliss Date: Thu, 2 Jul 2015 13:51:52 -0700 Subject: [PATCH 3/6] Making docs more clear on steps to get database installed. --- docs/quickstart/index.rst | 4 ++++ 1 file changed, 4 insertions(+) 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 From eadfaaeed0b24cdf442369c1d70f30d681815084 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Thu, 2 Jul 2015 14:12:39 -0700 Subject: [PATCH 4/6] Fixing an issue you couldn't create a configuration because one did not yet exist. --- lemur/__init__.py | 5 ----- lemur/default.conf.py | 24 ++++++++++++++++++++++++ lemur/factory.py | 6 +++--- lemur/manage.py | 6 +++++- 4 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 lemur/default.conf.py diff --git a/lemur/__init__.py b/lemur/__init__.py index 388914bd..015ad459 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 42afb32d..e0470ae2 100644 --- a/lemur/factory.py +++ b/lemur/factory.py @@ -88,11 +88,11 @@ 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"))) + else: + app.config.from_object(from_file(os.path.join(os.getcwd(), 'default.conf.py'))) - if not app.config.get('LEMUR_ENCRYPTION_KEY'): - raise NoEncryptionKeyFound def configure_extensions(app): diff --git a/lemur/manage.py b/lemur/manage.py index c87543da..2f4aee15 100755 --- a/lemur/manage.py +++ b/lemur/manage.py @@ -495,7 +495,7 @@ def create_config(config_path=None): sys.stdout.write("Created a new configuration file {0}\n".format(config_path)) -if __name__ == "__main__": +def main(): manager.add_command("start", LemurServer()) manager.add_command("runserver", Server(host='127.0.0.1')) manager.add_command("clean", Clean()) @@ -506,3 +506,7 @@ if __name__ == "__main__": manager.add_command('create_role', CreateRole()) manager.add_command("sync", Sync()) manager.run() + + +if __name__ == "__main__": + main() From 277599f0e558a6bb01cb40fab54d339d5360b05c Mon Sep 17 00:00:00 2001 From: kevgliss Date: Sat, 4 Jul 2015 12:50:41 -0700 Subject: [PATCH 5/6] fixing an a small typo --- lemur/manage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lemur/manage.py b/lemur/manage.py index 2f4aee15..1680ed2f 100755 --- a/lemur/manage.py +++ b/lemur/manage.py @@ -333,7 +333,7 @@ class InitializeApp(Command): else: sys.stdout.write("[-] Default user has already been created, skipping...!\n") - if current_app.app.config.get('AWS_ACCOUNT_MAPPINGS'): + 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) From b04fb471e9fb80efb871c9582ac21472d0cd135f Mon Sep 17 00:00:00 2001 From: kevgliss Date: Sat, 4 Jul 2015 12:55:28 -0700 Subject: [PATCH 6/6] Ensuring that path to to the default config is correct regardless of how the app was started. --- lemur/factory.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lemur/factory.py b/lemur/factory.py index e0470ae2..7dcb25b1 100644 --- a/lemur/factory.py +++ b/lemur/factory.py @@ -91,8 +91,7 @@ def configure_app(app, config=None): elif os.path.isfile(os.path.expanduser("~/.lemur/lemur.conf.py")): app.config.from_object(from_file(os.path.expanduser("~/.lemur/lemur.conf.py"))) else: - app.config.from_object(from_file(os.path.join(os.getcwd(), 'default.conf.py'))) - + app.config.from_object(from_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'default.conf.py'))) def configure_extensions(app):