diff --git a/lib/puppet/functions/validate_available_themes.rb b/lib/puppet/functions/validate_available_themes.rb new file mode 100644 index 00000000..346050bd --- /dev/null +++ b/lib/puppet/functions/validate_available_themes.rb @@ -0,0 +1,15 @@ +Puppet::Functions.create_function(:validate_available_themes) do + + def validate_available_themes(themes) + req_keys = Set.new(['name', 'label', 'path']) + themes.each do |theme| + if theme.keys.to_set != req_keys + if theme.keys.to_set.subset?(req_keys) + raise Puppet::Error, "Some of the required keys (name, label and path) are missing" + else + raise Puppet::Error, "Unsupported keys are detected" + end + end + end + end +end diff --git a/manifests/init.pp b/manifests/init.pp index d793c946..c16233d6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -360,7 +360,7 @@ # [*available_themes*] # (optional) An array of hashes detailing available themes. Each hash must # have the followings keys for themes to be made available; name, label, -# path. Defaults to false +# path. Defaults to undef # # { 'name' => 'theme_name', 'label' => 'theme_label', 'path' => 'theme_path' } # @@ -372,14 +372,15 @@ # ] # } # -# Or in Hiera: -# horizon::available_themes: -# - { name: 'default', label: 'Default', path: 'themes/default' } -# - { name: 'material', label: 'Material', path: 'themes/material' } +# Or in Hiera: +# horizon::available_themes: +# - { name: 'default', label: 'Default', path: 'themes/default' } +# - { name: 'material', label: 'Material', path: 'themes/material' } # # [*default_theme*] -# (optional) The default theme to use from list of available themes. Value should be theme_name. -# Defaults to false +# (optional) The default theme to use from list of available themes. Value +# should be theme_name. +# Defaults to undef # # [*authentication_plugins*] # (optional) List of authentication plugins to be used. @@ -620,8 +621,8 @@ class horizon( Boolean $secure_cookies = false, $django_session_engine = undef, $vhost_extra_params = undef, - $available_themes = false, - $default_theme = false, + Horizon::AvailableThemes $available_themes = undef, + Optional[String[1]] $default_theme = undef, Array[String[1]] $authentication_plugins = [], Enum['on', 'off'] $password_autocomplete = 'off', $create_image_defaults = undef, @@ -667,6 +668,10 @@ class horizon( fail('websso_initial_choice is required when websso_choices_hide_keystone is true') } + if $available_themes { + validate_available_themes($available_themes) + } + Service <| title == 'memcached' |> -> Class['horizon'] if $policy_files_path != undef { diff --git a/spec/type_aliases/availablethemes_spec.rb b/spec/type_aliases/availablethemes_spec.rb new file mode 100644 index 00000000..d5874d72 --- /dev/null +++ b/spec/type_aliases/availablethemes_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe 'Horizon::AvailableThemes' do + describe 'valid types' do + context 'with valid types' do + [ + [ + {'name' => 'default'} + ], + [ + {'name' => 'default'}, + {'name' => 'custom'} + ], + ].each do |value| + describe value.inspect do + it { is_expected.to allow_value(value) } + end + end + end + end + + describe 'invalid types' do + context 'with garbage inputs' do + [ + [], + ['name'], + [{'name' => 1}], + [{1 => 'default'}], + [{'name' => ''}], + [{'' => 'default'}], + ].each do |value| + describe value.inspect do + it { is_expected.not_to allow_value(value) } + end + end + end + end +end diff --git a/types/availablethemes.pp b/types/availablethemes.pp new file mode 100644 index 00000000..583721f1 --- /dev/null +++ b/types/availablethemes.pp @@ -0,0 +1,6 @@ +type Horizon::AvailableThemes = Optional[ + Array[ + Hash[String[1], String[1]], + 1 + ] +]