Skip to content

Commit

Permalink
fix the inject_headers transpiler rule (elastic#27481)
Browse files Browse the repository at this point in the history
  • Loading branch information
faec authored Aug 19, 2021
1 parent 53d7c2e commit 4b442ce
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ output:
hosts:
- 127.0.0.1:9200
- 127.0.0.1:9300
headers:
h1: test-header
username: elastic
password: changeme
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ output:
hosts:
- 127.0.0.1:9200
- 127.0.0.1:9300
headers:
h1: test-header
username: elastic
password: changeme
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ fleet:
output:
elasticsearch:
hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ]
headers:
h1: test-header
username: fleet
password: fleetpassword

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ output:
hosts:
- 127.0.0.1:9200
- 127.0.0.1:9300
headers:
h1: test-header

namespace: test_namespace
username: elastic
password: changeme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ fleet:
output:
elasticsearch:
hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ]
headers:
h1: test-header
username: fleet
password: fleetpassword

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ metricbeat:
output:
elasticsearch:
hosts: [127.0.0.1:9200, 127.0.0.1:9300]
headers:
h1: test-header

namespace: test_namespace
username: elastic
password: changeme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ output:
hosts:
- 127.0.0.1:9200
- 127.0.0.1:9300
headers:
h1: test-header
username: elastic
password: changeme
bulk_max_size: 23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ fleet:
output:
elasticsearch:
hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ]
headers:
h1: test-header
username: fleet
password: fleetpassword

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ metricbeat:
output:
elasticsearch:
hosts: [127.0.0.1:9200, 127.0.0.1:9300]
headers:
h1: test-header
username: elastic
password: changeme
bulk_max_size: 23
Expand Down
4 changes: 2 additions & 2 deletions x-pack/elastic-agent/pkg/agent/transpiler/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1638,12 +1638,12 @@ func (r *InjectHeadersRule) Apply(agentInfo AgentInfo, ast *AST) (err error) {
return nil
}

outputsNode, found := Lookup(ast, "outputs")
outputNode, found := Lookup(ast, "output")
if !found {
return nil
}

elasticsearchNode, found := outputsNode.Find("elasticsearch")
elasticsearchNode, found := outputNode.Find("elasticsearch")
if found {
headersNode, found := elasticsearchNode.Find("headers")
if found {
Expand Down
8 changes: 4 additions & 4 deletions x-pack/elastic-agent/pkg/agent/transpiler/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ rest: of

"inject auth headers: no headers": {
givenYAML: `
outputs:
output:
elasticsearch:
hosts:
- "127.0.0.1:9201"
Expand All @@ -734,7 +734,7 @@ outputs:
port: 5
`,
expectedYAML: `
outputs:
output:
elasticsearch:
headers:
h1: test-header
Expand All @@ -753,7 +753,7 @@ outputs:

"inject auth headers: existing headers": {
givenYAML: `
outputs:
output:
elasticsearch:
headers:
sample-header: existing
Expand All @@ -764,7 +764,7 @@ outputs:
port: 5
`,
expectedYAML: `
outputs:
output:
elasticsearch:
headers:
sample-header: existing
Expand Down

0 comments on commit 4b442ce

Please sign in to comment.