-
Notifications
You must be signed in to change notification settings - Fork 96
Add tokenpath parameter to collector #1077
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
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fefb0ed
Add tokenpath parameter to collector
john-david3 5eedb9e
Merge branch 'v3' into collector-tokenpath
john-david3 c7f48f7
Merge v3
john-david3 a57aa19
Merge branch 'main' into collector-tokenpath
john-david3 62493f0
PR feedback
john-david3 eb64183
PR feedback
john-david3 32a278c
Merge branch 'main' into collector-tokenpath
john-david3 44ca275
PR feedback
john-david3 3f7c081
check for empty filepath
john-david3 efbb0bc
Merge branch 'main' into collector-tokenpath
john-david3 794b548
update values method
john-david3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,9 @@ | |
package config | ||
|
||
import ( | ||
_ "embed" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path" | ||
"strings" | ||
|
@@ -631,6 +633,61 @@ func TestValidateYamlFile(t *testing.T) { | |
} | ||
} | ||
|
||
//go:embed testdata/nginx-agent-with-token.conf | ||
var agentConfigWithToken string | ||
|
||
func getAgentConfigWithToken(token string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be moved to |
||
return fmt.Sprintf(agentConfigWithToken, token) | ||
} | ||
|
||
func TestResolveExtensions(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
expected string | ||
}{ | ||
{ | ||
name: "Test 1: Header value is a valid token", | ||
input: "super-secret-token", | ||
expected: "super-secret-token", | ||
}, | ||
{ | ||
name: "Test 2: Header value is a valid token path", | ||
input: "testdata/nginx-token.crt", | ||
expected: "super-secret-token", | ||
}, | ||
{ | ||
name: "Test 3: Header value is empty", | ||
input: "", | ||
expected: "", | ||
}, | ||
} | ||
|
||
viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter)) | ||
tempDir := t.TempDir() | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tempFile := helpers.CreateFileWithErrorCheck(t, tempDir, "nginx-agent.conf") | ||
defer helpers.RemoveFileWithErrorCheck(t, tempFile.Name()) | ||
|
||
confContent := []byte(getAgentConfigWithToken(tt.input)) | ||
_, writeErr := tempFile.Write(confContent) | ||
require.NoError(t, writeErr) | ||
|
||
err := loadPropertiesFromFile(tempFile.Name()) | ||
require.NoError(t, err) | ||
|
||
extension := resolveExtensions() | ||
require.NotNil(t, extension) | ||
assert.Equal(t, tt.expected, extension.HeadersSetter.Headers[0].Value) | ||
|
||
err = tempFile.Close() | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func getAgentConfig() *Config { | ||
return &Config{ | ||
UUID: "", | ||
|
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,10 @@ | ||
log: | ||
level: info | ||
|
||
collector: | ||
extensions: | ||
headers_setter: | ||
headers: | ||
- action: insert | ||
key: "authorization" | ||
value: %s |
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 @@ | ||
super-secret-token |
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 |
---|---|---|
|
@@ -27,4 +27,3 @@ allowed_directories: | |
# token: "" | ||
# tls: | ||
# skip_verify: false | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a new FilePath field to the Header struct instead of putting file paths in the Value field.