-
Notifications
You must be signed in to change notification settings - Fork 265
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
[DBConnector]: Add database config env support #345
base: master
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -27,7 +27,14 @@ void SonicDBConfig::initialize(const string &file) | |
throw runtime_error("SonicDBConfig already initialized"); | ||
} | ||
|
||
ifstream i(file); | ||
string filename = file; | ||
if ( filename == "" ) | ||
{ | ||
const auto env = getenv(SONIC_DB_CONFIG_FILE_ENV_VAL); | ||
filename = env ? string(env) : DEFAULT_SONIC_DB_CONFIG_FILE; | ||
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.
FYI: no need to explicit convert 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.
Add some testcases? |
||
} | ||
|
||
ifstream i(filename); | ||
if (i.good()) | ||
{ | ||
try | ||
|
@@ -68,8 +75,8 @@ void SonicDBConfig::initialize(const string &file) | |
} | ||
else | ||
{ | ||
SWSS_LOG_ERROR("Sonic database config file doesn't exist at %s\n", file.c_str()); | ||
throw runtime_error("Sonic database config file doesn't exist at " + file); | ||
SWSS_LOG_ERROR("Sonic database config file doesn't exist at %s\n", filename.c_str()); | ||
throw runtime_error("Sonic database config file doesn't exist at " + filename); | ||
} | ||
} | ||
|
||
|
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.