WIP: Implement type validation

Change-Id: I0ef6b0aaa8607b1dbf3c289d8631b9b85c6d6289
This commit is contained in:
Takashi Kajinami 2021-11-01 11:53:09 +09:00
parent 5734cafcee
commit 0e9fc01da9
17 changed files with 112 additions and 86 deletions

View File

@ -61,20 +61,20 @@
# string; optional; default to undef
#
define openstacklib::db::mysql (
$password = undef,
$plugin = undef,
$dbname = $title,
$user = $title,
$host = '127.0.0.1',
$charset = 'utf8',
$collate = 'utf8_general_ci',
$allowed_hosts = [],
$privileges = 'ALL',
$create_user = true,
$create_grant = true,
$tls_options = ['NONE'],
Optional[String] $password = undef,
Optional[String] $plugin = undef,
String[1] $dbname = $title,
String[1] $user = $title,
Stdlb::Host $host = '127.0.0.1',
String[1] $charset = 'utf8',
String[1] $collate = 'utf8_general_ci',
Variant[Stdlib::Host, Array[Stdlib::Host]] $allowed_hosts = [],
Variant[String, Array[String]] $privileges = 'ALL',
Boolean $create_user = true,
Boolean $create_grant = true,
Variant[String, Array[String]] $tls_options = ['NONE'],
# DEPRECATED PARAMETER
$password_hash = undef,
Optional[String] $password_hash = undef,
) {
include mysql::server

View File

@ -17,6 +17,11 @@
# [*privileges*]
# the privileges to grant to this user
#
# [*allowed_host*]
# A string representing map of host and database. Should be formatted like
# <host>_<dbname>.
# Defaults to $name
#
# [*plugin*]
# Authentication plugin to use when connecting to the MySQL server;
# Defaults to undef
@ -36,19 +41,17 @@
# Defaults to ['NONE']
#
define openstacklib::db::mysql::host_access (
$user,
$password_hash,
$database,
$privileges,
$plugin = undef,
$create_user = true,
$create_grant = true,
$tls_options = ['NONE'],
String[1] $user,
String[1] $password_hash,
String[1] $database,
Variant[String, Array[String]] $privileges,
Pattern[/_/] $allowed_host = $title,
Optional[String] $plugin = undef,
Boolean $create_user = true,
Boolean $create_grant = true,
Variant[String, Array[String]] $tls_options = ['NONE'],
) {
validate_legacy(Pattern[/_/], 'validate_re', $title,
['_', 'Title must be $dbname_$host'])
$host = inline_template('<%= @title.split("_").last.downcase %>')
if $create_user {

View File

@ -31,13 +31,13 @@
# string; required
#
define openstacklib::db::postgresql (
$password = undef,
$dbname = $title,
$user = $title,
$encoding = undef,
$privileges = 'ALL',
Optional[String] $password = undef,
String[1] $dbname = $title,
String[1] $user = $title,
Optional[String] $encoding = undef,
String $privileges = 'ALL',
# DEPRECATED PARAMETERS
$password_hash = undef,
Optional[String] $password_hash = undef,
){
if $password_hash != undef {

View File

@ -17,9 +17,9 @@
# Defaults to 'present'
#
class openstacklib::iscsid(
$enabled = true,
$manage_service = true,
$package_ensure = 'present'
Boolean $enabled = true,
Boolean $manage_service = true,
String[1] $package_ensure = 'present'
) {
include openstacklib::params

View File

@ -62,16 +62,16 @@
# Defaults to true
#
define openstacklib::messaging::rabbitmq(
$userid = 'guest',
$password = 'guest',
$virtual_host = '/',
$is_admin = false,
$configure_permission = '.*',
$write_permission = '.*',
$read_permission = '.*',
$manage_user = true,
$manage_user_permissions = true,
$manage_vhost = true,
String[1] $userid = 'guest',
String[1] $password = 'guest',
String[1] $virtual_host = '/',
Boolean $is_admin = false,
String[1] $configure_permission = '.*',
String[1] $write_permission = '.*',
String[1] $read_permission = '.*',
Boolean $manage_user = true,
Boolean $manage_user_permissions = true,
Boolean $manage_vhost = true,
) {
if $manage_user {

View File

@ -13,8 +13,8 @@
# Defaults to $::openstacklib::params::openstackclient_package_name
#
class openstacklib::openstackclient(
$package_name = $::openstacklib::params::openstackclient_package_name,
$package_ensure = 'present',
String[1] $package_name = $::openstacklib::params::openstackclient_package_name,
String[1] $package_ensure = 'present',
) inherits openstacklib::params {
ensure_packages($package_name, {

View File

@ -34,16 +34,14 @@
# Defaults to false.
#
define openstacklib::policy (
$policy_path = $name,
$policies = {},
$file_mode = '0640',
$file_user = undef,
$file_group = undef,
$file_format = 'json',
$purge_config = false,
Stdlib::Absolutepath $policy_path = $name,
Hash $policies = {},
Stdlib::Filemode $file_mode = '0640',
Optional[String] $file_user = undef,
Optional[String] $file_group = undef,
Enum['json', 'yaml'] $file_format = 'json',
Boolean $purge_config = false,
) {
validate_legacy(Hash, 'validate_hash', $policies)
validate_legacy(Stdlib::Absolutepath, 'validate_absolute_path', $policy_path)
if empty($policies) {
create_resources('openstacklib::policy::default', { $policy_path => {

View File

@ -37,14 +37,14 @@
# Defaults to false.
#
define openstacklib::policy::base (
$file_path,
$key,
$value = '',
$file_mode = '0640',
$file_user = undef,
$file_group = undef,
$file_format = 'json',
$purge_config = false,
Stdlib::Absolutepath $file_path,
String[1] $key,
String[1] $value = '',
Stdlib::Filemode $file_mode = '0640',
Optional[String] $file_user = undef,
Optional[String] $file_group = undef,
Enum['json', 'yaml'] $file_format = 'json',
Boolean $purge_config = false,
) {
ensure_resource('openstacklib::policy::default', $file_path, {

View File

@ -31,12 +31,12 @@
# Defaults to false.
#
define openstacklib::policy::default (
$file_path = $name,
$file_mode = '0640',
$file_user = undef,
$file_group = undef,
$file_format = 'json',
$purge_config = false,
Stdlib::Absolutepath $file_path = $name,
Stdlib::Filemode $file_mode = '0640',
Optional[String] $file_user = undef,
Optional[String] $file_group = undef,
Enum['json', 'yaml'] $file_format = 'json',
Boolean $purge_config = false,
) {
case $file_format {

View File

@ -22,11 +22,9 @@
# that should not autostart on install.
#
class openstacklib::policyrcd(
$services
Array[String] $services
) {
validate_legacy(Array, 'validate_array', $services)
if $::osfamily == 'Debian' {
# We put this out there so openstack services wont auto start
# when installed.

View File

@ -43,15 +43,15 @@
#
# [*timeout*]
# The maximum time the command should take;
# string; optional; default to '60'
# string; optional; default to 60
#
# [*tries*]
# Number of times to retry validation;
# string; optional; default to '10'
# string; optional; default to 10
#
# [*try_sleep*]
# Number of seconds between validation attempts;
# string; optional; default to '2'
# string; optional; default to 2
#
# [*onlyif*]
# Run the exec if all conditions in the array return true.
@ -66,17 +66,17 @@
# string; optional; default to empty array
#
define openstacklib::service_validation(
$command,
$service_name = $name,
$path = '/usr/bin:/bin:/usr/sbin:/sbin',
$provider = shell,
$refreshonly = false,
$timeout = '60',
$tries = '10',
$try_sleep = '2',
$onlyif = undef,
$unless = undef,
$environment = [],
String[1] $command,
String[1] $service_name = $name,
String[1] $path = '/usr/bin:/bin:/usr/sbin:/sbin',
String[1] $provider = 'shell',
Boolean $refreshonly = false,
Variant[Pattern[/\d+/], Integer] $timeout = 60,
Variant[Pattern[/\d+/], Integer] $tries = 10,
Variant[Pattern[/\d+/], Integer] $try_sleep = 2,
Optional[String] $onlyif = undef,
Optional[String] $unless = undef,
Array[String] $environment = [],
) {
if $onlyif and $unless {
@ -101,4 +101,3 @@ define openstacklib::service_validation(
-> Exec<| title == "execute ${service_name} validation" |>
}

5
types/array.pp Normal file
View File

@ -0,0 +1,5 @@
type Openstacklib::Array = Variant [
Array[String],
String,
Openstacklib::Default
]

7
types/boolean.pp Normal file
View File

@ -0,0 +1,7 @@
type Openstacklib::Boolean = Variant[
Boolean,
# lint:ignore:quoted_booleans
Enum['true', 'false', 'True', 'False'],
# lint:endignore
Openstacklib::Default
]

1
types/default.pp Normal file
View File

@ -0,0 +1 @@
type Openstacklib::Default = Enum['<SERVICE DEFAULT>']

6
types/float.pp Normal file
View File

@ -0,0 +1,6 @@
type Openstacklib::Float = Variant[
Float,
Pattern[/\d*/],
Pattern[/\d*\.\d+/],
Openstacklib::Default
]

5
types/integer.pp Normal file
View File

@ -0,0 +1,5 @@
type Openstacklib::Integer = Variant[
Integer,
Pattern[/\d*/],
Openstacklib::Default
]

4
types/string.pp Normal file
View File

@ -0,0 +1,4 @@
type Openstacklib::String = Variant[
String,
Openstacklib::Default
]