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

Commit

Permalink
Merge pull request #61 from queeno/support_multiple_users
Browse files Browse the repository at this point in the history
Introducing users param in puppet-uchiwa
  • Loading branch information
solarkennedy committed Dec 4, 2015
2 parents 6433469 + 028afda commit 6e22ab1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
20 changes: 20 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@
# }]
# An array of API endpoints to connect uchiwa to one or multiple sensu servers.
#
# [*users*]
# Array of hashes
# An array of user credentials to access the uchiwa dashboard. If set, it takes
# precendence over 'user' and 'pass'.
# Example:
# ```
# [{
# 'username' => 'user1',
# 'password' => 'pass1',
# 'readonly' => false
# },
# {
# 'username' => 'user2',
# 'password' => 'pass2',
# 'readonly' => true
# }]
# ```
#
class uchiwa (
$package_name = $uchiwa::params::package_name,
$service_name = $uchiwa::params::service_name,
Expand All @@ -112,6 +130,7 @@
$pass = $uchiwa::params::pass,
$refresh = $uchiwa::params::refresh,
$sensu_api_endpoints = $uchiwa::params::sensu_api_endpoints,
$users = $uchiwa::params::users
) inherits uchiwa::params {

# validate parameters here
Expand All @@ -131,6 +150,7 @@
validate_string($pass)
validate_integer($refresh)
validate_array($sensu_api_endpoints)
validate_array($users)

anchor { 'uchiwa::begin': } ->
class { 'uchiwa::install': } ->
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
$user = ''
$pass = ''
$refresh = '5'
$users = []
}
8 changes: 8 additions & 0 deletions spec/classes/uchiwa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,12 @@
}
end

context 'with multiple users' do
let(:params) {{ :users => [ { 'username' => 'user1', 'password' => 'pass1', 'readonly' => true } ] }}
it {
should contain_file('/etc/sensu/uchiwa.json') \
.with_content(/"username": "user1",\n "password": "pass1",\n "role": {\n "readonly": true\n }\n }/)
}
end

end
15 changes: 14 additions & 1 deletion templates/etc/sensu/uchiwa.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@
"port": <%= @port %>,
"user": "<%= @user %>",
"pass": "<%= @pass %>",
"refresh": <%= @refresh %>
"refresh": <%= @refresh %><%= ',' if @users.size > 0 %>
<%- if @users.size > 0 -%>
"users": [
<%- @users.each_with_index do |user, i| -%>
{
"username": "<%= user['username'] %>",
"password": "<%= user['password'] %>",
"role": {
"readonly": <%= user['readonly'] %>
}
}<%= ',' if i < (@users.size - 1) %>
<%- end -%>
]
<%- end -%>
}
}

0 comments on commit 6e22ab1

Please sign in to comment.