Skip to content

Commit 24ec4c0

Browse files
authored
Merge pull request #976 from tylerjl/pipeline-json-types
Fix pipeline json types
2 parents c8bdc89 + 7244e4b commit 24ec4c0

File tree

8 files changed

+95
-2
lines changed

8 files changed

+95
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## x.x.x (Month Day, Year)
22

33
#### Fixes
4+
* Fix an issue with string coercion for certain fields in pipelines.
45

56
#### Features
67

lib/puppet_x/elastic/deep_to_s.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def self.deep_to_s(obj)
1010
obj.map { |element| deep_to_s(element) }
1111
elsif obj.is_a? Hash
1212
obj.merge(obj) { |_key, val| deep_to_s(val) }
13-
elsif (not obj.is_a? String) and obj.respond_to? :to_s
13+
elsif (not obj.is_a? String) and (not [true, false].include?(obj)) and obj.respond_to? :to_s
1414
obj.to_s
1515
else
1616
obj

spec/acceptance/tests/acceptance_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'helpers/acceptance/tests/basic_shared_examples.rb'
33
require 'helpers/acceptance/tests/template_shared_examples.rb'
44
require 'helpers/acceptance/tests/removal_shared_examples.rb'
5+
require 'helpers/acceptance/tests/pipeline_shared_examples.rb'
56
require 'helpers/acceptance/tests/plugin_shared_examples.rb'
67
require 'helpers/acceptance/tests/plugin_upgrade_shared_examples.rb'
78
require 'helpers/acceptance/tests/snapshot_repository_shared_examples.rb'
@@ -89,6 +90,8 @@
8990

9091
include_examples('template operations', es_01, v[:template])
9192

93+
include_examples('pipeline operations', es_01, v[:pipeline]) if semver(v[:elasticsearch_full_version]) >= semver('5.0.0')
94+
9295
include_examples('plugin acceptance tests', v[:elasticsearch_plugins]) unless v[:elasticsearch_plugins].empty?
9396

9497
# Only pre-5.x versions supported versions differing from core ES
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"description": "An example pipeline.",
3+
"on_failure": [
4+
{
5+
"set": {
6+
"field": "error",
7+
"value": "{{ _ingest.on_failure_message }}"
8+
}
9+
}
10+
],
11+
"processors": [
12+
{
13+
"grok": {
14+
"field": "message",
15+
"ignore_missing": true,
16+
"patterns": [
17+
"%{COMBINEDAPACHELOG}"
18+
]
19+
}
20+
},
21+
{
22+
"remove": {
23+
"field": "message"
24+
}
25+
},
26+
{
27+
"date": {
28+
"field": "read_timestamp",
29+
"formats": [
30+
"dd/MMM/YYYY:H:m:s Z"
31+
],
32+
"target_field": "@timestamp"
33+
}
34+
},
35+
{
36+
"remove": {
37+
"field": "read_timestamp"
38+
}
39+
},
40+
{
41+
"script": {
42+
"lang": "painless",
43+
"source": "ctx._index = 'foo';"
44+
}
45+
}
46+
]
47+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'json'
2+
require 'helpers/acceptance/tests/manifest_shared_examples'
3+
require 'helpers/acceptance/tests/bad_manifest_shared_examples'
4+
5+
shared_examples 'pipeline operations' do |instances, pipeline|
6+
describe 'pipeline resources' do
7+
let(:pipeline_name) { 'foo' }
8+
context 'present' do
9+
let(:extra_manifest) do
10+
<<-MANIFEST
11+
elasticsearch::pipeline { '#{pipeline_name}':
12+
ensure => 'present',
13+
content => #{pipeline}
14+
}
15+
MANIFEST
16+
end
17+
18+
include_examples(
19+
'manifest application',
20+
instances
21+
)
22+
23+
context 'absent' do
24+
let(:extra_manifest) do
25+
<<-MANIFEST
26+
elasticsearch::template { '#{pipeline_name}':
27+
ensure => absent,
28+
}
29+
MANIFEST
30+
end
31+
32+
include_examples(
33+
'manifest application',
34+
instances
35+
)
36+
end
37+
end
38+
end
39+
end

spec/helpers/unit/type/elasticsearch_rest_shared_examples.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
:name => resource_name,
6969
meta_property => { 'key' => { 'value' => '0', 'other' => true } }
7070
)[meta_property]).to include(
71-
'key' => { 'value' => 0, 'other' => 'true' }
71+
'key' => { 'value' => 0, 'other' => true }
7272
)
7373
end
7474
end

spec/spec_helper_acceptance.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def f
3333
JSON.load(File.new('spec/fixtures/templates/post_6.0.json'))
3434
end
3535
v[:template] = Puppet_X::Elastic.deep_to_i(Puppet_X::Elastic.deep_to_s(v[:template]))
36+
v[:pipeline] = JSON.load(File.new('spec/fixtures/pipelines/example.json'))
3637

3738
v[:elasticsearch_plugins] = Dir[
3839
artifact("*#{v[:elasticsearch_full_version]}.zip", ['plugins'])

spec/unit/type/elasticsearch_template_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def deep_stringify(obj)
109109
obj.map { |element| deep_stringify(element) }
110110
elsif obj.is_a? Hash
111111
obj.merge(obj) { |_key, val| deep_stringify(val) }
112+
elsif [true, false].include? obj
113+
obj
112114
else
113115
obj.to_s
114116
end

0 commit comments

Comments
 (0)