-
Notifications
You must be signed in to change notification settings - Fork 274
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
Support for setting a custom database name. Closes #936 #988
Merged
Merged
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
74fdf03
refactor
binaek 229dab2
movement
binaek e2a1197
install_db_name env var
binaek 9c6fc41
removing redeclarations
binaek db793ee
pg_hba
binaek 72cdb03
fmt
binaek b147956
removing unused function
binaek 30ac07e
custom database name
binaek 39cb56f
acceptance test
binaek afdacd9
review iteration
binaek 0c22315
spacing
binaek 8b0d25e
remove commented code
binaek cc052d7
guerilla refactoring
kaidaguerre 21531ea
log collection channel refactor
binaek bd341a9
refactor service installation to be independent
binaek 869c6be
xtra srgs
binaek d93ed5d
refactor
binaek 8adbbc7
refactor
binaek 701dcba
env var
binaek 6826abc
env var
binaek 2304587
env var test
binaek 43428e8
env var test
binaek c9aa75b
remove need for passing empty string to createLocalDbClient. Tidying.
kaidaguerre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,18 +24,25 @@ func getLocalSteampipeConnectionString() (string, error) { | |
} | ||
|
||
// Connect to the database using the first listen address, which is usually localhost | ||
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s dbname=%s sslmode=%s", info.Listen[0], info.Port, constants.DatabaseUser, constants.DatabaseName, SslMode()) | ||
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s dbname=%s sslmode=%s", info.Listen[0], info.Port, constants.DatabaseUser, info.Database, SslMode()) | ||
|
||
return psqlInfo, nil | ||
} | ||
|
||
// createRootDbClient connects as a superuser to the | ||
// installed database, if available, otherwise to the default | ||
// "postgres" database | ||
func createRootDbClient() (*sql.DB, error) { | ||
utils.LogTime("db.createSteampipeRootDbClient start") | ||
defer utils.LogTime("db™.createSteampipeRootDbClient 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. were you going to factor this out? I hate passing the empty name to createLocalDbClient |
||
return createLocalDbClient(constants.DatabaseName, constants.DatabaseSuperUser) | ||
return createLocalDbClient("", constants.DatabaseSuperUser) | ||
kaidaguerre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// createLocalDbClient connects and returns a connection to the given database using | ||
// the provided username | ||
// if the database is not provided, then it fallsback to the default database in the service | ||
// that was created during installation. | ||
func createLocalDbClient(dbname string, username string) (*sql.DB, error) { | ||
utils.LogTime("db.createDbClient start") | ||
defer utils.LogTime("db.createDbClient end") | ||
|
@@ -50,6 +57,14 @@ func createLocalDbClient(dbname string, username string) (*sql.DB, error) { | |
return nil, fmt.Errorf("steampipe service is not running") | ||
} | ||
|
||
if len(dbname) == 0 { | ||
dbname = info.Database | ||
} | ||
// if we still don't have it, fallback to default "postgres" | ||
if len(dbname) == 0 { | ||
dbname = "postgres" | ||
} | ||
|
||
// Connect to the database using the first listen address, which is usually localhost | ||
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s dbname=%s sslmode=%s", info.Listen[0], info.Port, username, dbname, SslMode()) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why do we have STEAMPIPE_INSTALL_DATABASE and STEAMPIPE_DATABASE?
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.
STEAMPIPE_DATABASE
is used by theremote connection
layer to connect to Steampipe Cloud, using theAPI_KEY