Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

refactor out uchiwa::params to init.pp, add new users array option #47

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 17 additions & 6 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
#
class uchiwa::config inherits uchiwa {

file { '/etc/sensu/uchiwa.json':
ensure => file,
content => template('uchiwa/etc/sensu/uchiwa.json.erb'),
owner => uchiwa,
group => uchiwa,
mode => '0440',

if count($uchiwa::users) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not have two entrypoints for when users or set or not.
Reduce duplication here, just have one template

file { '/etc/sensu/uchiwa.json':
ensure => file,
content => template('uchiwa/etc/sensu/users-uchiwa.json.erb'),
owner => uchiwa,
group => uchiwa,
mode => '0440',
}
} else {
file { '/etc/sensu/uchiwa.json':
ensure => file,
content => template('uchiwa/etc/sensu/user-uchiwa.json.erb'),
owner => uchiwa,
group => uchiwa,
mode => '0440',
}
}
}
45 changes: 28 additions & 17 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,34 @@
# An array of API endpoints to connect uchiwa to one or multiple sensu servers.
#
class uchiwa (
$package_name = $uchiwa::params::package_name,
$service_name = $uchiwa::params::service_name,
$version = $uchiwa::params::version,
$install_repo = $uchiwa::params::install_repo,
$repo = $uchiwa::params::repo,
$repo_source = $uchiwa::params::repo_source,
$repo_key_id = $uchiwa::params::repo_key_id,
$repo_key_source = $uchiwa::params::repo_key_source,
$manage_services = $uchiwa::params::manage_services,
$manage_user = $uchiwa::params::manage_user,
$host = $uchiwa::params::host,
$port = $uchiwa::params::port,
$user = $uchiwa::params::user,
$pass = $uchiwa::params::pass,
$refresh = $uchiwa::params::refresh,
$sensu_api_endpoints = $uchiwa::params::sensu_api_endpoints,
) inherits uchiwa::params {
$package_name = 'uchiwa',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we were not really using params at all.

$service_name = 'uchiwa',
$version = 'latest',
$install_repo = true,
$repo = 'main',
$repo_source = undef,
$repo_key_id = '7580C77F',
$repo_key_source = 'http://repos.sensuapp.org/apt/pubkey.gpg',
$manage_services = true,
$manage_user = true,
$host = '0.0.0.0',
$port = '3000',
$user = '',
$pass = '',
$users = [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a docstring on the format

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do mean by docstring -- as in puppet docs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea... but looking at this now I don't know what it is in reference to.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure i understand what you mean - but it is in line with the
puppet-sensu module, and it's got the docs above as well regardless...

On Thu, Jul 9, 2015 at 11:19 PM, Kyle Anderson [email protected]
wrote:

In manifests/init.pp
#47 (comment):

-) inherits uchiwa::params {

  • $package_name = 'uchiwa',
  • $service_name = 'uchiwa',
  • $version = 'latest',
  • $install_repo = true,
  • $repo = 'main',
  • $repo_source = undef,
  • $repo_key_id = '7580C77F',
  • $repo_key_source = 'http://repos.sensuapp.org/apt/pubkey.gpg',
  • $manage_services = true,
  • $manage_user = true,
  • $host = '0.0.0.0',
  • $port = '3000',
  • $user = '',
  • $pass = '',
  • $users = [],

Yea... but looking at this now I don't know what it is in reference to.


Reply to this email directly or view it on GitHub
https://github.com/Yelp/puppet-uchiwa/pull/47/files#r34325269.

$refresh = '5',
$sensu_api_endpoints = [{
name => 'sensu',
host => '127.0.0.1',
ssl => false,
insecure => false,
port => 4567,
user => 'sensu',
pass => 'sensu',
path => '',
timeout => 5,
}]
) {

# validate parameters here
validate_bool($install_repo)
Expand Down
47 changes: 0 additions & 47 deletions manifests/params.pp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sensu": [
<%- default_endpoint = scope['uchiwa::params::sensu_api_endpoints'][0] -%>
<%- default_endpoint = scope['uchiwa::sensu_api_endpoints'][0] -%>
<%- @sensu_api_endpoints.each_with_index do |endpoint, i| -%>
{
"name": "<%= endpoint['name'] || default_endpoint['name'] %>",
Expand Down
36 changes: 36 additions & 0 deletions templates/etc/sensu/users-uchiwa.json.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"sensu": [
<%- default_endpoint = scope['uchiwa::sensu_api_endpoints'][0] -%>
<%- @sensu_api_endpoints.each_with_index do |endpoint, i| -%>
{
"name": "<%= endpoint['name'] || default_endpoint['name'] %>",
"host": "<%= endpoint['host'] || default_endpoint['host'] %>",
"ssl": <%= endpoint['ssl'] || default_endpoint['ssl'] %>,
"insecure": <%= endpoint['insecure'] || default_endpoint['insecure']%>,
"port": <%= endpoint['port'] || default_endpoint['port'] %>,
"user": "<%= endpoint['user'] || default_endpoint['user'] %>",
"pass": "<%= endpoint['pass'] || default_endpoint['pass'] %>",
"path": "<%= endpoint['path'] || default_endpoint['path'] %>",
"timeout": <%= endpoint['timeout'] || default_endpoint['timeout'] %>
}<%= ',' if i < (@sensu_api_endpoints.size - 1) %>
<%- end -%>
],
"uchiwa": {
"host": "<%= @host %>",
"port": <%= @port %>,
"users": [
<%- @users.each_with_index do |user, i| -%>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some sort of unit test to prove that it works

{
"username": "<%= user['username'] %>",
"password": "<%= user['password'] %>",
"role": {
"readonly": <%= user['readonly'] %>
}
}<%= ',' if i < (@users.size - 1) %>
<%- end -%>
]
"refresh": <%= @refresh %>
}
}

$uchiwa::users