-
Notifications
You must be signed in to change notification settings - Fork 71
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
regex support for flag --secret-type:<type>:<regex> #243
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package internal | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
func unique(data []*certificateRef) []*certificateRef { | ||
output := []*certificateRef{} | ||
seen := map[string]bool{} | ||
|
@@ -13,3 +17,18 @@ func unique(data []*certificateRef) []*certificateRef { | |
|
||
return output | ||
} | ||
|
||
func getMatchingKeys(secretKeyValues map[string][]byte, pattern string) ([]string, error) { | ||
keys := make([]string, 0, len(secretKeyValues)) | ||
regex, err := regexp.Compile(pattern) | ||
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. Rather than compiling the regex on the fly, you should compile it just after flag and argument parsing, and store them as regexes in 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. Ok. Let me make the change |
||
if err != nil { | ||
return keys, err | ||
} | ||
|
||
for key := range secretKeyValues { | ||
if regex.MatchString(key) { | ||
keys = append(keys, key) | ||
} | ||
} | ||
return keys, nil | ||
} |
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.
In a cosmetic standpoint, this empty line could be removed.
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.
sure