Skip to content

Commit

Permalink
Feature replace hash parameters (#20)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jortencio authored Jul 27, 2023
1 parent a4ca78f commit e093ecd
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 53 deletions.
35 changes: 17 additions & 18 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -25,33 +27,30 @@ superset::admin_lastname: 'admin'
superset::admin_email: '[email protected]'

# 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'
Expand Down
92 changes: 61 additions & 31 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 = '[email protected]',
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,
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions manifests/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
11 changes: 10 additions & 1 deletion manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
4 changes: 4 additions & 0 deletions templates/superset_config.py.epp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e093ecd

Please sign in to comment.