diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b7997f8..56bf34c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,20 @@ Changelog This is the changelog for Puppetboard. +0.1.2 +==== + +* Add configuration option to set the default environment, defaults to + 'production' (https://github.com/puppet-community/puppetboard/pull/185) +* Loading all available environments with every page load. (Issue: + https://github.com/puppet-community/puppetboard/issues/186) + +0.1.1 +==== + +* Fix bug where the reports template was not generating the report links + with the right environment + 0.1.0 ==== diff --git a/puppetboard/app.py b/puppetboard/app.py index cda415d..9b216d2 100644 --- a/puppetboard/app.py +++ b/puppetboard/app.py @@ -78,15 +78,13 @@ def environments(): return x -def check_env(env): +def check_env(env, envs): if env != '*' and env not in envs: abort(404) app.jinja_env.globals['url_for_pagination'] = url_for_pagination app.jinja_env.globals['url_for_environments'] = url_for_environments -envs = environments() - @app.context_processor def utility_processor(): def now(format='%m/%d/%Y %H:%M:%S'): @@ -97,16 +95,19 @@ def utility_processor(): @app.errorhandler(400) def bad_request(e): + envs = environments() return render_template('400.html', envs=envs), 400 @app.errorhandler(403) def forbidden(e): + envs = environments() return render_template('403.html', envs=envs), 400 @app.errorhandler(404) def not_found(e): + envs = environments() return render_template('404.html', envs=envs), 404 @@ -114,11 +115,13 @@ def not_found(e): def precond_failed(e): """We're slightly abusing 412 to handle missing features depending on the API version.""" + envs = environments() return render_template('412.html', envs=envs), 412 @app.errorhandler(500) def server_error(e): + envs = environments() return render_template('500.html', envs=envs), 500 @@ -131,7 +134,8 @@ def index(env): :param env: Search for nodes in this (Catalog and Fact) environment :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) # TODO: Would be great if we could parallelize this somehow, doing these # requests in sequence is rather pointless. @@ -214,7 +218,8 @@ def nodes(env): :param env: Search for nodes in this (Catalog and Fact) environment :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) if env == '*': query = None @@ -257,7 +262,8 @@ def inventory(env): :param env: Search for facts in this environment :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) fact_desc = [] # a list of fact descriptions to go # in the table header @@ -329,7 +335,8 @@ def node(env, node_name): :param env: Ensure that the node, facts and reports are in this environment :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) if env == '*': query = '["=", "certname", "{0}"]]'.format(node_name) @@ -382,7 +389,8 @@ def reports(env, page): and this value :type page: :obj:`int` """ - check_env(env) + envs = environments() + check_env(env, envs) if env == '*': reports_query = None @@ -446,7 +454,8 @@ def reports_node(env, node_name, page): and this value :type page: :obj:`int` """ - check_env(env) + envs = environments() + check_env(env, envs) if env == '*': query = '["=", "certname", "{0}"]]'.format(node_name) @@ -504,7 +513,8 @@ def report_latest(env, node_name): :param node_name: Find the reports whose certname match this value :type node_name: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) if env == '*': query='["and",' \ @@ -546,7 +556,8 @@ def report(env, node_name, report_id): report :type report_id: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) if env == '*': query = '["and", ["=", "certname", "{0}"],' \ @@ -583,7 +594,8 @@ def facts(env): sake :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) facts_dict = collections.defaultdict(list) facts = get_or_abort(puppetdb.fact_names) @@ -611,7 +623,8 @@ def fact(env, fact): :param fact: Find all facts with this name :type fact: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) # we can only consume the generator once, lists can be doubly consumed # om nom nom @@ -645,7 +658,8 @@ def fact_value(env, fact, value): :param value: Filter facts whose value is equal to this :type value: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) if env == '*': query = None @@ -678,7 +692,8 @@ def query(env): select field in the environment block :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) if app.config['ENABLE_QUERY']: form = QueryForm() @@ -714,7 +729,8 @@ def metrics(env): for the environments template block :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) metrics = get_or_abort(puppetdb._query, 'mbean') for key, value in metrics.items(): @@ -734,7 +750,8 @@ def metric(env, metric): for the environments template block :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) name = unquote(metric) metric = puppetdb.metric(metric) @@ -753,7 +770,8 @@ def catalogs(env): :param env: Find the nodes with this catalog_environment value :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) if app.config['ENABLE_CATALOG']: nodenames = [] @@ -808,7 +826,8 @@ def catalog_node(env, node_name): :param env: Find the catalog with this environment value :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) if app.config['ENABLE_CATALOG']: catalog = get_or_abort(puppetdb.catalog, @@ -833,7 +852,8 @@ def catalog_submit(env): catalogs page with the right environment. :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) if app.config['ENABLE_CATALOG']: form = CatalogForm(request.form) @@ -861,7 +881,8 @@ def catalog_compare(env, compare, against): :param env: Ensure that the 2 catalogs are in the same environment :type env: :obj:`string` """ - check_env(env) + envs = environments() + check_env(env, envs) if app.config['ENABLE_CATALOG']: compare_cat = get_or_abort(puppetdb.catalog,