database

package
v0.0.0-...-d8b2627 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbortReservation

func AbortReservation(username string, id int) error

AbortReservation deletes a reservation entry from database. This is only possible, if the reservation is still upcoming and not active yet. This is because an active reservation has to be ended, whereas an upcoming reservation just can be deleted. Further, a reservation is only abortable by the user who created it. Function parameter id is the reservation's database id.

func CollectUserCreds

func CollectUserCreds(username string, readCreds readCredsFunc) []util.ReservationCreds

CollectUserCreds bundles all valid credentials for a user. It searches for the user's reservations with status 'active', adds the Environment information and looks up the corresponding credentials. As reading credentials from vault is a matter of the vault package, and it is tried to keep the packages database and vault separately, the readCreds function is passed as parameter. If a reservation is found for which no environment exists in database, the function creates kind of a dummy Environment struct using the EnvPlainName given in the Reservation. No error or similar will arise.

func CreateReservation

func CreateReservation(r util.Reservation) error

CreateReservation puts a new reservation entry to the database. Bevor writing to database, several checks are performed. Function checks time parameters for plausibility, tests, if user has an ssh key uploaded if necessary, and checks for possible conflicts with existing reservations. If everything is fine, reservation will be created. Otherwise, function returns a reservation error.

func DeleteOldReservations

func DeleteOldReservations(now time.Time)

DeleteOldReservations selects all expired reservations from database, which have a delete_on time smaller than now. It deletes all those reservations from database.

func DeleteOldUserEntries

func DeleteOldUserEntries(now time.Time)

DeleteOldUserEntries deletes all users from database table "users", who haven't logged in for a long time ("long time" is defined by constant "yearsTTL"). Old user entries are recognized by their delete_on column. So, this function deletes all user entries, whose delete_on dates are exceeded.

func DeleteUserEmail

func DeleteUserEmail(username string)

DeleteUserEmail deletes a user's e-mail address from database. The rest of the user's database entry remains.

func DeleteUserSSH

func DeleteUserSSH(username string)

DeleteUserSSH deletes a user's ssh public key from database. The rest of the user's database entry remains.

func ExpireActiveReservations

func ExpireActiveReservations(now time.Time, endBooking endBookingFunc)

ExpireActiveReservations selects all active reservations from database, wich have an end time smaller than now. It applies the endBooking function to all environments which are affected by those reservations. After, it changes the reservation's status in database. The reason, why the endBooking function is passed as parameter here is the ambition to preserve the separation of database and vault package. The time now is passed because an unchanging reference is needed over several function calls to avoid inconsistencies.

func GetEnvReservations

func GetEnvReservations(envPlainName string) []util.Reservation

GetEnvReservations returns all reservations stored in database for a specific environment.

func GetEnvironments

func GetEnvironments() map[string]util.Environment

GetEnvironments reads all environments from database and returns them as a map with the PlainNames as keys.

func GetUserEmail

func GetUserEmail(username string) (string, bool)

GetUserEmail returns the mail address for a given user from database if present. If not, an empty string will be returned, together with the second return value saying false.

func GetUserReservations

func GetUserReservations(username string) []util.Reservation

GetUserReservations returns all reservations stored in database for a specific username.

func GetUserSSH

func GetUserSSH(username string) (string, bool)

GetUserSSH returns the SSH public key for a given user from database if present. If not, an empty string will be returned, together with the second return value saying false.

func InitDB

func InitDB(l logging.Logger, config util.GafaspotConfig)

InitDB prepares the database for gafaspot. Opens the database at the path given in config file. As SQLite is used, database doesn't even need to exist yet. Prepares all database tables and fills the environments table with the information from config file. Sets the package variable db to enable every function in the package to access the database.

func RefreshDeletionDate

func RefreshDeletionDate(username string)

RefreshDeletionDate updates the column "delete_on" in the users table for a specific user, if a user entry exists. The delete_on entry is for enable the program to delete old entries for users, which haven't logged in for a long time. So, each time a user actually logs in, the deletion date has to be refreshed.

func SaveUserEmail

func SaveUserEmail(username, email string)

SaveUserEmail takes an mail address and stores it with the username to database table users. Function does not perform any checks, so make sure you validate the address format earlier.

func SaveUserSSH

func SaveUserSSH(username string, ssh []byte)

SaveUserSSH takes an ssh key and stores it with the username to database table users. Function does not perform any checks, so make sure you validate the key format earlier.

func StartUpcomingReservations

func StartUpcomingReservations(now time.Time, startBooking startBookingFunc, readCreds readCredsFunc)

StartUpcomingReservations selects all upcoming reservations from database, wich have a start time smaller than now. It applies the startBooking function to all environments which are affected by those reservations. After, it changes the reservation's status in database. The reason, why the startBooking function is passed as parameter here is the ambition to preserve the separation of database and vault package. The time 'now' is passed because an unchanging reference is needed over several function calls to avoid inconsistencies.

func UserHasEmail

func UserHasEmail(username string) bool

UserHasEmail determines, whether an e-mail address is stored in database for a given username

func UserHasSSH

func UserHasSSH(username string) bool

UserHasSSH determines, whether an SSH public key is stored in database for a given username

Types

type ReservationError

type ReservationError string

ReservationError is thrown by the CreateReservation func, if reservation parameters are not valid. In this case, reservation will not be created.

func (ReservationError) Error

func (err ReservationError) Error() string

Jump to

Keyboard shortcuts

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