Commit 45736680 authored by Daniel Dehennin's avatar Daniel Dehennin

feat(setup): create users from salt configuration

By default, a password reset email is sent to the user.
parent 47122a24
......@@ -8,3 +8,4 @@ include:
- .sources
- .config
- .service
- .setup
......@@ -17,6 +17,7 @@ values:
# letsencrypt:
# enabled: true
# account_email: 'me@example.net'
# users: {}
launcher:
rebuild_cmd: './launcher rebuild app'
bootstrap_cmd: './launcher bootstrap app'
......@@ -25,4 +26,5 @@ values:
restart_cmd: './launcher restart app'
cleanup_cmd: './launcher cleanup app'
destroy_cmd: './launcher destroy app'
run_cmd: 'docker exec app /bin/bash -c'
...
# -*- coding: utf-8 -*-
# vim: ft=sls
include:
- .users
# -*- coding: utf-8 -*-
# vim: ft=sls
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_service_running = tplroot ~ '.service.running' %}
{%- from tplroot | path_join("map.jinja") import discourse with context %}
include:
- {{ sls_service_running }}
{%- for user, params in discourse.get('users', {}).items() %}
{%- set email = params.get('email', '') %}
{%- set password = params.get('password', '') %}
{%- set enabled = params.get('enabled', 'True') %}
{%- set is_admin = params.get('admin', 'False') %}
{%- set create_user_cmd = 'cd /var/www/discourse/ && rake autosetup:createuser['
~ '"' ~ email ~ '"'
~ ',"' ~ password ~ '"'
~ ',"' ~ enabled ~ '"'
~ ',"' ~ is_admin ~ '"'
~ ']'
%}
discourse-setup-users-create-{{ user }}-cmd-run:
cmd.run:
- name: {{ discourse | traverse('launcher:run_cmd')
~ " '"
~ create_user_cmd
~ "'"
}}
- cwd: {{ discourse.directory }}
- require:
- sls: {{ sls_service_running }}
{%- endfor %}
# -*- coding: utf-8 -*-
# vim: ft=sls
include:
- .create
......@@ -62,6 +62,24 @@ It depends on ``discourse.sources.hack``.
This state will rebuild the ``discourse`` application container if the
``discourse.config`` has changes.
``discourse.setup``
^^^^^^^^^^^^^^^^^^^
*Meta-state (This is a state that includes other states)*.
This state will initialize the ``discourse`` application with sane
defaults.
``discourse.setup.users``
^^^^^^^^^^^^^^^^^^^^^^^^^
This state will manage a set of users:
- create them if they don't exists
- send password reset email by default or set their password if defined
- set them active or not
- set them ``admin`` or not.
``discourse.clean``
^^^^^^^^^^^^^^^^^^^
......
......@@ -14,6 +14,12 @@ discourse:
letsencrypt:
enabled: true
account_email: 'me@example.net'
users:
william:
# Password reset mail is sent by default
email: 'william.shakespears@example.net'
enabled: true
admin: true
tofs:
# The files_switch key serves as a selector for alternative
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment