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 #78 from br0ch0n/support_usersoptions
Browse files Browse the repository at this point in the history
Support the new UsersOptions hash
  • Loading branch information
solarkennedy authored Dec 20, 2016
2 parents 64ce619 + 8e622f6 commit 8095b7c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
11 changes: 11 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ Litle more advanced:
```
uchiwa::ssl: { 'certfile': '/opt/ssl/%{::hostname}.crt', 'keyfile': '/opt/ssl/%{::hostname}.key' }
```
## Users Options

Example of declaring the UsersOptions hash as defined in https://docs.uchiwa.io/getting-started/configuration/#users-options:

Via hiera:
```
uchiwa::usersoptions:
disableNoExpiration: true
requireSilencingReason: true
defaultExpireOnResolve: true
```

## License

Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
$users = $uchiwa::params::users,
$auth = $uchiwa::params::auth,
$ssl = $uchiwa::params::ssl,
$usersoptions = $uchiwa::params::usersoptions,
) inherits uchiwa::params {

# validate parameters here
Expand All @@ -177,6 +178,7 @@
validate_array($users)
validate_hash($auth)
validate_hash($ssl)
validate_hash($usersoptions)

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 @@ -49,4 +49,5 @@
$users = []
$auth = {}
$ssl = {}
$usersoptions = {}
}
9 changes: 9 additions & 0 deletions spec/classes/uchiwa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,13 @@
}
end

context 'with usersoptions' do
let(:params) {{ :usersoptions => { 'disableNoExpiration' => true, 'defaultTheme' => 'uchiwa-default' } }}
it {
should contain_file('/etc/sensu/uchiwa.json') \
.with_content(/"disableNoExpiration": true/) \
.with_content(/"defaultTheme": "uchiwa-default"/)
}
end

end
21 changes: 16 additions & 5 deletions templates/etc/sensu/uchiwa.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"timeout": <%= endpoint['timeout'] || default_endpoint['timeout'] %>
}<%= ',' if j < (endpoint['host'].size - 1) -%>
<%- end -%>
<%= ',' if i < (@sensu_api_endpoints.size - 1) %>
<%= ',' if i < (@sensu_api_endpoints.size - 1) %>
<%- end -%>
],
"uchiwa": {
"host": "<%= @host %>",
"port": <%= @port %>,
"user": "<%= @user %>",
"pass": "<%= @pass %>",
"refresh": <%= @refresh %><%= ',' if @users.size > 0 or @auth.size == 2 or @ssl.size == 2%>
"refresh": <%= @refresh %><%= ',' if @users.size > 0 or @auth.size == 2 or @ssl.size == 2 or @usersoptions.size > 0 %>
<%- if @users.size > 0 -%>
"users": [
<%- @users.each_with_index do |user, i| -%>
Expand All @@ -41,19 +41,30 @@
}
}<%= ',' if i < (@users.size - 1) %>
<%- end -%>
]<%= ',' if @users.size %>
]<%= ',' if @auth.size == 2 or @ssl.size == 2 or @usersoptions.size > 0 %>
<%- end -%>
<%- if @auth.size == 2 -%>
"auth": {
"publickey": "<%= @auth['publickey'] %>",
"privatekey": "<%= @auth['privatekey'] %>"
}<%= ',' if @ssl.size == 2 %>
}<%= ',' if @ssl.size == 2 || @usersoptions.size > 0 %>
<%- end -%>
<%- if @ssl.size == 2 -%>
"ssl": {
"certfile": "<%= @ssl['certfile'] %>",
"keyfile": "<%= @ssl['keyfile'] %>"
}
}<%= ',' if @usersoptions.size > 0 %>
<%- end -%>
<%- if @usersoptions.size > 0 -%>
"usersOptions": {
<%- @usersoptions.each_with_index do |(k,v), idx| -%>
<%- if [true, false].include? v -%>
"<%= k %>": <%= v %><%= ',' if idx != (@usersoptions.size - 1) %>
<%- else -%>
"<%= k %>": "<%= v %>"<%= ',' if idx != (@usersoptions.size - 1) %>
<%- end -%>
<%- end -%>
}
<%- end -%>
}
}

0 comments on commit 8095b7c

Please sign in to comment.