db_local

package
v0.21.2-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2023 License: AGPL-3.0 Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CertIssuer               = "steampipe.io"
	ServerCertValidityPeriod = 3 * (365 * (24 * time.Hour)) // 3 years
)
View Source
const RunningDBStructVersion = 20220411
View Source
const TagColumn = "column"

TagColumn is the tag used to specify the column name and type in the introspection tables

Variables

View Source
var EndOfTime = time.Date(9999, 12, 31, 23, 59, 59, 0, time.UTC)

Functions

func CreateConnectionPool added in v0.20.0

func CreateConnectionPool(ctx context.Context, opts *CreateDbOptions, maxConnections int) (*pgxpool.Pool, error)

CreateConnectionPool

func CreateIntrospectionTables added in v0.21.0

func CreateIntrospectionTables(ctx context.Context, workspaceResources *modconfig.ResourceMaps, tx pgx.Tx) error

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 session data will be present

func EnsureDBInstalled

func EnsureDBInstalled(ctx context.Context) (err error)

EnsureDBInstalled makes sure that the embedded postgres database is installed and ready to run

func ExecuteSqlInTransaction added in v0.20.0

func ExecuteSqlInTransaction(ctx context.Context, conn *pgx.Conn, statements ...string) (results []pgconn.CommandTag, err error)

func ExecuteSqlWithArgsInTransaction added in v0.20.0

func ExecuteSqlWithArgsInTransaction(ctx context.Context, conn *pgx.Conn, queries ...db_common.QueryWithArgs) (results []pgconn.CommandTag, err error)

func FindAllSteampipePostgresInstances

func FindAllSteampipePostgresInstances(ctx context.Context) ([]*psutils.Process, error)

func IsDBInstalled added in v0.21.0

func IsDBInstalled() bool

IsDBInstalled checks and reports whether the embedded database binaries are available

func IsFDWInstalled added in v0.21.0

func IsFDWInstalled() bool

IsFDWInstalled chceks whether all files required for the Steampipe FDW are available

func PopulatePluginTable added in v0.21.0

func PopulatePluginTable(ctx context.Context, conn *pgx.Conn) error

func SendPostgresNotification added in v0.20.0

func SendPostgresNotification(_ context.Context, conn *pgx.Conn, notification any) error

SendPostgresNotification send a postgres notification that the schema has chganged

func SetUserSearchPath added in v0.20.0

func SetUserSearchPath(ctx context.Context, pool *pgxpool.Pool) ([]string, error)

func ShutdownService

func ShutdownService(ctx context.Context, invoker constants.Invoker)

ShutdownService stops the database instance if the given 'invoker' matches

func TrimLogs

func TrimLogs()

Types

type ClientCount added in v0.19.0

type ClientCount struct {
	SteampipeClients     int
	PluginManagerClients int
	TotalClients         int
}

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 ColumnTag added in v0.21.0

type ColumnTag struct {
	Column string
	// the introspected go type
	ColumnType string
}

ColumnTag is a struct used to display column info in introspection tables

type CreateDbOptions

type CreateDbOptions struct {
	DatabaseName, Username string
}

type LocalDbClient

type LocalDbClient struct {
	db_client.DbClient
	// contains filtered or unexported fields
}

LocalDbClient wraps over DbClient

func GetLocalClient

func GetLocalClient(ctx context.Context, invoker constants.Invoker, onConnectionCallback db_client.DbConnectionCallback, opts ...db_client.ClientOption) (*LocalDbClient, *error_helpers.ErrorAndWarnings)

GetLocalClient starts service if needed and creates a new LocalDbClient

func (*LocalDbClient) Close

func (c *LocalDbClient) Close(ctx context.Context) error

Close implements Client close the connection to the database and shuts down the db service if we are the last connection

func (*LocalDbClient) RegisterNotificationListener added in v0.21.0

func (c *LocalDbClient) RegisterNotificationListener(f func(notification *pgconn.Notification))

type Passwords

type Passwords struct {
	Root      string
	Steampipe string
}

Passwords :: structure for working with DB passwords

type RunningDBInstanceInfo

type RunningDBInstanceInfo struct {
	Pid int `json:"pid"`
	// store both resolved and user input listen addresses
	// keep the same 'listen' json tag to maintain backward compatibility
	ResolvedListenAddresses []string          `json:"listen"`
	GivenListenAddresses    []string          `json:"raw_listen"`
	Port                    int               `json:"port"`
	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) MatchWithGivenListenAddresses added in v0.21.0

func (r *RunningDBInstanceInfo) MatchWithGivenListenAddresses(listenAddresses []string) bool

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 1 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) ToListenAddresses added in v0.21.0

func (slt StartListenType) ToListenAddresses() []string

ToListenAddresses is transforms StartListenType known aliases into their actual value

type StartResult

type StartResult struct {
	error_helpers.ErrorAndWarnings
	Status             StartDbStatus
	DbState            *RunningDBInstanceInfo
	PluginManagerState *pluginmanager.State
	PluginManager      *pluginmanager.PluginManagerClient
}

StartResult is a pseudoEnum for outcomes of StartNewInstance

func StartServices

func StartServices(ctx context.Context, listenAddresses []string, port int, invoker constants.Invoker) *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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL