-
Notifications
You must be signed in to change notification settings - Fork 5k
Using specific pass for each host in redis output #16206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+213
−13
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0d9cb32
Using specific pass for each host in redis output
rvillablanca b88f2a7
Merge remote-tracking branch 'origin/master' into specific-password-r…
rvillablanca 02fb2b1
Partials advances parsing redis scheme
rvillablanca abb0df4
Validate tls config when schema is 'rediss'
rvillablanca 3f23756
Fix collition name with package url
rvillablanca 9ce4c41
* fix bug with host
rvillablanca 79ad5a2
More validations in url
rvillablanca a37d524
Merge remote-tracking branch 'origin/master' into specific-password-r…
rvillablanca b219e24
Merge remote-tracking branch 'origin/master' into specific-password-r…
rvillablanca 56cfc0e
Add some corrections
rvillablanca f8d1161
Merge remote-tracking branch 'origin/master' into specific-password-r…
rvillablanca 2d9e68b
Typo
rvillablanca 7e53c61
unit test and integration tests
rvillablanca 877f1fa
Merge remote-tracking branch 'origin/master' into specific-password-r…
rvillablanca ed763da
Fix redis output integration tests
rvillablanca 2296621
Minor improvements when testing redis output
rvillablanca 30a2bf0
Add license header
rvillablanca df66485
Add changes to changelog
rvillablanca 87106f9
Fix license header
rvillablanca 0bd9c96
Fix imports
rvillablanca 831348c
Formatting using make fmt update
rvillablanca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you under | ||
| // the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package redis | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/elastic/beats/libbeat/beat" | ||
| "github.com/elastic/beats/libbeat/common" | ||
| "github.com/elastic/beats/libbeat/outputs" | ||
| _ "github.com/elastic/beats/libbeat/outputs/codec/json" | ||
| ) | ||
|
|
||
| type checker func(*testing.T, outputs.Group) | ||
|
|
||
| func checks(cs ...checker) checker { | ||
| return func(t *testing.T, g outputs.Group) { | ||
| for _, c := range cs { | ||
| c(t, g) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func clientsLen(required int) checker { | ||
| return func(t *testing.T, group outputs.Group) { | ||
| assert.Len(t, group.Clients, required) | ||
| } | ||
| } | ||
|
|
||
| func clientPassword(index int, pass string) checker { | ||
| return func(t *testing.T, group outputs.Group) { | ||
| redisClient := group.Clients[index].(*backoffClient) | ||
| assert.Equal(t, redisClient.client.password, pass) | ||
| } | ||
| } | ||
|
|
||
| func TestMakeRedis(t *testing.T) { | ||
| tests := map[string]struct { | ||
| config map[string]interface{} | ||
| valid bool | ||
| checks checker | ||
| }{ | ||
|
rvillablanca marked this conversation as resolved.
|
||
| "no host": { | ||
| config: map[string]interface{}{ | ||
| "hosts": []string{}, | ||
| }, | ||
| }, | ||
| "invald scheme": { | ||
| config: map[string]interface{}{ | ||
| "hosts": []string{"redisss://localhost:6379"}, | ||
| }, | ||
| }, | ||
| "Single host": { | ||
| config: map[string]interface{}{ | ||
| "hosts": []string{"localhost:6379"}, | ||
| }, | ||
| valid: true, | ||
| checks: checks(clientsLen(1), clientPassword(0, "")), | ||
| }, | ||
| "Multiple hosts": { | ||
| config: map[string]interface{}{ | ||
| "hosts": []string{"redis://localhost:6379", "rediss://localhost:6380"}, | ||
| }, | ||
| valid: true, | ||
| checks: clientsLen(2), | ||
| }, | ||
| "Default password": { | ||
| config: map[string]interface{}{ | ||
| "hosts": []string{"redis://localhost:6379"}, | ||
| "password": "defaultPassword", | ||
| }, | ||
| valid: true, | ||
| checks: checks(clientsLen(1), clientPassword(0, "defaultPassword")), | ||
| }, | ||
| "Specific and default password": { | ||
| config: map[string]interface{}{ | ||
| "hosts": []string{"redis://localhost:6379", "rediss://:mypassword@localhost:6380"}, | ||
| "password": "defaultPassword", | ||
| }, | ||
| valid: true, | ||
| checks: checks( | ||
| clientsLen(2), | ||
| clientPassword(0, "defaultPassword"), | ||
| clientPassword(1, "mypassword"), | ||
| ), | ||
| }, | ||
| } | ||
| beatInfo := beat.Info{Beat: "libbeat", Version: "1.2.3"} | ||
| for name, test := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| cfg, err := common.NewConfigFrom(test.config) | ||
| assert.NoError(t, err) | ||
| groups, err := makeRedis(nil, beatInfo, outputs.NewNilObserver(), cfg) | ||
| assert.Equal(t, err == nil, test.valid) | ||
| if err != nil && test.valid { | ||
| t.Log(err) | ||
| } | ||
| if test.checks != nil { | ||
| test.checks(t, groups) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.