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

Added API parameters for user and password #119

Merged
merged 1 commit into from
Jan 14, 2014
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
31 changes: 31 additions & 0 deletions lib/puppet/provider/sensu_api_config/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def create
conf['api'] = {}
self.port = resource[:port]
self.host = resource[:host]
self.user = resource[:user] unless resource[:user].nil?
self.password = resource[:password] unless resource[:password].nil?
end

# Public: Remove the API configuration section.
Expand Down Expand Up @@ -75,4 +77,33 @@ def host
def host=(value)
conf['api']['host'] = value
end

# Public: Retrieve the api username
#
# Returns the String hostname.
def user
conf['api']['user']
end

# Public: Set the api user
#
# Returns nothing.
def user=(value)
conf['api']['user'] = value
end

# Public: Retrieve the password for the api
#
# Returns the String password.
def password
conf['api']['password']
end

# Public: Set the api password
#
# Returns nothing.
def password=(value)
conf['api']['password'] = value
end

end
8 changes: 8 additions & 0 deletions lib/puppet/type/sensu_api_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def initialize(*args)
defaultto 'localhost'
end

newproperty(:user) do
desc "The username used for clients to authenticate against the Sensu API"
end

newproperty(:password) do
desc "The password use for client authentication against the Sensu API"
end

autorequire(:package) do
['sensu']
end
Expand Down
10 changes: 6 additions & 4 deletions manifests/api/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
ensure => $ensure,
owner => 'sensu',
group => 'sensu',
mode => '0444',
mode => '0440',
}

sensu_api_config { $::fqdn:
ensure => $ensure,
host => $sensu::api_host,
port => $sensu::api_port,
ensure => $ensure,
host => $sensu::api_host,
port => $sensu::api_port,
user => $sensu::api_user,
password => $sensu::api_password,
}

}
12 changes: 11 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,17 @@
# Default: localhost
#
# [*api_port*]
# Integer. Port of the sensu api service
# Integer. Port of the sensu api service
# Default: 4567
#
# [*api_user*]
# String. Password of the sensu api service
# Default: undef
#
# [*api_password*]
# Integer. Password of the sensu api service
# Default: undef
#
# [*dashboard_host*]
# String. Hostname of the dahsboard host
# Default: $::ipaddress
Expand Down Expand Up @@ -175,6 +183,8 @@
$redis_port = 6379,
$api_host = 'localhost',
$api_port = 4567,
$api_user = undef,
$api_password = undef,
$dashboard_host = $::ipaddress,
$dashboard_port = 8080,
$dashboard_user = 'admin',
Expand Down
21 changes: 21 additions & 0 deletions spec/classes/sensu_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
:host => 'localhost',
:port => 4567
) }
it { should contain_sensu_api_config('testhost.domain.com').without_api_user }
it { should contain_sensu_api_config('testhost.domain.com').without_api_password }
end # defaults

context 'set config params' do
Expand All @@ -69,6 +71,25 @@
:host => 'sensuapi.domain.com',
:port => 5678
) }
it { should contain_sensu_api_config('testhost.domain.com').without_api_user }
it { should contain_sensu_api_config('testhost.domain.com').without_api_password }
end # set config params

context 'set config params including authentication' do
let(:params) { {
:api => true,
:api_host => 'sensuapi.domain.com',
:api_port => 5678,
:api_user => 'test_user',
:api_password => 'test_password'
} }
it { should contain_sensu_api_config('testhost.domain.com').with(
:ensure => 'present',
:host => 'sensuapi.domain.com',
:port => 5678,
:user => 'test_user',
:password => 'test_password'
) }
end # set config params

context 'purge config' do
Expand Down