Skip to content
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

env var for config file added #135

Closed
wants to merge 1 commit into from

Conversation

siddhikhapare
Copy link

@siddhikhapare siddhikhapare commented Jul 25, 2023

Overview

Use the CONFIG environment variable to load the config file, but it currently doesn't allow custom file paths. Kubevuln always defaults to searching for the config file in the /etc/config path, regardless of the CONFIG env value.

How to Test

Build kubevuln using make
Load config file using the CONFIG environment variable
export CONFIG=path/to/clusterData.json

Set the PORT environment variable to 8081
export PORT=8080

Related issues/PRs:

Resolved #129

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have commented on my code, particularly in hard-to-understand areas
  • I have performed a self-review of my code
  • If it is a core feature, I have added thorough tests.
  • New and existing unit tests pass locally with my changes

Signed-off-by: siddhikhapare <siddhikhapare77@gmail.com>
@@ -26,7 +26,12 @@ import (
func main() {
ctx := context.Background()

c, err := config.LoadConfig("/etc/config")
configPath := os.Getenv("CONFIG")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthyx what do you think is the proper solution here? Because we are thinking of having multiple configuration files...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, the goal is to split the config between component and cluster like in node-agent.

@dwertent
Copy link

dwertent commented Aug 3, 2023

/improve

Comment on lines +29 to +32
configPath := os.Getenv("CONFIG")
if configPath == "" {
configPath = "/etc/config"
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: It's a good practice to define default values as constants at the beginning of the file or package. This makes it easier to manage and change these values in the future.

Suggested change
configPath := os.Getenv("CONFIG")
if configPath == "" {
configPath = "/etc/config"
}
const defaultConfigPath = "/etc/config"
...
configPath := os.Getenv("CONFIG")
if configPath == "" {
configPath = defaultConfigPath
}

Comment on lines 35 to 37
if err != nil {
logger.L().Ctx(ctx).Fatal("load config error", helpers.Error(err))
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Error messages should be descriptive and provide context for easier debugging. Consider adding more information to the error message when the configuration file fails to load.

Suggested change
if err != nil {
logger.L().Ctx(ctx).Fatal("load config error", helpers.Error(err))
}
if err != nil {
logger.L().Ctx(ctx).Fatal("Failed to load config from path: "+configPath, helpers.Error(err))
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

@matthyx matthyx closed this Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[question] can't load config file using CONFIG env
3 participants