Skip to content

Commit

Permalink
Sensu_user resources that are not admin should auto require admin use…
Browse files Browse the repository at this point in the history
…r in order to be able to properly be applied
  • Loading branch information
treydock committed May 25, 2020
1 parent c51f5a6 commit 1aee2c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/puppet/type/sensu_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* `Service[sensu-backend]`
* `Sensuctl_configure[puppet]`
* `Sensu_api_validator[sensu]`
* `Sensu_user[admin]`
DESC

extend PuppetX::Sensu::Type
Expand Down Expand Up @@ -113,6 +114,14 @@ def should_to_s(newvalue)
defaultto('/etc/sensu/ssl/ca.crt')
end

autorequire(:sensu_user) do
if self[:name] == 'admin'
[]
else
['admin']
end
end

validate do
required_properties = [
:password
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/sensu_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@
end
end

it 'should autorequire sensu_user' do
validator = Puppet::Type.type(:sensu_user).new(:name => 'admin', :password => 'password')
catalog = Puppet::Resource::Catalog.new
catalog.add_resource user
catalog.add_resource validator
rel = user.autorequire[0]
expect(rel.source.ref).to eq(validator.ref)
expect(rel.target.ref).to eq(user.ref)
end

include_examples 'autorequires', false, true, false do
let(:res) { user }
end
Expand Down

0 comments on commit 1aee2c8

Please sign in to comment.