Documentation ¶
Overview ¶
Package postgresql manage the storage in a PostgreSQL database.
Index ¶
- Constants
- func DBNameForFunc(depth int) string
- func FromConnStrToDsn(cs ConnStr) string
- type ConnStr
- type FindingTicket
- type PostgresStore
- func (db *PostgresStore) Close() error
- func (db *PostgresStore) CreateFindingTicket(t model.Ticket) (model.FindingTicket, error)
- func (db *PostgresStore) FindProjectConfigByTeamID(teamID string) (model.ProjectConfig, error)
- func (db *PostgresStore) FindServerConf(serverID string) (model.TrackerConfig, error)
- func (db *PostgresStore) GetFindingTicket(findingID, teamID string) (model.FindingTicket, error)
- func (db *PostgresStore) Healthcheck() error
Constants ¶
const ( // TestDBName is the testing database name. TestDBName = "vultrackerdb_test" // TestDBUser is the testing database user. TestDBUser = "vultrackerdb_test" // TestDBPassword is the testing database password. TestDBPassword = "vultrackerdb_test" // DBDialect is the testing database dialect. DBDialect = "postgres" )
Variables ¶
This section is empty.
Functions ¶
func DBNameForFunc ¶
DBNameForFunc creates the name of a test PostgresStore for a function that is calling this one the number of levels above in the calling tree equal to the specified depth. For instance if a function named FuncA calls function, called FuncB that in turn makes the following call: DBNameForFunc(2), this function will return the following name: vultrackerdb_FuncA_test.
func FromConnStrToDsn ¶
FromConnStrToDsn transform a struct with the connection data to a connection string.
Types ¶
type ConnStr ¶
type ConnStr struct { Host string `toml:"host"` Port string `toml:"port"` User string `toml:"user"` Pass string `toml:"pass"` DB string `toml:"db"` SSLMode string `toml:"sslmode"` }
ConnStr holds the PostgreSQL connection information.
func CreateTestDatabase ¶
CreateTestDatabase builds an empty database in the default local test server. The name of the PostgresStore will be "vultrackerdb_<name>_test", where <name> corresponds to the name of the function calling this one.
type FindingTicket ¶
type FindingTicket struct { model.FindingTicket CreatedAt pq.NullTime `db:"created_at"` UpdatedAt pq.NullTime `db:"updated_at"` }
FindingTicket represents a relation between tickets and findings.
type PostgresStore ¶
PostgresStore holds the database connection.
func NewDB ¶
func NewDB(cs ConnStr, logger echo.Logger) (*PostgresStore, error)
NewDB instantiates a new PostgreSQL connection.
func PrepareDatabaseLocal ¶
func PrepareDatabaseLocal(fixturesPath string, f func(connectionString ConnStr, logger echo.Logger) (*PostgresStore, error)) (*PostgresStore, error)
PrepareDatabaseLocal creates a new local test database for the calling function and populates it the fixtures in the specified path.
func (*PostgresStore) Close ¶
func (db *PostgresStore) Close() error
Close closes PostgresStore db connection.
func (*PostgresStore) CreateFindingTicket ¶
func (db *PostgresStore) CreateFindingTicket(t model.Ticket) (model.FindingTicket, error)
CreateFindingTicket inserts a row in the database to store the relation between a finding, a team and a ticket.
func (*PostgresStore) FindProjectConfigByTeamID ¶
func (db *PostgresStore) FindProjectConfigByTeamID(teamID string) (model.ProjectConfig, error)
FindProjectConfigByTeamID retrieves a project configuration for a specific team from a postgres database.
func (*PostgresStore) FindServerConf ¶
func (db *PostgresStore) FindServerConf(serverID string) (model.TrackerConfig, error)
FindServerConf retrieves a ticket tracker configuration from a postgres database.
func (*PostgresStore) GetFindingTicket ¶
func (db *PostgresStore) GetFindingTicket(findingID, teamID string) (model.FindingTicket, error)
GetFindingTicket retrieves a row from the database that contains the link to the ticket tracker for a specific finding and team.
func (*PostgresStore) Healthcheck ¶
func (db *PostgresStore) Healthcheck() error
Healthcheck simply checks for database connectivity.