Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Add apiuser object
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Skopenko committed Aug 23, 2017
1 parent afd8b26 commit f24b049
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ Similarly, `ignore where` statements are created using LWRP resource `Array` att
Currently icinga2 cookbook supports below Objects LWRP Resources:

- icinga2_apilistener
- icinga2_apiuser
- icinga2_applynotification
- icinga2_applyservice
- icinga2_checkcommand
Expand Down Expand Up @@ -1722,6 +1723,30 @@ Above LWRP resource will create an icinga `ApiListener` object.
- *accept_commands* (optional, TrueClass/FalseClass) - icinga `ApiListener` attribute `accept_commands`


## LWRP icinga2_apiuser

LWRP `apiuser` creates an icinga `ApiUser` object.


**LWRP ApiUser example**

icinga2_apiuser 'master' do
password 'mysecretapipassword'
client_cn 'myname'
permissions '["*"]'
end

Above LWRP resource will create an icinga `apiuser` object.


**LWRP Options**

- *action* (optional, String) - default :enable, options: :enable, :disable
- *password* (required, String) - icinga `apiuser` attribute `password`
- *permissions* (required, String) - icinga `apiuser` attribute `permissions`
- *client_cn* (optional, String) - icinga `apiuser` attribute `client_cn`


## LWRP icinga2_livestatuslistener

LWRP `livestatuslistener` creates an icinga `LiveStatusListener` object.
Expand Down
2 changes: 2 additions & 0 deletions libraries/provider_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def object_resources
case new_resource.resource_name
when :icinga2_apilistener
resource.is_a?(Chef::Resource::Icinga2Apilistener)
when :icinga2_apiuser
resource.is_a?(Chef::Resource::Icinga2Apiuser)
when :icinga2_applydependency
resource.is_a?(Chef::Resource::Icinga2Applydependency)
when :icinga2_applynotification
Expand Down
69 changes: 69 additions & 0 deletions libraries/resource_apiuser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true
class Chef
class Resource
# provides icinga2_apiuser
class Icinga2Apiuser < Chef::Resource
identity_attr :name

def initialize(name, run_context = nil)
super
@resource_name = :icinga2_apiuser if respond_to?(:resource_name)
@provides = :icinga2_apiuser
@provider = Chef::Provider::Icinga2Instance
@action = :create
@allowed_actions = [:create, :delete, :nothing]
@name = name
end

def cookbook(arg = nil)
set_or_return(
:cookbook, arg,
:kind_of => String,
:default => 'icinga2'
)
end

def password(arg = nil)
set_or_return(
:password, arg,
:kind_of => String,
:required => true,
:default => nil
)
end

def permissions(arg = nil)
set_or_return(
:permissions, arg,
:kind_of => String,
:required => true,
:default => nil
)
end

def client_cn(arg = nil)
set_or_return(
:client_cn, arg,
:kind_of => String,
:default => nil
)
end

def template_support(arg = nil)
set_or_return(
:template_support, arg,
:kind_of => [FalseClass],
:default => false
)
end

def resource_properties(arg = nil)
set_or_return(
:resource_properties, arg,
:kind_of => Array,
:default => %w(password permissions client_cn)
)
end
end
end
end
10 changes: 10 additions & 0 deletions spec/support/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ def delete_icinga2_apilistener(name)
.new(:icinga2_apilistener, :delete, name)
end

def create_icinga2_apiuser(name)
ChefSpec::Matchers::ResourceMatcher
.new(:icinga2_apiuser, :create, name)
end

def delete_icinga2_apiuser(name)
ChefSpec::Matchers::ResourceMatcher
.new(:icinga2_apiuser, :delete, name)
end

def create_icinga2_applydependency(name)
ChefSpec::Matchers::ResourceMatcher
.new(:icinga2_applydependency, :create, name)
Expand Down
22 changes: 22 additions & 0 deletions templates/default/object.apiuser.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* This file is managed by Chef.
* Do NOT modify this file directly.
*/

/**
* ApiUser Object.
*/

<% @objects.sort.map do |object, options|%>
object ApiUser <%= object.inspect -%> {
<% if options['password'] -%>
password = "<%= options['password'] %>"
<% end -%>
<% if options['permissions'] -%>
permissions = <%= options['permissions'] %>
<% end -%>
<% if options['client_cn'] -%>
client_cn = "<%= options['client_cn'] %>"
<% end -%>
}
<% end -%>

0 comments on commit f24b049

Please sign in to comment.