Documentation ¶
Index ¶
- Constants
- Variables
- func CertificatesExist() bool
- func CreateLocalDbConnection(ctx context.Context, opts *CreateDbOptions) (*pgx.Conn, error)
- func EnsureDBInstalled(ctx context.Context) (err error)
- func FindAllSteampipePostgresInstances(ctx context.Context) ([]*psutils.Process, error)
- func GetLocalClient(ctx context.Context, invoker constants.Invoker, ...) (db_common.Client, error)
- func IsInstalled() bool
- func RefreshConnectionAndSearchPaths(ctx context.Context, invoker constants.Invoker) error
- func RemoveAllCertificates() error
- func RemoveServerCertificate() error
- func ServiceExecutableRelativeLocation() string
- func ShutdownService(ctx context.Context, invoker constants.Invoker)
- func TrimLogs()
- func ValidateRootCertificate() bool
- func ValidateServerCertificate() bool
- type ClientCount
- type CreateDbOptions
- type LocalDbClient
- func (c *LocalDbClient) AcquireSession(ctx context.Context) *db_common.AcquireSessionResult
- func (c *LocalDbClient) AllSchemaNames() []string
- func (c *LocalDbClient) CacheClear(ctx context.Context) error
- func (c *LocalDbClient) CacheOff(ctx context.Context) error
- func (c *LocalDbClient) CacheOn(ctx context.Context) error
- func (c *LocalDbClient) Close(ctx context.Context) error
- func (c *LocalDbClient) ConstructSearchPath(ctx context.Context, requiredSearchPath, searchPathPrefix []string) ([]string, error)
- func (c *LocalDbClient) Execute(ctx context.Context, query string, args ...any) (res *queryresult.Result, err error)
- func (c *LocalDbClient) ExecuteInSession(ctx context.Context, session *db_common.DatabaseSession, onComplete func(), ...) (res *queryresult.Result, err error)
- func (c *LocalDbClient) ExecuteSync(ctx context.Context, query string, args ...any) (*queryresult.SyncQueryResult, error)
- func (c *LocalDbClient) ExecuteSyncInSession(ctx context.Context, session *db_common.DatabaseSession, query string, ...) (*queryresult.SyncQueryResult, error)
- func (c *LocalDbClient) ForeignSchemaNames() []string
- func (c *LocalDbClient) GetCurrentSearchPath(ctx context.Context) ([]string, error)
- func (c *LocalDbClient) GetCurrentSearchPathForDbConnection(ctx context.Context, databaseConnection *sql.Conn) ([]string, error)
- func (c *LocalDbClient) GetDefaultSearchPath(ctx context.Context) []string
- func (c *LocalDbClient) GetRequiredSessionSearchPath() []string
- func (c *LocalDbClient) GetSchemaFromDB(ctx context.Context) (*schema.Metadata, error)
- func (c *LocalDbClient) LoadSchemaNames(ctx context.Context) error
- func (c *LocalDbClient) RefreshConnectionAndSearchPaths(ctx context.Context, forceUpdateConnectionNames ...string) *steampipeconfig.RefreshConnectionResult
- func (c *LocalDbClient) RefreshSessions(ctx context.Context) *db_common.AcquireSessionResult
- func (c *LocalDbClient) SetRequiredSessionSearchPath(ctx context.Context) error
- type Passwords
- type RunningDBInstanceInfo
- type StartDbStatus
- type StartListenType
- type StartResult
- type StopStatus
Constants ¶
const CertIssuer = "steampipe.io"
const RunningDBStructVersion = 20220411
Variables ¶
Functions ¶
func CertificatesExist ¶
func CertificatesExist() bool
CertificatesExist checks if the root and server certificate and key files exist
func CreateLocalDbConnection ¶ added in v0.19.0
func CreateLocalDbConnection(ctx context.Context, opts *CreateDbOptions) (*pgx.Conn, error)
CreateLocalDbConnection connects and returns a connection to the given database using the provided username if the database is not provided (empty), it connects to the default database in the service that was created during installation. NOTE: no session data callback is used - no sesison data will be present
func EnsureDBInstalled ¶
EnsureDBInstalled makes sure that the embedded pg database is installed and running
func GetLocalClient ¶
func GetLocalClient(ctx context.Context, invoker constants.Invoker, onConnectionCallback db_client.DbConnectionCallback) (db_common.Client, error)
GetLocalClient starts service if needed and creates a new LocalDbClient
func IsInstalled ¶
func IsInstalled() bool
IsInstalled checks and reports whether the embedded database is installed and setup
func RefreshConnectionAndSearchPaths ¶
RefreshConnectionAndSearchPaths creates a local client and refreshed connections and search paths
func RemoveAllCertificates ¶
func RemoveAllCertificates() error
RemoveAllCertificates removes root and server certificates so that they can be regenerated
func RemoveServerCertificate ¶
func RemoveServerCertificate() error
RemoveServerCertificate removes the server certificate certificates so it will be regenerated
func ServiceExecutableRelativeLocation ¶
func ServiceExecutableRelativeLocation() string
func ShutdownService ¶
ShutdownService stops the database instance if the given 'invoker' matches
func ValidateRootCertificate ¶
func ValidateRootCertificate() bool
ValidateRootCertificate checks the root certificate exists, is not expired and has correct Subject
func ValidateServerCertificate ¶
func ValidateServerCertificate() bool
ValidateServerCertificate checks the server certificate exists, is not expired and has correct issuer
Types ¶
type ClientCount ¶ added in v0.19.0
func GetClientCount ¶ added in v0.19.0
func GetClientCount(ctx context.Context) (*ClientCount, error)
GetClientCount returns the number of connections to the service from anyone other than _this_execution_ of steampipe
We assume that any connections from this execution will eventually be closed - if there are any other external connections, we cannot shut down the database
this is to handle cases where either a third party tool is connected to the database, or other Steampipe sessions are attached to an already running Steampipe service - we do not want the db service being closed underneath them
note: we need the PgClientAppName check to handle the case where there may be one or more open DB connections from this instance at the time of shutdown - for example when a control run is cancelled If we do not exclude connections from this execution, the DB will not be shut down after a cancellation
type CreateDbOptions ¶
type CreateDbOptions struct {
DatabaseName, Username string
}
type LocalDbClient ¶
type LocalDbClient struct {
// contains filtered or unexported fields
}
LocalDbClient wraps over DbClient
func NewLocalClient ¶
func NewLocalClient(ctx context.Context, invoker constants.Invoker, onConnectionCallback db_client.DbConnectionCallback) (*LocalDbClient, error)
NewLocalClient verifies that the local database instance is running and returns a LocalDbClient to interact with it
func (*LocalDbClient) AcquireSession ¶
func (c *LocalDbClient) AcquireSession(ctx context.Context) *db_common.AcquireSessionResult
func (*LocalDbClient) AllSchemaNames ¶ added in v0.19.0
func (c *LocalDbClient) AllSchemaNames() []string
AllSchemaNames implements Client
func (*LocalDbClient) CacheClear ¶
func (c *LocalDbClient) CacheClear(ctx context.Context) error
CacheClear implements Client
func (*LocalDbClient) CacheOff ¶
func (c *LocalDbClient) CacheOff(ctx context.Context) error
CacheOff implements Client
func (*LocalDbClient) CacheOn ¶
func (c *LocalDbClient) CacheOn(ctx context.Context) error
CacheOn implements Client
func (*LocalDbClient) Close ¶
func (c *LocalDbClient) Close(ctx context.Context) error
Close implements Client close the connection to the database and shuts down the backend if we are the last connection
func (*LocalDbClient) ConstructSearchPath ¶ added in v0.19.0
func (*LocalDbClient) Execute ¶
func (c *LocalDbClient) Execute(ctx context.Context, query string, args ...any) (res *queryresult.Result, err error)
Execute implements Client
func (*LocalDbClient) ExecuteInSession ¶
func (c *LocalDbClient) ExecuteInSession(ctx context.Context, session *db_common.DatabaseSession, onComplete func(), query string, args ...any) (res *queryresult.Result, err error)
ExecuteInSession implements Client
func (*LocalDbClient) ExecuteSync ¶
func (c *LocalDbClient) ExecuteSync(ctx context.Context, query string, args ...any) (*queryresult.SyncQueryResult, error)
ExecuteSync implements Client
func (*LocalDbClient) ExecuteSyncInSession ¶
func (c *LocalDbClient) ExecuteSyncInSession(ctx context.Context, session *db_common.DatabaseSession, query string, args ...any) (*queryresult.SyncQueryResult, error)
ExecuteSyncInSession implements Client
func (*LocalDbClient) ForeignSchemaNames ¶
func (c *LocalDbClient) ForeignSchemaNames() []string
ForeignSchemaNames implements Client
func (*LocalDbClient) GetCurrentSearchPath ¶
func (c *LocalDbClient) GetCurrentSearchPath(ctx context.Context) ([]string, error)
GetCurrentSearchPath implements Client
func (*LocalDbClient) GetCurrentSearchPathForDbConnection ¶
func (*LocalDbClient) GetDefaultSearchPath ¶
func (c *LocalDbClient) GetDefaultSearchPath(ctx context.Context) []string
GetDefaultSearchPath builds default search path from the connection schemas, book-ended with public and internal
func (*LocalDbClient) GetRequiredSessionSearchPath ¶
func (c *LocalDbClient) GetRequiredSessionSearchPath() []string
GetRequiredSessionSearchPath implements Client
func (*LocalDbClient) GetSchemaFromDB ¶
GetSchemaFromDB for LocalDBClient optimises the schema extraction by extracting schema information for connections backed by distinct plugins and then fanning back out.
func (*LocalDbClient) LoadSchemaNames ¶ added in v0.19.0
func (c *LocalDbClient) LoadSchemaNames(ctx context.Context) error
LoadSchemaNames implements Client
func (*LocalDbClient) RefreshConnectionAndSearchPaths ¶
func (c *LocalDbClient) RefreshConnectionAndSearchPaths(ctx context.Context, forceUpdateConnectionNames ...string) *steampipeconfig.RefreshConnectionResult
func (*LocalDbClient) RefreshSessions ¶
func (c *LocalDbClient) RefreshSessions(ctx context.Context) *db_common.AcquireSessionResult
func (*LocalDbClient) SetRequiredSessionSearchPath ¶
func (c *LocalDbClient) SetRequiredSessionSearchPath(ctx context.Context) error
SetRequiredSessionSearchPath implements Client
type RunningDBInstanceInfo ¶
type RunningDBInstanceInfo struct { Pid int `json:"pid"` Port int `json:"port"` Listen []string `json:"listen"` ListenType StartListenType `json:"listen_type"` Invoker constants.Invoker `json:"invoker"` Password string `json:"password"` User string `json:"user"` Database string `json:"database"` StructVersion int64 `json:"struct_version"` }
RunningDBInstanceInfo contains data about the running process and it's credentials
func GetState ¶
func GetState() (*RunningDBInstanceInfo, error)
GetState checks that the database instance is running and returns its details
func (*RunningDBInstanceInfo) Save ¶
func (r *RunningDBInstanceInfo) Save() error
func (*RunningDBInstanceInfo) String ¶
func (r *RunningDBInstanceInfo) String() string
type StartDbStatus ¶
type StartDbStatus int
StartDbStatus is a pseudoEnum for outcomes of starting the db
const ( // start from 10 to prevent confusion with int zero-value ServiceStarted StartDbStatus = iota + 1 ServiceAlreadyRunning ServiceFailedToStart )
type StartListenType ¶
type StartListenType string
StartListenType is a pseudoEnum of network binding for postgres
const ( // ListenTypeNetwork - bind to all known interfaces ListenTypeNetwork StartListenType = "network" // ListenTypeLocal - bind to localhost only ListenTypeLocal = "local" )
func (StartListenType) IsValid ¶
func (slt StartListenType) IsValid() error
IsValid is a validator for StartListenType known values
type StartResult ¶
type StartResult struct { Error error Status StartDbStatus DbState *RunningDBInstanceInfo PluginManagerState *pluginmanager.PluginManagerState }
StartResult is a pseudoEnum for outcomes of StartNewInstance
func StartServices ¶
func StartServices(ctx context.Context, port int, listen StartListenType, invoker constants.Invoker) (startResult *StartResult)
func (*StartResult) SetError ¶
func (r *StartResult) SetError(err error) *StartResult
type StopStatus ¶
type StopStatus int
StopStatus is a pseudoEnum for service stop result
const ( // start from 1 to prevent confusion with int zero-value ServiceStopped StopStatus = iota + 1 ServiceNotRunning ServiceStopFailed ServiceStopTimedOut )
func StopServices ¶
func StopServices(ctx context.Context, force bool, invoker constants.Invoker) (status StopStatus, e error)
StopServices searches for and stops the running instance. Does nothing if an instance was not found