Commit 09b44b96 authored by Vincent Pelletier's avatar Vincent Pelletier

erp5.mariadb: Make user and password optional.

Allow creating databases without associated user account.
Do not document this, as it is part of a yet-incomplete feature.
parent e5325b93
......@@ -177,7 +177,7 @@ context =
[template-mariadb]
< = download-base
filename = instance-mariadb.cfg.in
md5sum = 087e92559489e1c77a3a1ace613a6bf5
md5sum = 7e9ec4e0d52e48bd03303a9d9f16627a
link-binary =
${coreutils:location}/bin/basename
${coreutils:location}/bin/cat
......@@ -213,7 +213,7 @@ md5sum = dd779e54d22105702aa72cadc994d957
[template-mariadb-initial-setup]
< = download-base
filename = mariadb_initial_setup.sql.in
md5sum = 564006953b7d7a12d40a14b6648b32f0
md5sum = b8d2d9af0c4cab45c8337aeac28d5fae
[template-create-erp5-site]
< = download-base
......
......@@ -22,7 +22,11 @@ recipe = slapos.cookbook:publish.serialised
{% macro render_database_list(database_list) -%}
{% set publish_database_list = [] -%}
{% for database in database_list -%}
{% if database.get('user') -%}
{% do publish_database_list.append("mysql://" ~ database['user'] ~ ":" ~ database['password'] ~ "@" ~ ip ~ ":" ~ port ~ "/" ~ database['name']) -%}
{%- else -%}
{% do publish_database_list.append("mysql://" ~ ip ~ ":" ~ port ~ "/" ~ database['name']) -%}
{%- endif %}
{% endfor -%}
{{ dumps(publish_database_list) }}
{% endmacro -%}
......
......@@ -7,10 +7,12 @@ DROP FUNCTION IF EXISTS sphinx_snippets;
{% macro database(name, user, password) -%}
CREATE DATABASE IF NOT EXISTS {{ name }};
{% if user -%}
GRANT ALL PRIVILEGES ON {{ name }}.* TO {{ user }}@'%' IDENTIFIED BY '{{ password }}';
GRANT ALL PRIVILEGES ON {{ name }}.* TO {{ user }}@'localhost' IDENTIFIED BY '{{ password }}';
{%- endif %}
{% endmacro -%}
{% for entry in parameter_dict['database-list'] -%}
{{ database(entry['name'], entry['user'], entry['password']) }}
{{ database(entry['name'], entry.get('user'), entry.get('password')) }}
{% endfor -%}
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