Changeset - 1cc95d998f7c
[Not reviewed]
0 3 0
Branko Majic (branko) - 21 months ago 2024-02-15 22:21:03
branko@majic.rs
MAR-197: Implement collapsible environment indicator for web server role.
3 files changed with 19 insertions and 8 deletions:
0 comments (0 inline, 0 general)
docs/rolereference.rst
Show inline comments
 
@@ -1440,30 +1440,31 @@ Depends on the following roles:
 
Parameters
 
~~~~~~~~~~
 

	
 
**default_https_tls_certificate** (string, mandatory)
 
  X.509 certificate used for TLS for HTTPS service. The file will be stored in
 
  directory ``/etc/ssl/certs/`` under name ``{{ ansible_fqdn }}_https.pem``.
 

	
 
**default_https_tls_key** (string, mandatory)
 
  Private key used for TLS for HTTPS service. The file will be stored in
 
  directory ``/etc/ssl/private/`` under name ``{{ ansible_fqdn }}_https.key``.
 

	
 
**environment_indicator** (dictionary, optional, ``null``)
 
  Specify configuration for including environment indicator on all HTML
 
  pages. Indicator is a simple strip at bottom of a page with custom background
 
  colour, text colour, and text.
 
  Specify configuration for including environment indicator on all
 
  HTML pages. Indicator is a simple strip at bottom of a page with
 
  custom background colour, text colour, and text. Indicator can be
 
  collapsed by clicking on the arrows on the left side of the strip.
 

	
 
  Specifying environment indicator is useful for avoiding mistakes when testing
 
  by having better visibility what environment you are in
 
  Specifying environment indicator is useful for avoiding mistakes
 
  when testing by having better visibility what environment you are in
 
  (production/staging/test).
 

	
 
  The following keys need to be specified:
 

	
 
  **background_colour** (string, mandatory)
 
    Background colour to use for the strip at bottom. This should be value
 
    compatible with CSS ``background-color`` attribute.
 

	
 
  **text_colour** (string, mandatory)
 
    Text colour to use for the strip at bottom. This should be value compatible
 
    with CSS ``color`` attribute.
 

	
roles/web_server/molecule/default/tests/test_optional.py
Show inline comments
 
@@ -65,15 +65,20 @@ def test_default_vhost_index_page(host):
 
    assert "<p>Welcome to default virtual host.</p>" in page.stdout
 

	
 

	
 
def test_environment_indicator(host):
 
    """
 
    Tests if environment indicator is applied correctly.
 
    """
 

	
 
    hostname = host.ansible.get_variables()['inventory_hostname']
 

	
 
    page = host.run('curl https://%s/' % hostname)
 

	
 
    expected_content = """
 
    <details open='true' style='width: 100%; line-height: 1.5em; font-weight: bold; color: #00ff00;'>
 
        <summary style='background-color: #ff0000; list-style-type: none; position: fixed; bottom: 5px; z-index: 999999;'>&#128896;&#128898;</summary>
 
        <div style='background-color: #ff0000; width: 100%; text-align: center; position: fixed; bottom: 5px; z-index: 999998;'>parameters-optional</div>
 
    </details>
 
"""
 
    assert page.rc == 0
 
    assert "<div id='website-environment' style='background-color: #ff0000; width: 100%; text-align: center; position: fixed; bottom: 5px; color: #00ff00; " \
 
        "font-weight: bold; z-index: 999999;'>parameters-optional</div></body>" in page.stdout
 
    assert expected_content in page.stdout
roles/web_server/templates/nginx-default.j2
Show inline comments
 
@@ -31,15 +31,20 @@ server {
 
    # Set server_name to something that won't be matched (for default server).
 
    server_name _;
 

	
 
    location / {
 
        # Always point user to the same index page.
 
        try_files $uri /index.html;
 
    }
 

	
 
    {% if environment_indicator -%}
 
    # Show environment indicator on HTML pages.
 
    sub_filter_types text/html;
 
    sub_filter_once on;
 
    sub_filter "</body>" "<div id='website-environment' style='background-color: {{ environment_indicator.background_colour }}; width: 100%; text-align: center; position: fixed; bottom: 5px; color: {{ environment_indicator.text_colour }}; font-weight: bold; z-index: 999999;'>{{ environment_indicator.text }}</div></body>";
 
    sub_filter "</body>" "
 
    <details open='true' style='position: fixed; left: 0; width: 100%; line-height: 1.5em; font-weight: bold; color: {{ environment_indicator.text_colour }};'>
 
        <summary style='background-color: {{ environment_indicator.background_colour }}; list-style-type: none; position: fixed; bottom: 5px; z-index: 999999;'>&#128896;&#128898;</summary>
 
        <div style='background-color: {{ environment_indicator.background_colour }}; width: 100%; text-align: center; position: fixed; bottom: 5px; z-index: 999998;'>{{ environment_indicator.text }}</div>
 
    </details>
 
";
 
    {% endif -%}
 
}
0 comments (0 inline, 0 general)