Files
puppet-openstacklib/manifests/db/mysql/host_access.pp
Tobias Urdin 6bdeca8d21 Use validate_legacy
This changes all the puppet 3 validate_* functions
to use the validate_legacy function.

The validate_legacy function has been available since
about three years but require Puppet >= 4.4.0 and since
there is Puppet 4.10.12 as latest we should assume people
are running a fairly new Puppet 4 version.

This is the first step to then remove all validate function
calls and use proper types for parameter as described in spec [1].

[1] https://review.openstack.org/#/c/568929/

Change-Id: I70b9cafad10ec5abfc0166feb01c49adbd1f517d
2019-02-23 22:31:06 +01:00

68 lines
1.7 KiB
Puppet

# Allow a user to access the database for the service
#
# == Namevar
# String with the form dbname_host. The host part of the string is the host
# to allow
#
# == Parameters
# [*user*]
# username to allow
#
# [*password_hash*]
# user password hash
#
# [*database*]
# the database name
#
# [*privileges*]
# the privileges to grant to this user
#
# [*create_user*]
# Flag to allow for the skipping of the user as part of the database setup.
# Set to false to skip the user creation.
# Defaults to true.
#
# [*create_grant*]
# Flag to allow for the skipping of the user grants as part of the database
# setup. Set to false to skip the user creation.
# Defaults to true.
#
# [*tls_options*]
# The TLS options that the user will have
# Defaults to ['NONE']
#
define openstacklib::db::mysql::host_access (
$user,
$password_hash,
$database,
$privileges,
$create_user = true,
$create_grant = true,
$tls_options = ['NONE'],
) {
validate_legacy(Pattern[/_/], 'validate_re', $title,
['_', 'Title must be $dbname_$host'])
$host = inline_template('<%= @title.split("_").last.downcase %>')
if $create_user {
mysql_user { "${user}@${host}":
password_hash => $password_hash,
tls_options => $tls_options,
}
Mysql_database<| title == $database |>
~> Mysql_user<| title == "${user}@${host}" |>
}
if $create_grant {
mysql_grant { "${user}@${host}/${database}.*":
privileges => $privileges,
table => "${database}.*",
user => "${user}@${host}",
}
Mysql_user<| title == "${user}@${host}" |>
~> Mysql_grant<| title == "${user}@${host}/${database}.*" |>
}
}