From e093ecd12eb8ec9ec72b450db53b6cf9e2fbb34f Mon Sep 17 00:00:00 2001 From: jortencio <87046872+jortencio@users.noreply.github.com> Date: Thu, 27 Jul 2023 10:22:28 +1000 Subject: [PATCH] Feature replace hash parameters (#20) * flatten postgresql parameters * Change the way config_sqlalchemy_database_uri is set in superset_config.py when module is managing postgres * Fix logic for setting config_sqlalchemy_database_uri * unwrap password * Flatten gunicorn config hash and add default values to parameters with missing defaults --- data/common.yaml | 35 ++++++------ manifests/init.pp | 92 +++++++++++++++++++++----------- manifests/postgresql.pp | 6 +-- manifests/service.pp | 11 +++- templates/superset_config.py.epp | 4 ++ 5 files changed, 95 insertions(+), 53 deletions(-) diff --git a/data/common.yaml b/data/common.yaml index cf9edcf..7ed6e97 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -3,7 +3,9 @@ lookup_options: superset::config_secret_key: convert_to: "Sensitive" superset::admin_password: - convert_to: "Sensitive" + convert_to: "Sensitive" + superset::pgsql_password: + convert_to: "Sensitive" superset::install_dir: "/home/superset" superset::version: '2.1.0' @@ -25,33 +27,30 @@ superset::admin_lastname: 'admin' superset::admin_email: 'admin@mycompany.com' # Default gunicorn as defined in Superset Documentation https://superset.apache.org/docs/installation/configuring-superset -superset::gunicorn_config: - install_dir: "%{lookup('superset::install_dir')}" - worker_class: "gevent" - workers: 10 - timeout: 120 - bind: "0.0.0.0:%{lookup('superset::port')}" - limit_request_line: 0 - limit_request_field_size: 0 - statsd_host: localhost:8125 +superset::gunicorn_install_dir: "/home/superset" +superset::gunicorn_worker_class: "gevent" +superset::gunicorn_workers: 10 +superset::gunicorn_timeout: 120 +superset::gunicorn_bind: "0.0.0.0:%{lookup('superset::port')}" +superset::gunicorn_limit_request_line: 0 +superset::gunicorn_limit_request_field_size: 0 +superset::gunicorn_statsd_host: localhost:8125 superset::manage_config: true superset::config_row_limit: ~ superset::config_webserver_port: "%{alias('superset::port')}" superset::config_secret_key: '53cR37K3y' -superset::config_sqlalchemy_database_uri: "postgresql://%{lookup('superset::pgsql_config.user')}:%{lookup('superset::pgsql_config.password')}@%{lookup('superset::pgsql_config.host')}:%{lookup('superset::pgsql_config.port')}/%{lookup('superset::pgsql_config.database')}" +superset::config_sqlalchemy_database_uri: ~ superset::config_wtf_csrf_enabled: ~ superset::config_wtf_csrf_exempt_list: ~ superset::config_wtf_csrf_time_limit: ~ superset::config_mapbox_api_key: ~ - -superset::pgsql_config: - database: 'superset' - user: 'superset' - password: 'password' - host: 'localhost' - port: 5432 +superset::pgsql_database: 'superset' +superset::pgsql_user: 'superset' +superset::pgsql_password: 'password' +superset::pgsql_host: 'localhost' +superset::pgsql_port: 5432 superset::python_version: 'python38' superset::python_pip: 'present' diff --git a/manifests/init.pp b/manifests/init.pp index 2487dab..6a29460 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -52,16 +52,29 @@ # @param admin_email # Parameter for setting the admin user email address # -# @param gunicorn_config -# Overide option for gunicorn. -# Default: -# - install_dir: "%{lookup('superset::install_dir')}" -# - workers: 10 -# - timeout: 120 -# - bind: "0.0.0.0:%{lookup('superset::port')}" -# - limit_request_line: 0 -# - limit_request_field_size: 0 -# - statsd_host: localhost:8125 +# @param gunicorn_install_dir +# Overide for gunicorn install_dir option. +# +# @param gunicorn_workers +# Overide for gunicorn workers option. +# +# @param gunicorn_worker_class +# Overide for gunicorn worker_class option. +# +# @param gunicorn_timeout +# Overide for gunicorn timeout option. +# +# @param gunicorn_bind +# Overide for gunicorn bind option. +# +# @param gunicorn_limit_request_line +# Overide for gunicorn limit_request_line option. +# +# @param gunicorn_limit_request_field_size +# Overide for gunicorn limit_request_field_size option. +# +# @param gunicorn_statsd_host +# Overide for gunicorn statsd_host option. # # @param manage_config # Boolean for setting whether to manage the config file superset_config.py @@ -90,14 +103,20 @@ # @param config_mapbox_api_key # Optional setting for setting MAPBOX_API_KEY in superset_config.py # -# @param pgsql_config -# Overide option for overiding the default postgresql configuration -# Available options include: -# - database -# - user -# - password -# - host -# - port +# @param pgsql_database +# Overide option for overiding the default postgresql database +# +# @param pgsql_user +# Overide option for overiding the default postgresql user +# +# @param pgsql_password +# Overide option for overiding the default postgresql password +# +# @param pgsql_host +# Overide option for overiding the default postgresql host +# +# @param pgsql_port +# Overide option for overiding the default postgresql port # # @param python_version # Overide option for setting the Python version if it will be managed by this module @@ -116,22 +135,29 @@ # # lint:ignore:parameter_order class superset ( - String $install_dir, - Variant[Enum['present','absent','latest'], String[1]] $version = 'present', + String $install_dir = '/home/superset', + Variant[Enum['present','absent','latest'], String[1]] $version = '2.1.0', Array[String] $additional_python_lib = [], - Integer $port, - String $user, - Boolean $load_examples, - Boolean $manage_python, - Boolean $manage_webserver, - Boolean $manage_db, - Boolean $manage_firewall, + Integer $port = 8088, + String $user = 'superset', + Boolean $load_examples = false, + Boolean $manage_python = true, + Boolean $manage_webserver = true, + Boolean $manage_db = true, + Boolean $manage_firewall = false, String $admin_username = 'admin', Sensitive[String] $admin_password = Sensitive('password'), String $admin_firstname = 'admin', String $admin_lastname = 'admin', String $admin_email = 'admin@mycompany.com', - Hash $gunicorn_config, + String $gunicorn_install_dir = '/home/superset', + String $gunicorn_worker_class = 'gevent', + Integer $gunicorn_workers = 10, + Integer $gunicorn_timeout = 120, + String $gunicorn_bind = '0.0.0.0:8088', + Integer $gunicorn_limit_request_line = 0, + Integer $gunicorn_limit_request_field_size = 0, + String $gunicorn_statsd_host = 'localhost:8125', Boolean $manage_config = true, Optional[Integer] $config_row_limit = undef, Optional[Integer] $config_webserver_port = undef, @@ -141,12 +167,16 @@ Optional[Array[String]] $config_wtf_csrf_exempt_list = undef, Optional[Integer] $config_wtf_csrf_time_limit = undef, Optional[String] $config_mapbox_api_key = undef, - Hash $pgsql_config, - String $python_version, + String $pgsql_database = 'superset', + String $pgsql_user = 'superset', + Sensitive[String] $pgsql_password = Sensitive('password'), + String $pgsql_host = 'localhost', + Integer $pgsql_port = 5432, + String $python_version = 'python38', Enum['present','absent','latest'] $python_pip = 'present', Enum['present','absent','latest'] $python_dev = 'present', Enum['present','absent','latest'] $python_venv = 'absent', - Array[String] $db_drivers, + Array[String] $db_drivers = ['psycopg2'], ) { # lint:endignore diff --git a/manifests/postgresql.pp b/manifests/postgresql.pp index 414ecb7..a5cac66 100644 --- a/manifests/postgresql.pp +++ b/manifests/postgresql.pp @@ -9,9 +9,9 @@ class { 'postgresql::server': } - postgresql::server::db { $superset::pgsql_config[database]: - user => $superset::pgsql_config[user], - password => postgresql::postgresql_password($superset::pgsql_config[user], $superset::pgsql_config[password]), + postgresql::server::db { $superset::pgsql_database: + user => $superset::pgsql_user, + password => postgresql::postgresql_password($superset::pgsql_user, $superset::pgsql_password.unwrap), } } } diff --git a/manifests/service.pp b/manifests/service.pp index bde3778..ed70a01 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -13,7 +13,16 @@ owner => $superset::user, group => $superset::user, mode => '0755', - content => epp('superset/superset.gunicorn.epp',$superset::gunicorn_config), + content => epp('superset/superset.gunicorn.epp', { + install_dir => $superset::gunicorn_install_dir, + workers => $superset::gunicorn_workers, + worker_class => $superset::gunicorn_worker_class, + bind => $superset::gunicorn_bind, + timeout => $superset::gunicorn_timeout, + limit_request_line => $superset::gunicorn_limit_request_line, + limit_request_field_size => $superset::gunicorn_limit_request_field_size, + statsd_host => $superset::gunicorn_statsd_host, + }), } file { '/usr/lib/systemd/system/superset.service': diff --git a/templates/superset_config.py.epp b/templates/superset_config.py.epp index b93e852..9024188 100644 --- a/templates/superset_config.py.epp +++ b/templates/superset_config.py.epp @@ -24,9 +24,13 @@ SECRET_KEY = <%= "\'${superset::config_secret_key}\'" %> # Note that the connection information to connect to the datasources # you want to explore are managed directly in the web UI # SQLALCHEMY_DATABASE_URI = 'sqlite:////path/to/superset.db' +<% if $superset::manage_db { -%> +SQLALCHEMY_DATABASE_URI = <%= "\'postgresql://${superset::pgsql_user}:${superset::pgsql_password.unwrap}@${superset::pgsql_host}:${superset::pgsql_port}/${superset::pgsql_database}\'" %> +<% } else { %> <% if $superset::config_sqlalchemy_database_uri { -%> SQLALCHEMY_DATABASE_URI = <%= "\'${superset::config_sqlalchemy_database_uri}\'" %> <% } %> +<% } %> # Flask-WTF flag for CSRF # WTF_CSRF_ENABLED = True