Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional parameter plugindir (Directory containing kibana plugins) #71

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions Guardfile

This file was deleted.

30 changes: 30 additions & 0 deletions lib/puppet/functions/kibana/hash2yaml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

# @summary Converts a puppet hash to YAML string.
Puppet::Functions.create_function(:'kibana::hash2yaml') do
# @param input The hash to be converted to YAML
# @param options A hash of options to control YAML file format
# @return [String] A YAML formatted string
# @example Call the function with the $input hash
# kibana::hash2yaml($input)
dispatch :yaml do
param 'Hash', :input
optional_param 'Hash', :options
end

require 'yaml'

def yaml(input, options = {})
settings = {
'header' => '# File managed by Puppet.'
}

settings.merge!(options)

if settings['header'].to_s.empty?
input.to_yaml
else
"#{settings['header']}\n#{input.to_yaml}"
end
end
end
75 changes: 0 additions & 75 deletions lib/puppet_x/elastic/hash.rb

This file was deleted.

12 changes: 10 additions & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@
'absent' => $kibana::ensure,
default => 'file',
}
$config = $kibana::config

file { '/etc/kibana/kibana.yml':
ensure => $_ensure,
content => template("${module_name}/etc/kibana/kibana.yml.erb"),
content => Sensitive(kibana::hash2yaml($kibana::config)),
owner => $kibana::kibana_user,
group => $kibana::kibana_group,
mode => '0660',
}

if $kibana::plugindir {
file { $kibana::plugindir:
ensure => 'directory',
owner => $kibana::kibana_user,
group => $kibana::kibana_group,
mode => '0755',
}
}
}
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
# @param status Service status
# @param service_name Service name
# @param package_name Package name
# @param plugindir
# Directory containing kibana plugins.
# Use this setting if you want to manage the directory
# @param kibana_user owner of kibana.yml
# @param kibana_group group of kibana.yml
#
Expand All @@ -36,6 +39,7 @@
Boolean $oss,
Optional[String] $package_source,
Kibana::Status $status,
Optional[Stdlib::Absolutepath] $plugindir = undef,
String[1] $service_name = 'kibana',
String[1] $package_name = 'kibana',
String[1] $kibana_user = 'kibana',
Expand Down
14 changes: 10 additions & 4 deletions spec/classes/kibana_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
group: 'kibana',
mode: '0660'
).
with_content(%r{
# Managed by Puppet..
---.
}xm)
with_content(sensitive(%r{
# Managed by Puppet..
---.
}xm))
end

it 'enables and starts the service' do
Expand Down Expand Up @@ -246,6 +246,12 @@
with_name('kibana-custom')
}
end

describe 'kibana_plugindir' do
let(:params) { { plugindir: '/usr/local/kibana/plugins' } }

it { is_expected.to contain_file('/usr/local/kibana/plugins').with(mode: '0755') }
end
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/functions/kibana_hash2yaml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require 'spec_helper'
describe 'kibana::hash2yaml' do
context 'with header' do
it do
is_expected.to run.with_params({ cle: 1 }, { header: '# HEADER' }).and_return('# HEADER\ncle: 1')
end
end

context 'without header' do
it do
is_expected.to run.with_params({ cle: 1 }).and_return('# File managed by Puppet.\ncle: 1')
end
end
end
65 changes: 0 additions & 65 deletions spec/templates/kibana.yml.erb_spec.rb

This file was deleted.

26 changes: 0 additions & 26 deletions spec/unit/puppet_x/elastic/hash_spec.rb

This file was deleted.

7 changes: 0 additions & 7 deletions templates/etc/kibana/kibana.yml.erb

This file was deleted.