-
Notifications
You must be signed in to change notification settings - Fork 48
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
Uses environment variables as fallback when no config file is used. #35
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 |
---|---|---|
|
@@ -93,12 +93,16 @@ def initialize(configFile) | |
@password = @config["icinga2"]["api"]["password"] | ||
@pkiPath = @config["icinga2"]["api"]["pki_path"] | ||
else | ||
@log.warn(sprintf('Config file %s not found! Using default config.', configFile)) | ||
@host = "localhost" | ||
@port = 5665 | ||
@user = "dashing" | ||
@password = "icinga2ondashingr0xx" | ||
@log.warn(sprintf('Config file %s not found. Using ENV vars.', configFile)) | ||
@host = ENV['ICINGA_API_HOST'] | ||
@port = ENV['ICINGA_API_PORT'] | ||
@user = ENV['ICINGA_API_USER'] | ||
@password = ENV['ICINGA_API_PASSWORD'] | ||
@pkiPath = "pki/" | ||
|
||
if [@host, @port, @user, @password].all? {|value| value.nil? or value == ""} | ||
raise ArgumentError.new('No config file or env var found!') | ||
end | ||
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. That looks good to me :) 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. my actual prefer handling are the handling of configuration or environment vars should be located outside of a library. but the code above are okay :) 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. I agreed we should move it into a separate file. Do we need to do this now or we can create an issue to understand better how we should implement this? |
||
end | ||
|
||
@apiVersion = "v1" # TODO: allow user to configure version? | ||
|
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.
Mh, I prefer to have a defined configuration in place, although I understand the idea. This should be discussed in a separate issue imho, to move the configuration into a sample.
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.
If the user follows the documentation and moves the sample file, everything should work as expected, keeping the backward compatibility.
If we don't want to touch the config file right now, we can invert the order and use the config file as fallback in the case we didn't set the env vars. What do you think?
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.
Users don't follow the docs, they start right away. That's my main concern.