-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Wildcard support for x509_cert files #6952
Conversation
Fixes #6951 |
Would this also allow to add a complete dir?
|
Yes :) |
AWEsome, let's hope this get's merged quickly. I should be able to build it from 9309072 right? |
I just rebased master, resolved the merge conflict, it works :) |
Took a little bit to x-compile but i got r running. No strange things yet so thumbs up from me! Thx bud! |
Wow, this is exactly what we were looking to do - great work @jaroug ! @danielnelson - is there anything holding up the review of this other than time? |
It’s sad that it’s been all year since PR was created. Maybe there is something new or you just forgot about it. Very useful functions and features cannot be added for a whole year. Please, take a look, @danielnelson, @jaroug |
var allFiles []string | ||
|
||
for _, source := range c.Sources { | ||
if strings.HasPrefix(source, "/") { |
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 you should swap the order of processing and first call sourcesToURLs()
and afterwards this function. This way you can be sure that file always have file://
prepended. Otherwise you might miss files where the user added file://
already for you.
if strings.HasPrefix(source, "/") { | |
if strings.HasPrefix(source, "file://") { |
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.
the globing tools don't work with url styled path, so I'll have to strip the leading file://
if len(files) <= 0 { | ||
return fmt.Errorf("could not find file: %v", source) | ||
} | ||
allFiles = append(allFiles, files...) |
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.
Please remember to prepend file://
again here after swapping functions.
err := c.refreshFilePaths() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = c.sourcesToURLs() | ||
if err != nil { | ||
return err | ||
} | ||
|
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 it's better to swap these functions so refreshFilePaths()
(which might be called expandFilePaths()
) can work on normalized inputs as otherwise you miss entries where the user specified files in the form file:///etc/certs/*
.
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 suggest swapping the two functions in Init()
and work on normalized URLs instead of relying on the user not specifying file://
prefixed with wildcards. See my comments in the code.
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.
looks like it needs some merge conflicts resolved. Any additional test coverage would be great, but not a blocker.
@sjwang90 gonna have a look asap |
9309072
to
ee52ee5
Compare
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.
Looks good so far. Only one more question: You now moved the globbing to Init()
which means you won't catch new certs and maybe will poke old (already deleted) certs. Is this by intention? Maybe it would make sense to take the extra cycles and update the cert-list in every gather-cycle?!?
@srebhan it was requested by the previous person holding the PR: #6952 (comment) |
@jaroug almost, if you read the comment you cited carefully the idea was to prepare the glob-statement in |
@srebhan oh yeah ok, I totally misunderstood, my bad, I'll have a look asap |
Hi @jaroug, just checking on the status. We're hoping for a Telegraf 1.18 release candidate this week and would love to get this in. |
👋 I made those changes a bit in a hurry so it might be far from perfect but it seems to work. I haven't considered searching for globpath on "file://" inputs since I'm not sure it's supposed to be supported by the URL package, should I? |
*sees 'ready to merge' tag is this really happening ? 🤞 |
Well hopefully, poke @sjwang90 |
@jaroug and @ikkemaniac please stay calm and let the Influx guys do their job. It might take some more time due to the amount of PRs they have to handle and the way PRs are merged during the release cycle. So poking at this every second day takes away review resources (e.g. mine ;-))... |
Looks good, but i'd like to see some tests. also looks like the existing tests are failing in windows. |
} | ||
for _, file := range files { | ||
file = "file://" + file | ||
u, err := url.Parse(file) |
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.
Looks like this causes windows tests to fail, as it assumes the path is a linux-style path. On windows the path will start with C:
or something and it will recognize the colon as a port. A workaround for windows is adding an extra slash to the file://
part but it looks like there might be other issues (see: golang/go#13276). I'm thinking maybe we'd just need to manually handle the windows case here, not 100% sure but we will need it to work on windows.
Hi @jaroug, are you able/willing to fix this windows path problem? If not, let us know and we'll try to find someone who can. This PR is useful and I'd hate to see it stagnate again after getting so close to being merged! Thanks! |
* rename refreshFilePaths to expandFilePaths * expandFilePaths handles '/path/to/*.pem' and 'files:///path/to/*.pem' * update sample config
* add var globFilePathsToUrls to stack files path * add var globpaths to stack compiled globpath * rework sourcesToURLs to compile files path and stack them * rename expandFilePaths to expandFilePathsToUrls * rework expandFilePathsToUrls to only match compiled globpath * rework the `Gather` ticker to match globpath at each call
* add specifics regarding relative paths in sample config * add logger and use it in expandFilePathsToUrls() * precompile glob for `files://`, `/` and `://`
* rename expandFilePathsToUrls() to collectCertURLs() * collectCertURLs() now returns []*url.URL to avoid extra field globFilePathsToUrls in structure * update the Gather() ticker accordingly
…not supposed to be supported by the OS
2c66fc5
to
73e4b2b
Compare
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.
Looks like new artifacts were built from this PR. Get them here!
Artifact URLs
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.
Looks like new artifacts were built from this PR. Get them here!
Artifact URLs
* Accept standard unix glob matching rules * comply with indentation * update readme * move globing expand and url parsing into Init() * chore: rebase branch on upstream master * rename refreshFilePaths to expandFilePaths * expandFilePaths handles '/path/to/*.pem' and 'files:///path/to/*.pem' * update sample config * fix: recompile files globing pattern at every gather tic * add var globFilePathsToUrls to stack files path * add var globpaths to stack compiled globpath * rework sourcesToURLs to compile files path and stack them * rename expandFilePaths to expandFilePathsToUrls * rework expandFilePathsToUrls to only match compiled globpath * rework the `Gather` ticker to match globpath at each call * fix: comply with requested changes * add specifics regarding relative paths in sample config * add logger and use it in expandFilePathsToUrls() * precompile glob for `files://`, `/` and `://` * fix: update README to match last changes * fix: comply with last requested changes * rename expandFilePathsToUrls() to collectCertURLs() * collectCertURLs() now returns []*url.URL to avoid extra field globFilePathsToUrls in structure * update the Gather() ticker accordingly * fix(windows): do not try to compile glopath for windows path as it's not supposed to be supported by the OS * fix(ci): apply go fmt * fix(ci): empty-lines/import-shadowing Co-authored-by: Anthony LE BERRE <[email protected]>
This Pull seems to be the only change I can obviously find between v1.18.1 and v1.19.0 for x509_cert and I'm concerned it may have broken URL testing on Windows ? |
Required for all PRs:
Closes #6951