-
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
Conversation
0ec5c6f
to
9c6fc41
Compare
db/db_local/install.go
Outdated
} | ||
|
||
func installSteampipeDatabaseAndUser(steampipePassword string, rootPassword string) error { | ||
func installDatabaseAndSetupPermissions() (string, error) { |
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.
comment explaining what the return values are
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.
In fact I'd be tempted to pull out the database name logic and pass the name in from the calling code
functions should do 1 thing where possible
db/db_local/install.go
Outdated
} | ||
|
||
func installForeignServer() error { | ||
func installForeignServer(dbName string) error { |
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.
dbName -> databaseName
db/db_local/install.go
Outdated
} | ||
return sig | ||
} | ||
// func getInstalledBinarySignature() string { |
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.
can we delete this?
db/db_local/start_database.go
Outdated
@@ -142,7 +142,7 @@ func StartDB(port int, listen StartListenType, invoker constants.Invoker) (start | |||
|
|||
// startPostgresProcessAndSetPassword starts the postgres process and writes out the state file | |||
// after it is convinced that the process is started and is accepting connections | |||
func startPostgresProcessAndSetPassword(port int, listen StartListenType, invoker constants.Invoker) (e error) { | |||
func startPostgresProcessAndSetPassword(port int, listen StartListenType, invoker constants.Invoker) (datName string, e error) { |
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 need named parameters?
db/db_local/start_database.go
Outdated
} | ||
|
||
err = postgresCmd.Process.Release() | ||
if err != nil { | ||
postgresCmd.Process.Kill() | ||
return err | ||
return "", err |
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.
what is this doing? add comment
postgresCmd.Process.Release()
db/db_local/start_database.go
Outdated
} | ||
|
||
// connect to the service and retrieve the database name | ||
datName, err = retrieveDatabaseNameFromService(invoker) |
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.
databaseName
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.
and please use this consistently
db/db_local/start_database.go
Outdated
@@ -142,7 +142,7 @@ func StartDB(port int, listen StartListenType, invoker constants.Invoker) (start | |||
|
|||
// startPostgresProcessAndSetPassword starts the postgres process and writes out the state file | |||
// after it is convinced that the process is started and is accepting connections | |||
func startPostgresProcessAndSetPassword(port int, listen StartListenType, invoker constants.Invoker) (e error) { | |||
func startPostgresProcessAndSetPassword(port int, listen StartListenType, invoker constants.Invoker) (datName string, e error) { | |||
utils.LogTime("startPostgresProcess start") | |||
defer utils.LogTime("startPostgresProcess end") |
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.
I think this function should read as follows: (with error handling of course)
func startPostgresAndSetPassword(port int, listen StartListenType, invoker constants.Invoker) (string, error) {
process, err := startPostgreProcess(port, listen, invoker)
databaseName, err = retrieveDatabaseName()
err := setPassword()
}
}
constants/env.go
Outdated
@@ -5,6 +5,7 @@ const ( | |||
EnvUpdateCheck = "STEAMPIPE_UPDATE_CHECK" | |||
EnvInstallDir = "STEAMPIPE_INSTALL_DIR" | |||
EnvConnectionString = "STEAMPIPE_CONNECTION_STRING" | |||
EnvInstallDatabase = "STEAMPIPE_INSTALL_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.
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 the remote connection
layer to connect to Steampipe Cloud, using the API_KEY
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.
getting there
_, err := executeSqlAsRoot(statements...) | ||
|
||
for _, statement := range statements { | ||
// NOTE: This may print a password to the log file, but it doesn't matter |
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.
I'm not sure I agree that it doesn't matter - can we do anything about this?
db/db_local/start_database.go
Outdated
// after it is convinced that the process is started and is accepting connections | ||
func startPostgresProcessAndSetPassword(port int, listen StartListenType, invoker constants.Invoker) (e error) { | ||
func startPostgresProcessAndSetup(port int, listen StartListenType, invoker constants.Invoker) (databaseName string, e error) { |
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.
e -> err
db/db_local/create_client.go
Outdated
|
||
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 comment
The 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
db/db_local/start_database.go
Outdated
} | ||
}() | ||
// release the process - let the OS adopt it, so that we can exit | ||
// DO AT END? IN DEFER? |
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.
remove/resolve this comment
// DO AT END? IN DEFER?
db/db_local/start_database.go
Outdated
return ServiceStarted, err | ||
} | ||
|
||
// startPostgresProcessAndSetup starts the postgres process and writes out the state file |
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.
remove
db/db_local/start_database.go
Outdated
|
||
err = setupServicePassword(invoker, password) | ||
// set the password on the database | ||
// we can't do this during installation, since the 'steampipe` user isn't setup yet |
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.
inconsistent quote marks - do not use slanty quotes in code comments
When we run steampipe for the first time, if it finds the environment variable
STEAMPIPE_INSTALL_DATABASE
set to a non-empty value, it will install the database with the given name - if it's not present, or is empty, it will default tosteampipe