Showing with 432 additions and 180 deletions.
  1. +9 −5 CHANGELOG.md
  2. +4 −8 README.md
  3. +75 −3 REFERENCE.md
  4. +31 −33 lib/puppet/provider/sensu_agent_entity_config/sensu_api.rb
  5. +32 −3 lib/puppet/provider/sensu_api.rb
  6. +20 −0 lib/puppet/provider/sensu_oidc_auth/sensu_api.rb
  7. +20 −0 lib/puppet/provider/sensu_oidc_auth/sensuctl.rb
  8. +30 −0 lib/puppet/provider/sensu_postgres_config/sensuctl.rb
  9. +24 −0 lib/puppet/provider/sensuctl.rb
  10. +5 −6 lib/puppet/type/sensu_agent_entity_config.rb
  11. +1 −1 lib/puppet/type/sensu_check.rb
  12. +6 −0 lib/puppet/type/sensu_oidc_auth.rb
  13. +27 −0 lib/puppet/type/sensu_postgres_config.rb
  14. +3 −2 lib/puppet_x/sensu/agent_entity_config.rb
  15. +4 −9 manifests/agent.pp
  16. +16 −21 manifests/agent/annotation.pp
  17. +16 −21 manifests/agent/label.pp
  18. +1 −1 manifests/agent/subscription.pp
  19. +12 −0 manifests/backend.pp
  20. +7 −3 manifests/backend/datastore/postgresql.pp
  21. +1 −1 metadata.json
  22. +6 −48 spec/acceptance/01_agent_spec.rb
  23. +1 −1 spec/acceptance/06_postgresql_spec.rb
  24. +1 −0 spec/acceptance/windows_spec.rb
  25. +6 −0 spec/classes/agent_spec.rb
  26. +7 −3 spec/classes/backend_datastore_postgresql_spec.rb
  27. +0 −4 spec/defines/agent_annotation_spec.rb
  28. +0 −4 spec/defines/agent_label_spec.rb
  29. +18 −0 spec/unit/provider/sensu_api_spec.rb
  30. +2 −0 spec/unit/provider/sensu_oidc_auth/sensu_api_spec.rb
  31. +2 −0 spec/unit/provider/sensu_oidc_auth/sensuctl_spec.rb
  32. +12 −1 spec/unit/provider/sensu_postgres_config/sensuctl_spec.rb
  33. +18 −0 spec/unit/provider/sensuctl_spec.rb
  34. +2 −1 spec/unit/sensu_check_spec.rb
  35. +2 −0 spec/unit/sensu_oidc_auth_spec.rb
  36. +11 −1 spec/unit/sensu_postgres_config_spec.rb
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [v5.1.0](https://github.com/sensu/sensu-puppet/tree/v5.1.0) (2020-10-08)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v5.0.0...v5.1.0)

### Added

- Support Sensu Go 6.1 [\#1274](https://github.com/sensu/sensu-puppet/pull/1274) ([treydock](https://github.com/treydock))

## [v5.0.0](https://github.com/sensu/sensu-puppet/tree/v5.0.0) (2020-09-08)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v4.13.1...v5.0.0)
Expand Down Expand Up @@ -118,7 +126,6 @@

- Allow agents to have subscriptions defined as a resource [\#1227](https://github.com/sensu/sensu-puppet/pull/1227) ([treydock](https://github.com/treydock))
- Support bonsai version with v prefix [\#1223](https://github.com/sensu/sensu-puppet/pull/1223) ([treydock](https://github.com/treydock))
- Manage license through sensu\_license type [\#1218](https://github.com/sensu/sensu-puppet/pull/1218) ([treydock](https://github.com/treydock))

### Fixed

Expand All @@ -135,6 +142,7 @@

### Added

- Manage license through sensu\_license type [\#1218](https://github.com/sensu/sensu-puppet/pull/1218) ([treydock](https://github.com/treydock))
- Add more examples [\#1214](https://github.com/sensu/sensu-puppet/pull/1214) ([treydock](https://github.com/treydock))
- Better organization of class variables [\#1213](https://github.com/sensu/sensu-puppet/pull/1213) ([treydock](https://github.com/treydock))
- Better documentation of private types [\#1212](https://github.com/sensu/sensu-puppet/pull/1212) ([treydock](https://github.com/treydock))
Expand Down Expand Up @@ -269,10 +277,6 @@

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

### Fixed

- Document sensu\_asset deprecations [\#1170](https://github.com/sensu/sensu-puppet/pull/1170) ([treydock](https://github.com/treydock))

## [v3.10.0](https://github.com/sensu/sensu-puppet/tree/v3.10.0) (2019-10-31)

[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v3.9.0...v3.10.0)
Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ Please log an issue if you identify any incompatibilities.
| --------------- | ----------------------------------- |
| 5.0 - 5.15 | latest v3 |
| 5.16+ | latest v4 |
| 6.0+ | latest v5 |
| 6.0 | v5.0.0 |
| 6.1+ | v5.1.0+

### Upgrade note

Sensu Go 5.x is a rewrite of Sensu and no longer depends on redis and rabbitmq.
Version 3 of this module supports Sensu Go >= 5.0.0 to < 5.16.0.
Version 4 of this module supports Sensu Go >= 5.16.0 < 6.0.0.
Version 5 of this module supports Sensu Go >= 6.0.0 < 7.0.0.
Version 5.0.0 of this module supports Sensu Go >= 6.0.0 < 6.1.0.
Version 5.1.0+ of this module supports Sensu Go >= 6.1.0 < 7.0.0.

Users wishing to use the previous Ruby based Sensu should use the [sensu/sensuclassic](https://forge.puppet.com/sensu/sensuclassic) module.

Expand Down Expand Up @@ -106,8 +108,6 @@ See [API Providers](#api-providers) for example Hiera that can be used in a file
This module will still continue to write subscriptions and other agent configurations to `agent.yml` so that if an agent entity is deleted it can be recreated
by restarting the `sensu-agent` service.

**NOTE**: At this time redaction of labels or annotations is not supported and will cause this module to produce errors. See [limitations](#limitations) for details.

### Updating this module from 3.x to 4.x

Class parameter changes:
Expand Down Expand Up @@ -1212,10 +1212,6 @@ Examples can be found in the [examples](https://github.com/sensu/sensu-puppet/tr

## Limitations

Sensu Go 6 support of this module can not support redacted labels or annotations due to how agent entity API calls are made.
At this time this module will produce errors if redacted labels or annotations are encountered.
See [sensu-go#3955](https://github.com/sensu/sensu-go/issues/3955) for details on this issue.

The type `sensu_user` does not at this time support `ensure => absent` due to a limitation with sensuctl, see [sensu-go#2540](https://github.com/sensu/sensu-go/issues/2540).

When changing the `sensu::password` value, it's necessary to run Puppet on the backend first to update the `admin` password.
Expand Down
78 changes: 75 additions & 3 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,14 @@ Default value: `'default'`

##### `redact`

Data type: `Optional[Array[String[1]]]`
Data type: `Array[String[1]]`

The agent entity redact list
Passing `redact` as part of `config_hash` takes precedence
Defaults come from Sensu documentation:
https://docs.sensu.io/sensu-go/latest/reference/agent/#security-configuration-flags

Default value: ``undef``
Default value: `['password','passwd','pass','api_key','api_token','access_key','secret_key','private_key','secret']`

##### `show_diff`

Expand Down Expand Up @@ -846,6 +846,38 @@ The PostgreSQL pool size

Default value: `20`

##### `postgresql_strict`

Data type: `Boolean`

Enables strict configuration checks for PostgreSQL

Default value: ``false``

##### `postgresql_batch_buffer`

Data type: `Integer`

PostgreSQL batch buffer size

Default value: `0`

##### `postgresql_batch_size`

Data type: `Integer`

PostgreSQL batch size

Default value: `1`

##### `postgresql_batch_workers`

Data type: `Integer`

PostgreSQL batch workers

Default value: `20`

### `sensu::cli`

Class to manage the Sensu CLI.
Expand Down Expand Up @@ -2235,7 +2267,7 @@ Default value: `default`

##### `output_metric_format`

Valid values: `nagios_perfdata`, `graphite_plaintext`, `influxdb_line`, `opentsdb_line`, `absent`
Valid values: `nagios_perfdata`, `graphite_plaintext`, `influxdb_line`, `opentsdb_line`, `prometheus_text`, `absent`

The metric format generated by the check command.

Expand Down Expand Up @@ -3605,6 +3637,14 @@ The OIDC provider application "Client ID"

The OIDC provider application "Client Secret"

##### `disable_offline_access`

Valid values: ``true``, ``false``

Sets if OIDC provider can include the offline_access scope

Default value: `false`

##### `ensure`

Valid values: `present`, `absent`
Expand Down Expand Up @@ -3767,6 +3807,28 @@ sensu_postgres_config { 'puppet':

The following properties are available in the `sensu_postgres_config` type.

##### `batch_buffer`

Valid values: `/^[0-9]+$/`

Maximum number of requests to buffer in memory.

Default value: `0`

##### `batch_size`

Valid values: `/^[0-9]+$/`

Number of requests in each PostgreSQL write transaction

Default value: `1`

##### `batch_workers`

Valid values: `/^[0-9]+$/`

Number of requests in each PostgreSQL write transaction, defaults to value for pool_size

##### `dsn`

Use the dsn attribute to specify the data source names as a URL or PostgreSQL connection string
Expand All @@ -3785,6 +3847,16 @@ Valid values: `/^[0-9]+$/`

The maximum number of connections to hold in the PostgreSQL connection pool

Default value: `0`

##### `strict`

Valid values: ``true``, ``false``

Perform configuration validation when configuring this resource

Default value: `false`

#### Parameters

The following parameters are available in the `sensu_postgres_config` type.
Expand Down
64 changes: 31 additions & 33 deletions lib/puppet/provider/sensu_agent_entity_config/sensu_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,51 +128,49 @@ def initialize(value = {})
end

def update(add = true)
entity = get_entity(resource[:entity], resource[:namespace], api_opts)
redacted = PuppetX::Sensu::AgentEntityConfig.check_redacted(entity)
if redacted
raise Puppet::Error, "Sensu_agent_entity_config[#{resource[:name]}]: Unable to manage resource, REDACTED values detected"
end
config = resource[:config]
if PuppetX::Sensu::AgentEntityConfig.metadata_configs.include?(config)
obj = entity['metadata'][config]
config_class = PuppetX::Sensu::AgentEntityConfig.config_classes[config]
case config_class
when Hash
value = add ? resource[:value] : nil
obj = {resource[:key] => value}
else
obj = entity[config]
end
case PuppetX::Sensu::AgentEntityConfig.config_classes[config]
when Array
if add && obj.nil?
obj = []
end
if add
obj << resource[:value]
data = get_entity(resource[:entity], resource[:namespace], api_opts)
obj = data[config]
case config_class
when Array
obj = [] if add && obj.nil?
if add
obj << resource[:value]
else
obj.delete(resource[:value])
end
else
obj.delete(resource[:value])
obj = add ? resource[:value] : ""
end
when Hash
if add && obj.nil?
obj = {}
end
if add
obj[resource[:key]] = resource[:value]
end
if version_cmp('6.1.0')
method = 'patch'
entity = {}
if PuppetX::Sensu::AgentEntityConfig.metadata_configs.include?(config)
entity['metadata'] = {}
entity['metadata'][config] = obj
else
obj.delete(resource[:key])
entity[config] = obj
end
else
if add
obj = resource[:value]
method = 'put'
entity = get_entity(resource[:entity], resource[:namespace], api_opts)
if PuppetX::Sensu::AgentEntityConfig.metadata_configs.include?(config)
entity['metadata'][config] = {} if entity['metadata'][config].nil?
entity['metadata'][config][obj.keys[0]] = obj.values[0]
else
obj = ""
entity[config] = obj
end
end
if PuppetX::Sensu::AgentEntityConfig.metadata_configs.include?(config)
entity['metadata'][config] = obj
else
entity[config] = obj
end
opts = {
:namespace => resource[:namespace],
:method => 'put',
:method => method,
}
api_request("entities/#{resource[:entity]}", entity, api_opts.merge(opts))
end
Expand Down
35 changes: 32 additions & 3 deletions lib/puppet/provider/sensu_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,23 @@ def self.api_request(path, data = nil, opts = {})
request = Net::HTTP::Post.new(uri.path)
elsif method == 'put'
request = Net::HTTP::Put.new(uri.path)
elsif method == 'patch'
request = Net::HTTP::Patch.new(uri.path)
elsif method == 'delete'
request = Net::HTTP::Delete.new(uri.path)
end
# Add data for POST and PUT
if ['post','put'].include?(method)
# Add data for POST, PUT, and PATCH
if ['post','put','patch'].include?(method)
Puppet.debug("BODY: #{data.to_json}")
request.body = data.to_json unless data.nil?
end
# Add headers
request.add_field("Accept", "application/json") if defined?(request) && !request.nil?
request.add_field("Content-Type", "application/json") if defined?(request) && !request.nil?
if method == 'patch'
request.add_field("Content-Type", "application/merge-patch+json") if defined?(request) && !request.nil?
else
request.add_field("Content-Type", "application/json") if defined?(request) && !request.nil?
end
# Add either token or basic auth
if token.nil? && username && password && opts[:auth] != false
Puppet.debug("Sensu API: Using basic auth of #{username}:#{password}")
Expand Down Expand Up @@ -237,6 +243,29 @@ def auth_test(*args)
self.class.auth_test(*args)
end

def self.version
data = api_request('/version', nil, {:failonfail => false})
rescue Exception => e
Puppet.notice "Unable to query Sensu API version: #{e.message}"
return nil
else
return data.fetch('sensu_backend', nil)
end
def version
self.class.version
end

def self.version_cmp(v)
if @current_version.nil?
@current_version = version
end
return true if @current_version.nil?
return Gem::Version.new(@current_version) >= Gem::Version.new(v)
end
def version_cmp(*args)
self.class.version_cmp(*args)
end

def self.get_bonsai_asset(name)
opts = {
:url => 'https://bonsai.sensu.io'
Expand Down
20 changes: 20 additions & 0 deletions lib/puppet/provider/sensu_oidc_auth/sensu_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

mk_resource_methods

def min_version
{
disable_offline_access: '6.1.0',
}
end

def self.instances
auths = []

Expand Down Expand Up @@ -62,6 +68,13 @@ def create
value = resource[property]
next if value.nil?
next if value == :absent || value == [:absent]
if min_version.key?(property)
v = min_version[property]
if ! version_cmp(v)
Puppet.warning("Sensu_oidc_auth[#{resource[:name]}] Property #{property} skipped, does not meet minimum Sensu Go version of #{v}")
next
end
end
if [:true, :false].include?(value)
value = convert_boolean_property_value(value)
end
Expand Down Expand Up @@ -92,6 +105,13 @@ def flush
value = resource[property]
end
next if value.nil?
if min_version.key?(property)
v = min_version[property]
if ! version_cmp(v)
Puppet.warning("Sensu_oidc_auth[#{resource[:name]}] Property #{property} skipped, does not meet minimum Sensu Go version of #{v}")
next
end
end
if [:true, :false].include?(value)
value = convert_boolean_property_value(value)
elsif value == :absent
Expand Down
Loading