-
Notifications
You must be signed in to change notification settings - Fork 154
Set provider config from ENV vars instead of plain text files #249
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
Set provider config from ENV vars instead of plain text files #249
Conversation
|
Found 2 different approaches to solve this issue:
The problem I'm facing is that the yaml decoder does not set boolean values in any of the following cases:
It always defaults to false. I've tried using both the std lib pkg and the yamlutil used in Nuclei. |
|
we can go with second approach.. // utils.go
func readProviderConfig(filepath string) (io.Reader, error) {
// Open the file
file, err := os.Open(filepath)
if err != nil {
return nil, err
}
defer file.Close()
// Create a scanner to read the file line by line
scanner := bufio.NewScanner(file)
// Create a string builder to accumulate the modified data
var sb strings.Builder
// Iterate over each line and do variable substitution
for scanner.Scan() {
line := scanner.Text()
newLine := substituteEnvVars(line)
sb.WriteString(newLine)
sb.WriteString("\n")
}
// Check for errors
if err := scanner.Err(); err != nil {
return nil, err
}
return strings.NewReader(sb.String()), nil
}
func substituteEnvVars(line string) string {
for _, word := range strings.Fields(line) {
word = strings.Trim(word, " \"")
if strings.HasPrefix(word, "$") {
key := strings.TrimPrefix(word, "$")
val := os.Getenv(key)
line = strings.ReplaceAll(line, word, val)
}
}
return line
}
reader, err := readProviderConfig(options.ProviderConfig)
if err != nil {
return nil, errors.Wrap(err, "could not open provider config file")
}
if parseErr := yaml.NewDecoder(reader).Decode(&providerOptions); parseErr != nil {
return nil, errors.Wrap(parseErr, "could not parse provider config file")
} |
|
…orks only with strings Signed-off-by: iamargus95 <[email protected]>
Signed-off-by: iamargus95 <[email protected]>
Signed-off-by: iamargus95 <[email protected]>
Signed-off-by: iamargus95 <[email protected]>
tarunKoyalwar
left a comment
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.
nice work @iamargus95 , lgtm ! verified locally and seems to work
ex config
cat ~/.config/notify/provider-config.yaml
discord:
- id: "crawl"
discord_channel: "crawl"
discord_username: "test"
discord_format: "{{data}}"
discord_webhook_url: "$DISCORD_WEBHOOK_URL"
|
@iamargus95 , since this is a generic implementation what do you think of creating new PR to move this function to https://github.com/projectdiscovery/utils/tree/main/file . that way we can extend this support to other projects Thanks |
Signed-off-by: iamargus95 <[email protected]>
|
@tarunKoyalwar |
tarunKoyalwar
left a comment
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.
@iamargus95 , since upstream pr projectdiscovery/utils#149 is merged now can you update this PR to use those helper utils
@tarunKoyalwar I think the latest release (v0.0.30) does not have the newly added helper function. Waiting for it to be added. |
|
Signed-off-by: iamargus95 <[email protected]>
Signed-off-by: iamargus95 <[email protected]>
|
Kudos, SonarCloud Quality Gate passed!
|








Here is the
config.yamlI used while testing locally.These are the export statements I used to set the ENV variables.