23 changes: 17 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [v4.2.1](https://github.com/sensu/sensu-puppet/tree/v4.2.1) (2020-01-29)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v4.2.0...v4.2.1)

### Added

- Remove workaround for sensuctl command json formatting [\#1204](https://github.com/sensu/sensu-puppet/pull/1204) ([treydock](https://github.com/treydock))

### Fixed

- Several fixes for sensu\_bonsai\_asset [\#1202](https://github.com/sensu/sensu-puppet/pull/1202) ([treydock](https://github.com/treydock))
- Remove unnecessary auto requirement [\#1200](https://github.com/sensu/sensu-puppet/pull/1200) ([treydock](https://github.com/treydock))

## [v4.2.0](https://github.com/sensu/sensu-puppet/tree/v4.2.0) (2020-01-20)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v4.1.0...v4.2.0)
Expand Down Expand Up @@ -171,6 +184,10 @@

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v3.4.0...v3.4.1)

### Added

- Add acceptance tests that use puppetserver [\#1123](https://github.com/sensu/sensu-puppet/pull/1123) ([treydock](https://github.com/treydock))

### Fixed

- Fix to support Puppetserver 5 [\#1122](https://github.com/sensu/sensu-puppet/pull/1122) ([treydock](https://github.com/treydock))
Expand All @@ -196,7 +213,6 @@

### Added

- Add acceptance tests that use puppetserver [\#1123](https://github.com/sensu/sensu-puppet/pull/1123) ([treydock](https://github.com/treydock))
- \(GH-1111\) Remove Ubuntu 14.04 LTS as it is end of life \(EOL\) [\#1112](https://github.com/sensu/sensu-puppet/pull/1112) ([ghoneycutt](https://github.com/ghoneycutt))
- Add Windows support for Sensu Go agent [\#1108](https://github.com/sensu/sensu-puppet/pull/1108) ([treydock](https://github.com/treydock))

Expand All @@ -220,11 +236,6 @@
### Added

- Prep 3.1.0 release [\#1103](https://github.com/sensu/sensu-puppet/pull/1103) ([treydock](https://github.com/treydock))
- Support opting out of tessen phone home [\#1101](https://github.com/sensu/sensu-puppet/pull/1101) ([treydock](https://github.com/treydock))

### Fixed

- Do not raise errors if custom puppet facts are undefined [\#1100](https://github.com/sensu/sensu-puppet/pull/1100) ([treydock](https://github.com/treydock))



Expand Down
9 changes: 3 additions & 6 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _Private Classes_

_Public Resource types_

* [`sensu_ad_auth`](#sensu_ad_auth): Manages Sensu AD auth. Requires valid enterprise license.
* [`sensu_ad_auth`](#sensu_ad_auth): Manages Sensu AD auth.
* [`sensu_api_validator`](#sensu_api_validator): Verify that a connection can be successfully established between a node and the sensu-backend server. Its primary use is as a precondition t
* [`sensu_asset`](#sensu_asset): Manages Sensu assets
* [`sensu_bonsai_asset`](#sensu_bonsai_asset): Manages Sensu Bonsai assets
Expand All @@ -44,10 +44,10 @@ _Public Resource types_
* [`sensu_filter`](#sensu_filter): Manages Sensu filters
* [`sensu_handler`](#sensu_handler): Manages Sensu handlers
* [`sensu_hook`](#sensu_hook): Manages Sensu hooks
* [`sensu_ldap_auth`](#sensu_ldap_auth): Manages Sensu LDAP auth. Requires valid enterprise license.
* [`sensu_ldap_auth`](#sensu_ldap_auth): Manages Sensu LDAP auth.
* [`sensu_mutator`](#sensu_mutator): Manages Sensu mutators
* [`sensu_namespace`](#sensu_namespace): Manages Sensu namespaces
* [`sensu_oidc_auth`](#sensu_oidc_auth): Manages Sensu OIDC auth. Requires valid enterprise license.
* [`sensu_oidc_auth`](#sensu_oidc_auth): Manages Sensu OIDC auth.
* [`sensu_plugin`](#sensu_plugin): Manages Sensu plugins
* [`sensu_postgres_config`](#sensu_postgres_config): Manages Sensu postgres config
* [`sensu_resources`](#sensu_resources): Metatype for sensu resources
Expand Down Expand Up @@ -1068,7 +1068,6 @@ Default value: {}
* `Service[sensu-backend]`
* `Sensuctl_configure[puppet]`
* `Sensu_api_validator[sensu]`
* `Exec[sensu-add-license]`

#### Examples

Expand Down Expand Up @@ -2529,7 +2528,6 @@ The name of the hook.
* `Service[sensu-backend]`
* `Sensuctl_configure[puppet]`
* `Sensu_api_validator[sensu]`
* `Exec[sensu-add-license]`

#### Examples

Expand Down Expand Up @@ -2758,7 +2756,6 @@ The name of the namespace.
* `Service[sensu-backend]`
* `Sensuctl_configure[puppet]`
* `Sensu_api_validator[sensu]`
* `Exec[sensu-add-license]`

#### Examples

Expand Down
17 changes: 17 additions & 0 deletions lib/puppet/provider/sensu_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,21 @@ def self.get_bonsai_asset(name)
def get_bonsai_asset(name)
self.class.get_bonsai_asset(name)
end
def self.get_bonsai_latest_version(namespace, name)
return nil if namespace.nil? || name.nil?
full_name = "#{namespace}/#{name}"
@latest_version = {} if @latest_version.nil?
return @latest_version[full_name] if @latest_version[full_name]
@latest_version[full_name] = nil
versions = []
bonsai_asset = Puppet::Provider::SensuAPI.get_bonsai_asset(full_name)
(bonsai_asset['versions'] || []).each do |bonsai_version|
version = bonsai_version['version']
next unless version =~ /^[0-9]/
versions << version
end
versions = versions.sort_by { |v| Gem::Version.new(v) }
@latest_version[full_name] = versions.last
@latest_version[full_name]
end
end
14 changes: 1 addition & 13 deletions lib/puppet/provider/sensu_bonsai_asset/sensu_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,7 @@ def self.prefetch(resources)
end

def self.latest_version(namespace, name)
return @latest_version if @latest_version
@latest_version = nil
return nil if namespace.nil? || name.nil?
versions = []
bonsai_asset = self.get_bonsai_asset("#{namespace}/#{name}")
(bonsai_asset['versions'] || []).each do |bonsai_version|
version = bonsai_version['version']
next unless version =~ /^[0-9]/
versions << version
end
versions = versions.sort_by { |v| Gem::Version.new(v) }
@latest_version = versions.last
@latest_version
get_bonsai_latest_version(namespace, name)
end

def exists?
Expand Down
14 changes: 1 addition & 13 deletions lib/puppet/provider/sensu_bonsai_asset/sensuctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,7 @@ def self.prefetch(resources)
end

def self.latest_version(namespace, name)
return @latest_version if @latest_version
@latest_version = nil
return nil if namespace.nil? || name.nil?
versions = []
bonsai_asset = Puppet::Provider::SensuAPI.get_bonsai_asset("#{namespace}/#{name}")
(bonsai_asset['versions'] || []).each do |bonsai_version|
version = bonsai_version['version']
next unless version =~ /^[0-9]/
versions << version
end
versions = versions.sort_by { |v| Gem::Version.new(v) }
@latest_version = versions.last
@latest_version
Puppet::Provider::SensuAPI.get_bonsai_latest_version(namespace, name)
end

def exists?
Expand Down
8 changes: 1 addition & 7 deletions lib/puppet/provider/sensu_command/sensuctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
def self.instances
commands = []

#TODO: Hack to force JSON format
# Fixed in https://github.com/sensu/sensu-go/pull/3495
current_format = config['format']
sensuctl(['config','set-format','json'])
data = sensuctl_list('command', false, false)
sensuctl(['config','set-format',current_format])

data = sensuctl_list('command', false)
data.each do |d|
command = {}
command[:ensure] = :present
Expand Down
10 changes: 3 additions & 7 deletions lib/puppet/provider/sensuctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,14 @@ def sensuctl(*args)
self.class.sensuctl(*args)
end

def self.sensuctl_list(command, namespaces = true, format = true)
def self.sensuctl_list(command, namespaces = true)
args = [command]
args << 'list'
if namespaces
args << '--all-namespaces'
end
#TODO: Making format optional is necessary to support sensuctl command list
# Fixed in https://github.com/sensu/sensu-go/pull/3495
if format
args << '--format'
args << 'json'
end
args << '--format'
args << 'json'
if ! chunk_size.nil?
args << '--chunk-size'
args << chunk_size.to_s
Expand Down
7 changes: 1 addition & 6 deletions lib/puppet/type/sensu_ad_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Puppet::Type.newtype(:sensu_ad_auth) do
desc <<-DESC
@summary Manages Sensu AD auth. Requires valid enterprise license.
@summary Manages Sensu AD auth.
@example Add a AD auth
sensu_ldap_auth { 'ad':
ensure => 'present',
Expand All @@ -33,7 +33,6 @@
* `Service[sensu-backend]`
* `Sensuctl_configure[puppet]`
* `Sensu_api_validator[sensu]`
* `Exec[sensu-add-license]`
DESC

extend PuppetX::Sensu::Type
Expand Down Expand Up @@ -222,10 +221,6 @@ def is_to_s(currentvalue)
desc 'The prefix added to all LDAP usernames.'
end

autorequire(:exec) do
[ 'sensu-add-license' ]
end

validate do
required_properties = [
:servers,
Expand Down
22 changes: 13 additions & 9 deletions lib/puppet/type/sensu_bonsai_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,19 @@ def should_to_s(newvalue)
# Generate sensu_asset resource to avoid resource purging deleting
# sensu_bonsai_asset resources
def generate
asset_opts = {}
asset_opts[:ensure] = self[:ensure]
asset_opts[:name] = "#{self[:rename]} in #{self[:namespace]}"
asset_opts[:namespace] = self[:namespace]
asset_opts[:require] = "Sensu_bonsai_asset[#{self[:name]}]"
asset_opts[:bonsai] = true
asset_opts[:provider] = self[:provider] if self[:provider]
asset = Puppet::Type.type(:sensu_asset).new(asset_opts)
[asset]
resources = []
if self[:ensure].to_s == 'present'
asset_opts = {}
asset_opts[:ensure] = self[:ensure]
asset_opts[:name] = "#{self[:rename]} in #{self[:namespace]}"
asset_opts[:namespace] = self[:namespace]
asset_opts[:require] = "Sensu_bonsai_asset[#{self[:name]}]"
asset_opts[:bonsai] = true
asset_opts[:provider] = self[:provider] if self[:provider]
asset = Puppet::Type.type(:sensu_asset).new(asset_opts)
resources << asset
end
resources
end

def self.title_patterns
Expand Down
7 changes: 1 addition & 6 deletions lib/puppet/type/sensu_ldap_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Puppet::Type.newtype(:sensu_ldap_auth) do
desc <<-DESC
@summary Manages Sensu LDAP auth. Requires valid enterprise license.
@summary Manages Sensu LDAP auth.
@example Add a LDAP auth
sensu_ldap_auth { 'openldap':
ensure => 'present',
Expand All @@ -33,7 +33,6 @@
* `Service[sensu-backend]`
* `Sensuctl_configure[puppet]`
* `Sensu_api_validator[sensu]`
* `Exec[sensu-add-license]`
DESC

extend PuppetX::Sensu::Type
Expand Down Expand Up @@ -216,10 +215,6 @@ def is_to_s(currentvalue)
desc 'The prefix added to all LDAP usernames.'
end

autorequire(:exec) do
[ 'sensu-add-license' ]
end

validate do
required_properties = [
:servers,
Expand Down
7 changes: 1 addition & 6 deletions lib/puppet/type/sensu_oidc_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Puppet::Type.newtype(:sensu_oidc_auth) do
desc <<-DESC
@summary Manages Sensu OIDC auth. Requires valid enterprise license.
@summary Manages Sensu OIDC auth.
@example Add an Active Directory auth
sensu_oidc_auth { 'oidc':
ensure => 'present',
Expand All @@ -26,7 +26,6 @@
* `Service[sensu-backend]`
* `Sensuctl_configure[puppet]`
* `Sensu_api_validator[sensu]`
* `Exec[sensu-add-license]`
DESC

extend PuppetX::Sensu::Type
Expand Down Expand Up @@ -89,10 +88,6 @@ def should_to_s(newvalue)
desc 'Scopes to include in the claims'
end

autorequire(:exec) do
[ 'sensu-add-license' ]
end

validate do
required_properties = [
:client_id,
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sensu-sensu",
"version": "4.2.0",
"version": "4.2.1",
"author": "sensu",
"summary": "A module to install the Sensu monitoring framework",
"license": "MIT",
Expand Down
7 changes: 7 additions & 0 deletions spec/acceptance/sensu_bonsai_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@

context 'install bonsai asset - latest' do
it 'should work without errors' do
# Define two assets as 'latest' using different providers
# to ensure the latest of each is used
# See https://github.com/sensu/sensu-puppet/pull/1202
pp = <<-EOS
include sensu::backend
sensu_bonsai_asset { 'sensu/sensu-pagerduty-handler':
ensure => 'present',
version => 'latest',
}
sensu_bonsai_asset { 'sensu/sensu-go-has-contact-filter':
ensure => 'present',
version => 'latest',
}
sensu_bonsai_asset { 'sensu/sensu-email-handler':
ensure => 'present',
version => 'latest',
Expand Down
10 changes: 2 additions & 8 deletions spec/unit/provider/sensu_command/sensuctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@
end

describe 'self.instances' do
before(:each) do
allow(provider).to receive(:config).and_return('format' => 'tabular')
allow(provider).to receive(:sensuctl).with(['config','set-format','json'])
allow(provider).to receive(:sensuctl).with(['config','set-format','tabular'])
end

it 'should create instances' do
allow(provider).to receive(:sensuctl_list).with('command', false, false).and_return(JSON.parse(my_fixture_read('list.json')))
allow(provider).to receive(:sensuctl_list).with('command', false).and_return(JSON.parse(my_fixture_read('list.json')))
expect(provider.instances.length).to eq(1)
end

it 'should return the resource for a command' do
allow(provider).to receive(:sensuctl_list).with('command', false, false).and_return(JSON.parse(my_fixture_read('list.json')))
allow(provider).to receive(:sensuctl_list).with('command', false).and_return(JSON.parse(my_fixture_read('list.json')))
property_hash = provider.instances[0].instance_variable_get("@property_hash")
expect(property_hash[:name]).to eq('command-test')
end
Expand Down
6 changes: 0 additions & 6 deletions spec/unit/provider/sensuctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
subject.sensuctl_list('namespace', false)
end

it 'should list a resource without all namespaces or json format' do
expected_args = ['command','list']
expect(subject).to receive(:sensuctl).with(expected_args).and_return("{}\n")
subject.sensuctl_list('command', false, false)
end

it 'should return empty array for null' do
allow(subject).to receive(:sensuctl).with(['check','list','--all-namespaces','--format','json']).and_return("null\n")
data = subject.sensuctl_list('check')
Expand Down
10 changes: 0 additions & 10 deletions spec/unit/sensu_ad_auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,6 @@
let(:res) { auth }
end

it 'should autorequire Exec[sensu-add-license]' do
exec = Puppet::Type.type(:exec).new(:name => 'sensu-add-license', :path => '/usr/bin')
catalog = Puppet::Resource::Catalog.new
catalog.add_resource auth
catalog.add_resource exec
rel = auth.autorequire[0]
expect(rel.source.ref).to eq(exec.ref)
expect(rel.target.ref).to eq(auth.ref)
end

[
:servers,
].each do |property|
Expand Down
Loading