Skip to content

Commit

Permalink
Support custom configurations in enterprise dashboard (fixes sensu#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Nov 24, 2018
1 parent 88042ac commit 12c2949
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/puppet/provider/sensu_enterprise_dashboard_config/json.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
require 'json' if Puppet.features.json?
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..',
'puppet_x', 'sensu', 'provider_create.rb'))
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..',
'puppet_x', 'sensu', 'to_type.rb'))

Puppet::Type.type(:sensu_enterprise_dashboard_config).provide(:json) do
confine :feature => :json
include PuppetX::Sensu::ToType
include PuppetX::Sensu::ProviderCreate

# Internal: Retrieve the current contents of /etc/sensu/dashboard.json
Expand Down Expand Up @@ -216,4 +219,18 @@ def oidc
def oidc=(value)
conf['dashboard']['oidc'] = value.to_hash
end

def is_property?(prop)
properties = self.class.resource_type.validproperties
properties.map(&:to_s).include? prop
end

def custom
conf['dashboard'].reject { |k,v| is_property?(k) }
end

def custom=(value)
conf['dashboard'].delete_if { |k,v| not is_property?(k) }
conf['dashboard'].merge!(to_type(value))
end
end
27 changes: 27 additions & 0 deletions lib/puppet/type/sensu_enterprise_dashboard_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,33 @@ def initialize(*args)
end
end

newproperty(:custom) do
desc "Custom config variables"
include PuppetX::Sensu::ToType

def is_to_s(hash = @is)
hash.keys.sort.map {|key| "#{key} => #{hash[key]}"}.join(", ")
end

def should_to_s(hash = @should)
hash.keys.sort.map {|key| "#{key} => #{hash[key]}"}.join(", ")
end

def insync?(is)
if defined? @should[0]
if is == @should[0].each { |k, v| value[k] = to_type(v) }
true
else
false
end
else
true
end
end

defaultto {}
end

autorequire(:package) do
['sensu-enterprise-dashboard']
end
Expand Down
1 change: 1 addition & 0 deletions manifests/enterprise/dashboard.pp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
gitlab => $::sensu::enterprise_dashboard_gitlab,
ldap => $::sensu::enterprise_dashboard_ldap,
oidc => $::sensu::enterprise_dashboard_oidc,
custom => $::sensu::enterprise_dashboard_custom,
notify => $file_notify,
}

Expand Down
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@
#
# @param enterprise_dashboard_oidc Optional OIDC configuration for Enterprise Dashboard
#
# @param enterprise_dashboard_custom List of custom attributes to include in the check.
# You can use it to pass any attribute that is not listed here explicitly.
# Example: { 'usersOptions' => { 'requireSilencingReason' => true } }
#
# @param path Used to set PATH in /etc/default/sensu
#
# @param redact Use to redact passwords from checks on the client side
Expand Down Expand Up @@ -460,6 +464,7 @@
Optional[Any] $enterprise_dashboard_gitlab = undef,
Optional[Any] $enterprise_dashboard_ldap = undef,
Optional[Any] $enterprise_dashboard_oidc = undef,
Optional[Hash] $enterprise_dashboard_custom = undef,
Variant[Stdlib::Absolutepath,Pattern[/^\$PATH$/]] $path = '$PATH',
Optional[Array] $redact = undef,
Boolean $deregister_on_stop = false,
Expand Down
14 changes: 14 additions & 0 deletions spec/classes/sensu_enterprise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@
end
end

context 'with enterprise_dashboard_custom defined' do
let(:params) { {
:enterprise => true,
:enterprise_user => 'sensu',
:enterprise_pass => 'sensu',
:enterprise_dashboard => true,
:enterprise_dashboard_custom => { 'key' => 'value' }
} }
it { should contain_sensu_enterprise_dashboard_config('testhost.domain.com').with({
'custom' => { 'key' => 'value' }
}) }
end
end

context 'with rabbitmq_ssl => true and rabbitmq_ssl_cert_chain => undef' do
let(:params) { {
:enterprise => true,
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/sensu_enterprise_dashboard_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@
expect(type_instance[:oidc]).to be_a(Hash)
end
end

describe 'accepts Hash values for :custom' do
it do
type_instance[:custom] = { :key => :value }
expect(type_instance[:custom]).to be_a(Hash)
end
end
end
3 changes: 3 additions & 0 deletions tests/sensu-server-enterprise.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
install_repo => true,
enterprise => true,
enterprise_dashboard => true,
enterprise_dashboard_custom => {
'usersOptions' => { 'requireSilencingReason' => true },
},
enterprise_user => $facts['se_user'],
enterprise_pass => $facts['se_pass'],
manage_services => true,
Expand Down

0 comments on commit 12c2949

Please sign in to comment.