Documentation ¶
Overview ¶
These functions extract (and validate) user provided form data.
Useful utility functions
Index ¶
- Constants
- Variables
- func AddDatabase(r *http.Request, loggedInUser string, dbOwner string, dbFolder string, ...) (numBytes int64, newCommitID string, err error)
- func AddDefaultLicences() (err error)
- func AddDefaultUser() error
- func AddUser(auth0ID string, userName string, password string, email string, ...) error
- func CacheData(cacheKey string, cacheData interface{}, cacheSeconds int) error
- func CheckDBExists(loggedInUser string, dbOwner string, dbFolder string, dbName string) (bool, error)
- func CheckDBID(loggedInUser string, dbOwner string, dbID int64) (avail bool, dbFolder string, dbName string, err error)
- func CheckDBStarred(loggedInUser string, dbOwner string, dbFolder string, dbName string) (bool, error)
- func CheckDBWatched(loggedInUser string, dbOwner string, dbFolder string, dbName string) (bool, error)
- func CheckEmailExists(email string) (bool, error)
- func CheckLicenceExists(userName string, licenceName string) (exists bool, err error)
- func CheckUserExists(userName string) (bool, error)
- func ClientCert(userName string) ([]byte, error)
- func CommitLicenceSHA(dbOwner string, dbFolder string, dbName string, commitID string) (licenceSHA string, err error)
- func ConnectCache() error
- func ConnectMinio() (err error)
- func ConnectPostgreSQL() (err error)
- func CreateCommitID(c CommitEntry) string
- func CreateDBTreeID(entries []DBTreeEntry) string
- func DB4SDefaultList(loggedInUser string) (map[string]UserInfo, error)
- func DBDetails(DB *SQLiteDBinfo, loggedInUser string, dbOwner string, dbFolder string, ...) error
- func DBStars(dbOwner string, dbFolder string, dbName string) (starCount int, err error)
- func DBWatchers(dbOwner string, dbFolder string, dbName string) (watcherCount int, err error)
- func DefaultCommit(dbOwner string, dbFolder string, dbName string) (string, error)
- func DeleteBranchHistory(dbOwner string, dbFolder string, dbName string, branchName string, ...) (isolatedTags []string, isolatedRels []string, err error)
- func DeleteComment(dbOwner string, dbFolder string, dbName string, discID int, comID int) error
- func DeleteDatabase(dbOwner string, dbFolder string, dbName string) error
- func DeleteLicence(userName string, licenceName string) (err error)
- func DisconnectPostgreSQL()
- func FlushViewCount()
- func ForkDatabase(srcOwner string, dbFolder string, dbName string, dstOwner string) (newForkCount int, err error)
- func ForkParent(loggedInUser string, dbOwner string, dbFolder string, dbName string) (parentOwner string, parentFolder string, parentDBName string, err error)
- func ForkedFrom(dbOwner string, dbFolder string, dbName string) (forkOwn string, forkFol string, forkDB string, forkDel bool, err error)
- func GenerateClientCert(userName string) (_ []byte, err error)
- func GetBranches(dbOwner string, dbFolder string, dbName string) (branches map[string]BranchEntry, err error)
- func GetCachedData(cacheKey string, cacheData interface{}) (bool, error)
- func GetCommitList(dbOwner string, dbFolder string, dbName string) (map[string]CommitEntry, error)
- func GetCurrentFunctionName() (FuncName string)
- func GetDatabase(r *http.Request, allowGet bool) (string, error)
- func GetDefaultBranchName(dbOwner string, dbFolder string, dbName string) (branchName string, err error)
- func GetDefaultTableName(dbOwner string, dbFolder string, dbName string) (tableName string, err error)
- func GetDiscussionAndMRCount(dbOwner string, dbFolder string, dbName string) (discCount int, mrCount int, err error)
- func GetFolder(r *http.Request, allowGet bool) (string, error)
- func GetFormBranch(r *http.Request) (string, error)
- func GetFormCommit(r *http.Request) (string, error)
- func GetFormLicence(r *http.Request) (licenceName string, err error)
- func GetFormRelease(r *http.Request) (release string, err error)
- func GetFormSourceURL(r *http.Request) (sourceURL string, err error)
- func GetFormTag(r *http.Request) (tag string, err error)
- func GetFormUDC(r *http.Request) (string, string, string, error)
- func GetLicence(userName string, licenceName string) (txt string, format string, err error)
- func GetLicenceInfoFromSha256(userName string, sha256 string) (lName string, lURL string, err error)
- func GetLicenceSha256FromName(userName string, licenceName string) (sha256 string, err error)
- func GetLicences(user string) (map[string]LicenceEntry, error)
- func GetOD(ignore_leading int, r *http.Request) (string, string, error)
- func GetODC(ignore_leading int, r *http.Request) (string, string, string, error)
- func GetODT(ignore_leading int, r *http.Request) (string, string, string, error)
- func GetODTC(ignore_leading int, r *http.Request) (string, string, string, string, error)
- func GetPub(r *http.Request) (bool, error)
- func GetReleases(dbOwner string, dbFolder string, dbName string) (releases map[string]ReleaseEntry, err error)
- func GetSQLiteRowCount(sdb *sqlite.Conn, dbTable string) (int, error)
- func GetTable(r *http.Request) (string, error)
- func GetTags(dbOwner string, dbFolder string, dbName string) (tags map[string]TagEntry, err error)
- func GetUFD(r *http.Request, allowGet bool) (string, string, string, error)
- func GetUsername(r *http.Request, allowGet bool) (string, error)
- func GetUsernameFromEmail(email string) (userName string, avatarURL string, err error)
- func GetViewCount(dbOwner string, dbFolder string, dbName string) (count int, err error)
- func IncrementDownloadCount(dbOwner string, dbFolder string, dbName string) error
- func IncrementViewCount(dbOwner string, dbFolder string, dbName string) error
- func InvalidateCacheEntry(loggedInUser string, dbOwner string, dbFolder string, dbName string, ...) error
- func IsCommitInBranchHistory(dbOwner string, dbFolder string, dbName string, branchName string, ...) (bool, error)
- func LogDownload(dbOwner string, dbFolder string, dbName string, loggedInUser string, ...) error
- func LogUpload(dbOwner string, dbFolder string, dbName string, loggedInUser string, ...) error
- func MemcacheHandle() *memcache.Client
- func MetadataCacheKey(prefix string, loggedInUser string, dbOwner string, dbFolder string, ...) string
- func MinioHandle(bucket string, id string) (*minio.Object, error)
- func MinioHandleClose(userDB *minio.Object) (err error)
- func MinioLocation(dbOwner string, dbFolder string, dbName string, commitID string, ...) (minioBucket string, minioID string, lastModified time.Time, err error)
- func NewEvent(details EventDetails) (err error)
- func OpenMinioObject(bucket string, id string) (*sqlite.Conn, error)
- func PrefUserMaxRows(loggedInUser string) int
- func RandomString(length int) string
- func ReadConfig() error
- func ReadSQLiteDBCSV(sdb *sqlite.Conn, dbTable string) ([][]string, error)
- func RenameDatabase(userName string, dbFolder string, dbName string, newName string) error
- func ReservedUsernamesCheck(userName string) error
- func SanityCheck(fileName string) (tables []string, err error)
- func SaveDBSettings(userName string, dbFolder string, dbName string, oneLineDesc string, ...) error
- func SendEmails()
- func SetClientCert(newCert []byte, userName string) error
- func SetUserPreferences(userName string, maxRows int, displayName string, email string) error
- func SetUserStatusUpdates(userName string, numUpdates int) error
- func SocialStats(dbOwner string, dbFolder string, dbName string) (wa int, st int, fo int, err error)
- func StatusUpdateCheck(dbOwner string, dbFolder string, dbName string, thisID int, userName string) (numStatusUpdates int, err error)
- func StatusUpdates(loggedInUser string) (statusUpdates map[string][]StatusUpdateEntry, err error)
- func StatusUpdatesLoop()
- func StoreBranches(dbOwner string, dbFolder string, dbName string, ...) error
- func StoreComment(dbOwner string, dbFolder string, dbName string, commenter string, discID int, ...) error
- func StoreCommits(dbOwner string, dbFolder string, dbName string, ...) error
- func StoreDatabase(dbOwner string, dbFolder string, dbName string, ...) error
- func StoreDatabaseFile(db *os.File, sha string, dbSize int64) error
- func StoreDefaultBranchName(dbOwner string, folder string, dbName string, branchName string) error
- func StoreDefaultTableName(dbOwner string, folder string, dbName string, tableName string) error
- func StoreDiscussion(dbOwner string, dbFolder string, dbName string, loggedInUser string, ...) (newID int, err error)
- func StoreLicence(userName string, licenceName string, txt []byte, url string, orderNum int, ...) error
- func StoreReleases(dbOwner string, dbFolder string, dbName string, ...) error
- func StoreStatusUpdates(userName string, statusUpdates map[string][]StatusUpdateEntry) error
- func StoreTags(dbOwner string, dbFolder string, dbName string, tags map[string]TagEntry) error
- func TableRowsCacheKey(prefix string, loggedInUser string, dbOwner string, dbFolder string, ...) string
- func Tables(sdb *sqlite.Conn, dbName string) ([]string, error)
- func ToggleDBStar(loggedInUser string, dbOwner string, dbFolder string, dbName string) error
- func ToggleDBWatch(loggedInUser string, dbOwner string, dbFolder string, dbName string) error
- func UpdateAvatarURL(userName string, avatarURL string) error
- func UpdateComment(dbOwner string, dbFolder string, dbName string, loggedInUser string, ...) error
- func UpdateContributorsCount(dbOwner string, dbFolder, dbName string) error
- func UpdateDiscussion(dbOwner string, dbFolder string, dbName string, loggedInUser string, ...) error
- func UpdateMergeRequestCommits(dbOwner string, dbFolder string, dbName string, discID int, ...) (err error)
- func UserNameFromAuth0ID(auth0id string) (string, error)
- func UserStatusUpdates(userName string) (numUpdates int, err error)
- func ValidateBranchName(fieldName string) error
- func ValidateCommitID(fieldName string) error
- func ValidateDB(dbName string) error
- func ValidateDiscussionTitle(fieldName string) error
- func ValidateDisplayName(dbName string) error
- func ValidateEmail(email string) error
- func ValidateFieldName(fieldName string) error
- func ValidateFolder(folder string) error
- func ValidateLicence(licence string) error
- func ValidateLicenceFullName(licence string) error
- func ValidateMarkdown(fieldName string) error
- func ValidatePGTable(table string) error
- func ValidateUser(user string) error
- func ValidateUserDB(user string, db string) error
- func ValidateUserDBTable(user string, db string, table string) error
- func ValidateUserEmail(user string, email string) error
- func ViewCount(dbOwner string, dbFolder string, dbName string) (viewCount int, err error)
- type AccessType
- type ActivityRange
- type ActivityRow
- type ActivityStats
- type AdminInfo
- type Auth0Info
- type Auth0Set
- type BranchEntry
- type CommitData
- type CommitEntry
- type DB4SInfo
- type DBEntry
- func UserStarredDBs(userName string) (list []DBEntry, err error)
- func UserWatchingDBs(userName string) (list []DBEntry, err error)
- func UsersStarredDB(dbOwner string, dbFolder string, dbName string) (list []DBEntry, err error)
- func UsersWatchingDB(dbOwner string, dbFolder string, dbName string) (list []DBEntry, err error)
- type DBInfo
- type DBTree
- type DBTreeEntry
- type DBTreeEntryType
- type DataRow
- type DataValue
- type DiscussionCommentEntry
- type DiscussionCommentType
- type DiscussionEntry
- type DiscussionType
- type DiskCacheInfo
- type EnvInfo
- type EventDetails
- type EventProcessingInfo
- type EventType
- type ForkEntry
- type ForkType
- type LicenceEntry
- type LicenceInfo
- type MemcacheInfo
- type MergeRequestEntry
- type MergeRequestState
- type MetaInfo
- type MinioInfo
- type PGInfo
- type RedashColumnMeta
- type RedashTableData
- type ReleaseEntry
- type SQLiteDBinfo
- type SQLiteRecordSet
- type SigningInfo
- type StatusUpdateEntry
- type TagEntry
- type TomlConfig
- type UploadRow
- type UserDetails
- type UserInfo
- type ValType
- type WebInfo
- type WhereClause
Constants ¶
const ( TODAY ActivityRange = "today" THIS_WEEK = "week" THIS_MONTH = "month" ALL_TIME = "all" )
const ( TREE DBTreeEntryType = "tree" DATABASE = "db" LICENCE = "licence" )
const ( TEXT DiscussionCommentType = "txt" CLOSE = "cls" REOPEN = "rop" )
const ( EVENT_NEW_DISCUSSION EventType = 0 // These are not iota, as it would be seriously bad for these numbers to change EVENT_NEW_MERGE_REQUEST = 1 EVENT_NEW_COMMENT = 2 EVENT_NEW_RELEASE = 3 )
const ( OPEN MergeRequestState = 0 // These are not iota, as it would be seriously bad for these numbers to change CLOSED_WITH_MERGE = 1 CLOSED_WITHOUT_MERGE = 2 )
const DefaultNumDisplayRows = 25
Number of rows to display by default on the database page
const MaxDatabaseSize = 512
The maximum database size accepted for upload (in MB)
const MaxLicenceSize = 1
The maximum licence size accepted for upload (in MB)
const MinioFolderChars = 6
The number of leading characters of a files' sha256 used as the Minio folder name eg: When set to 6, then "34f4255a737156147fbd0a44323a895d18ade79d4db521564d1b0dbb8764cbbc"
-> Minio folder: "34f425" -> Minio filename: "5a737156147fbd0a44323a895d18ade79d4db521564d1b0dbb8764cbbc"
Variables ¶
var ( // For input validation Validate *valid.Validate )
Functions ¶
func AddDatabase ¶
func AddDatabase(r *http.Request, loggedInUser string, dbOwner string, dbFolder string, dbName string, createBranch bool, branchName string, commitID string, public bool, licenceName string, commitMsg string, sourceURL string, newDB io.Reader, serverSw string, lastModified time.Time, commitTime time.Time, authorName string, authorEmail string, committerName string, committerEmail string, otherParents []string, dbSha string) (numBytes int64, newCommitID string, err error)
The main function which handles database upload processing for both the webUI and DB4S end points
func AddDefaultUser ¶
func AddDefaultUser() error
Add the default user to the system, used so the referential integrity of licence user_id 0 works.
func AddUser ¶
func AddUser(auth0ID string, userName string, password string, email string, displayName string, avatarURL string) error
Add a user to the system.
func CheckDBExists ¶
func CheckDBExists(loggedInUser string, dbOwner string, dbFolder string, dbName string) (bool, error)
Check if a database exists If an error occurred, the true/false value should be ignored, as only the error value is valid.
func CheckDBID ¶
func CheckDBID(loggedInUser string, dbOwner string, dbID int64) (avail bool, dbFolder string, dbName string, err error)
Check if a given database ID is available, and return it's folder/name so the caller can determine if it has been renamed. If an error occurs, the true/false value should be ignored, as only the error value is valid.
func CheckDBStarred ¶
func CheckDBStarred(loggedInUser string, dbOwner string, dbFolder string, dbName string) (bool, error)
Check if a database has been starred by a given user. The boolean return value is only valid when err is nil.
func CheckDBWatched ¶
func CheckDBWatched(loggedInUser string, dbOwner string, dbFolder string, dbName string) (bool, error)
Check if a database is being watched by a given user. The boolean return value is only valid when err is nil.
func CheckEmailExists ¶
Check if an email address already exists in our system. Returns true if the email is already in the system, false if not. If an error occurred, the true/false value should be ignored, as only the error value is valid.
func CheckLicenceExists ¶ added in v0.0.5
Checks if a licence exists in our system.
func CheckUserExists ¶
Check if a username already exists in our system. Returns true if the username is already taken, false if not. If an error occurred, the true/false value should be ignored, and only the error return code used.
func ClientCert ¶
Returns the certificate for a given user.
func CommitLicenceSHA ¶
func CommitLicenceSHA(dbOwner string, dbFolder string, dbName string, commitID string) (licenceSHA string, err error)
Returns the licence used by the database in a given commit
func ConnectCache ¶
func ConnectCache() error
func ConnectMinio ¶
func ConnectMinio() (err error)
Parse the Minio configuration, to ensure it seems workable. Note - this doesn't actually open a connection to the Minio server.
func ConnectPostgreSQL ¶
func ConnectPostgreSQL() (err error)
Creates a connection pool to the PostgreSQL server.
func CreateCommitID ¶
func CreateCommitID(c CommitEntry) string
Generate a stable SHA256 for a commit.
func CreateDBTreeID ¶
func CreateDBTreeID(entries []DBTreeEntry) string
Generate the SHA256 for a tree. Tree entry structure is: * [ entry type ] [ licence sha256] [ file sha256 ] [ file name ] [ last modified (timestamp) ] [ file size (bytes) ]
func DB4SDefaultList ¶
Return a list of 1) users with public databases, 2) along with the logged in users' most recently modified database (including their private one(s)).
func DBDetails ¶
func DBDetails(DB *SQLiteDBinfo, loggedInUser string, dbOwner string, dbFolder string, dbName string, commitID string) error
Retrieve the details for a specific database
func DBWatchers ¶
Returns the watchers count for a given database.
func DefaultCommit ¶
Retrieve the default commit ID for a specific database
func DeleteBranchHistory ¶
func DeleteBranchHistory(dbOwner string, dbFolder string, dbName string, branchName string, commitID string) (isolatedTags []string, isolatedRels []string, err error)
Safely removes the commit history for a branch, from the head of the branch back to (but not including) the specified commit. The new branch head will be at the commit ID specified
func DeleteComment ¶
Delete a specific comment from a discussion
func DeleteDatabase ¶
Deletes a database from PostgreSQL.
func DeleteLicence ¶ added in v0.0.5
Removes a (user supplied) database licence from the system.
func DisconnectPostgreSQL ¶
func DisconnectPostgreSQL()
Disconnects the PostgreSQL database connection.
func FlushViewCount ¶
func FlushViewCount()
Periodically flushes the database view count from memcache to PostgreSQL
func ForkDatabase ¶
func ForkDatabase(srcOwner string, dbFolder string, dbName string, dstOwner string) (newForkCount int, err error)
Fork the PostgreSQL entry for a SQLite database from one user to another
func ForkParent ¶
func ForkParent(loggedInUser string, dbOwner string, dbFolder string, dbName string) (parentOwner string, parentFolder string, parentDBName string, err error)
Return the parent of a database, if there is one (and it's accessible to the logged in user). If no parent was found, the returned Owner/Folder/DBName values will be empty strings
func ForkedFrom ¶
func ForkedFrom(dbOwner string, dbFolder string, dbName string) (forkOwn string, forkFol string, forkDB string, forkDel bool, err error)
Checks if the given database was forked from another, and if so returns that one's owner, folder and database name
func GenerateClientCert ¶
func GetBranches ¶
func GetBranches(dbOwner string, dbFolder string, dbName string) (branches map[string]BranchEntry, err error)
Load the branch heads for a database. TODO: It might be better to have the default branch name be returned as part of this list, by indicating in the list TODO which of the branches is the default.
func GetCachedData ¶
Retrieves cached data from Memcached
func GetCommitList ¶
Retrieves the full commit list for a database.
func GetCurrentFunctionName ¶
func GetCurrentFunctionName() (FuncName string)
Returns the name of the function this was called from
func GetDatabase ¶
Extracts a database name from GET or POST/PUT data.
func GetDefaultBranchName ¶
func GetDefaultBranchName(dbOwner string, dbFolder string, dbName string) (branchName string, err error)
Returns the default branch name for a database.
func GetDefaultTableName ¶
func GetDefaultTableName(dbOwner string, dbFolder string, dbName string) (tableName string, err error)
Returns the default table name for a database.
func GetDiscussionAndMRCount ¶
func GetDiscussionAndMRCount(dbOwner string, dbFolder string, dbName string) (discCount int, mrCount int, err error)
Returns the discussion and merge request counts for a database TODO: The only reason this function exists atm, is because we're incorrectly caching the discussion and MR data in TODO a way that makes invalidating it correctly hard/impossible. We should redo our memcached approach to solve the TODO issue properly
func GetFormBranch ¶
Return the requested branch name, from get or post data.
func GetFormCommit ¶
Return the requested database commit, from form data.
func GetFormLicence ¶
Returns the licence name (if any) present in the form data
func GetFormRelease ¶
Return the requested release name, from get or post data.
func GetFormSourceURL ¶
Returns the source URL (if any) present in the form data
func GetFormTag ¶
Return the requested tag name, from get or post data.
func GetFormUDC ¶
Return the username, database, and commit (if any) present in the form data.
func GetLicence ¶
Returns the text for a given licence.
func GetLicenceInfoFromSha256 ¶
func GetLicenceInfoFromSha256(userName string, sha256 string) (lName string, lURL string, err error)
Returns the friendly name + licence URL for the licence matching a given sha256. Note - When user defined licence has the same sha256 as a default one we return the user defined licences' friendly name.
func GetLicenceSha256FromName ¶
Returns the sha256 for a given licence.
func GetLicences ¶
func GetLicences(user string) (map[string]LicenceEntry, error)
Returns the list of licences available to a user.
func GetPub ¶
Returns the requested "public" variable, if present in the form data. If something goes wrong, it defaults to "false".
func GetReleases ¶
func GetReleases(dbOwner string, dbFolder string, dbName string) (releases map[string]ReleaseEntry, err error)
Retrieve the list of releases for a database.
func GetSQLiteRowCount ¶
Returns the number of rows in a SQLite table.
func GetUsername ¶
Return the username (if any) present in the GET or POST/PUT data.
func GetUsernameFromEmail ¶
Returns the username associated with an email address.
func GetViewCount ¶
Retrieves the view count in memcached for a database
func IncrementDownloadCount ¶
Increments the download count for a database
func IncrementViewCount ¶
Increments the view counter in memcached for a database
func InvalidateCacheEntry ¶
func InvalidateCacheEntry(loggedInUser string, dbOwner string, dbFolder string, dbName string, commitID string) error
Invalidate memcache data for a database entry or entries
func IsCommitInBranchHistory ¶
func IsCommitInBranchHistory(dbOwner string, dbFolder string, dbName string, branchName string, commitID string) (bool, error)
Checks if a given commit ID is in the history of the given branch
func LogDownload ¶
func LogDownload(dbOwner string, dbFolder string, dbName string, loggedInUser string, ipAddr string, serverSw string, userAgent string, downloadDate time.Time, sha string) error
Create a download log entry
func LogUpload ¶
func LogUpload(dbOwner string, dbFolder string, dbName string, loggedInUser string, ipAddr string, serverSw string, userAgent string, uploadDate time.Time, sha string) error
Create an upload log entry
func MetadataCacheKey ¶
func MetadataCacheKey(prefix string, loggedInUser string, dbOwner string, dbFolder string, dbName string, commitID string) string
Generate a predictable cache key for metadata information
func MinioHandle ¶
Get a handle from Minio for a SQLite database object.
func MinioHandleClose ¶
func MinioHandleClose(userDB *minio.Object) (err error)
Close a Minio object handle. Probably most useful for calling with defer().
func MinioLocation ¶
func MinioLocation(dbOwner string, dbFolder string, dbName string, commitID string, loggedInUser string) (minioBucket string, minioID string, lastModified time.Time, err error)
Return the Minio bucket and ID for a given database. dbOwner, dbFolder, & dbName are from owner/folder/database URL fragment, // loggedInUser is the name for the currently logged in user, for access permission check. Use an empty string ("") as the loggedInUser parameter if the true value isn't set or known. If the requested database doesn't exist, or the loggedInUser doesn't have access to it, then an error will be returned.
func OpenMinioObject ¶
Retrieves a SQLite database from Minio, opens it, returns the connection handle. Also returns the name of the temp file created, which the caller needs to delete (os.Remove()) when finished with it
func PrefUserMaxRows ¶
Return the user's preference for maximum number of SQLite rows to display.
func ReadSQLiteDBCSV ¶
This is a specialised variation of the ReadSQLiteDB() function, just for our CSV exporting code. It'll probably need to be merged with the above function at some point.
func RenameDatabase ¶
Rename a SQLite database.
func ReservedUsernamesCheck ¶
Checks a username against the list of reserved ones.
func SanityCheck ¶
Performs basic sanity checks of an uploaded database.
func SaveDBSettings ¶
func SaveDBSettings(userName string, dbFolder string, dbName string, oneLineDesc string, fullDesc string, defaultTable string, public bool, sourceURL string, defaultBranch string) error
Saves updated database settings to PostgreSQL.
func SetClientCert ¶
Stores a certificate for a given client.
func SetUserPreferences ¶
Sets the user's preference for maximum number of SQLite rows to display.
func SetUserStatusUpdates ¶
Increments the view counter in memcached for a database
func SocialStats ¶
func SocialStats(dbOwner string, dbFolder string, dbName string) (wa int, st int, fo int, err error)
Retrieve the latest social stats for a given database.
func StatusUpdateCheck ¶
func StatusUpdateCheck(dbOwner string, dbFolder string, dbName string, thisID int, userName string) (numStatusUpdates int, err error)
Checks if a status update for the user exists for a given discussion or MR, and if so then removes it
func StatusUpdates ¶
func StatusUpdates(loggedInUser string) (statusUpdates map[string][]StatusUpdateEntry, err error)
Retrieve the list of outstanding status updates for a user
func StatusUpdatesLoop ¶
func StatusUpdatesLoop()
Periodically generates status updates (alert emails TBD) from the event queue
func StoreBranches ¶
func StoreBranches(dbOwner string, dbFolder string, dbName string, branches map[string]BranchEntry) error
Updates the branches list for a database.
func StoreComment ¶
func StoreComment(dbOwner string, dbFolder string, dbName string, commenter string, discID int, comText string, discClose bool, mrState MergeRequestState) error
Adds a comment to a discussion.
func StoreCommits ¶
func StoreCommits(dbOwner string, dbFolder string, dbName string, commitList map[string]CommitEntry) error
Updates the commit list for a database.
func StoreDatabase ¶
func StoreDatabase(dbOwner string, dbFolder string, dbName string, branches map[string]BranchEntry, c CommitEntry, pub bool, buf *os.File, sha string, dbSize int64, oneLineDesc string, fullDesc string, createDefBranch bool, branchName string, sourceURL string) error
Stores database details in PostgreSQL, and the database data itself in Minio.
func StoreDatabaseFile ¶
Store a database file in Minio.
func StoreDefaultBranchName ¶
Stores the default branch name for a database.
func StoreDefaultTableName ¶
Stores the default table name for a database.
func StoreDiscussion ¶
func StoreDiscussion(dbOwner string, dbFolder string, dbName string, loggedInUser string, title string, text string, discType DiscussionType, mr MergeRequestEntry) (newID int, err error)
Stores a new discussion for a database.
func StoreLicence ¶
func StoreLicence(userName string, licenceName string, txt []byte, url string, orderNum int, fullName string, fileFormat string) error
Store a licence.
func StoreReleases ¶
func StoreReleases(dbOwner string, dbFolder string, dbName string, releases map[string]ReleaseEntry) error
Store the releases for a database.
func StoreStatusUpdates ¶
func StoreStatusUpdates(userName string, statusUpdates map[string][]StatusUpdateEntry) error
Store the status updates list for a user
func TableRowsCacheKey ¶
func TableRowsCacheKey(prefix string, loggedInUser string, dbOwner string, dbFolder string, dbName string, commitID string, dbTable string, rows int) string
Generate a predictable cache key for SQLite row data
func ToggleDBStar ¶
Toggle on or off the starring of a database by a user.
func ToggleDBWatch ¶
Toggle on or off the watching of a database by a user.
func UpdateAvatarURL ¶
Updates the Avatar URL for a user.
func UpdateComment ¶
func UpdateComment(dbOwner string, dbFolder string, dbName string, loggedInUser string, discID int, comID int, newText string) error
Updates the text for a comment
func UpdateContributorsCount ¶
Updates the contributors count for a database.
func UpdateDiscussion ¶
func UpdateDiscussion(dbOwner string, dbFolder string, dbName string, loggedInUser string, discID int, newTitle string, newText string) error
Updates the text for a discussion
func UpdateMergeRequestCommits ¶
func UpdateMergeRequestCommits(dbOwner string, dbFolder string, dbName string, discID int, mrCommits []CommitEntry) (err error)
Updates the commit list for a Merge Request
func UserNameFromAuth0ID ¶
Returns the username for a given Auth0 ID.
func UserStatusUpdates ¶
Returns the number of status updates outstanding for a user
func ValidateBranchName ¶
Validate the provided branch, release, or tag name.
func ValidateCommitID ¶ added in v0.0.5
Validate the provided commit ID.
func ValidateDiscussionTitle ¶
Validate the provided discussion or merge request title.
func ValidateDisplayName ¶ added in v0.0.5
Validate a provided full name.
func ValidateFieldName ¶
Validate the SQLite field name.
func ValidateLicence ¶
Validate the provided licence name (ID).
func ValidateLicenceFullName ¶ added in v0.0.5
Validate the provided licence full name.
func ValidateMarkdown ¶
Validate the provided markdown.
func ValidatePGTable ¶
Validate the provided PostgreSQL table name.
func ValidateUserDB ¶
Validate the provided user and database name.
func ValidateUserDBTable ¶
Validate the provided user, database, and table name.
func ValidateUserEmail ¶
Validate the provided username and email address.
Types ¶
type ActivityRange ¶
type ActivityRange string
type ActivityRow ¶
type ActivityStats ¶
type ActivityStats struct { Downloads []ActivityRow Forked []ActivityRow Starred []ActivityRow Uploads []UploadRow Viewed []ActivityRow }
func GetActivityStats ¶
func GetActivityStats() (stats ActivityStats, err error)
type AdminInfo ¶
type AdminInfo struct { Certificate string CertificateKey string `toml:"certificate_key"` HTTPS bool Server string }
Config info for the admin server
type BranchEntry ¶
type CommitData ¶
type CommitData struct { AuthorAvatar string `json:"author_avatar"` AuthorEmail string `json:"author_email"` AuthorName string `json:"author_name"` AuthorUsername string `json:"author_username"` ID string `json:"id"` LicenceChange string `json:"licence_change"` Message string `json:"message"` Timestamp time.Time `json:"timestamp"` }
type CommitEntry ¶
type CommitEntry struct { AuthorEmail string `json:"author_email"` AuthorName string `json:"author_name"` CommitterEmail string `json:"committer_email"` CommitterName string `json:"committer_name"` ID string `json:"id"` Message string `json:"message"` OtherParents []string `json:"other_parents"` Parent string `json:"parent"` Timestamp time.Time `json:"timestamp"` Tree DBTree `json:"tree"` }
func GetCommonAncestorCommits ¶
func GetCommonAncestorCommits(srcOwner string, srcFolder string, srcDBName string, srcBranch string, destOwner string, destFolder string, destName string, destBranch string) (ancestorID string, commitList []CommitEntry, err error, errType int)
Determines the common ancestor commit (if any) between a source and destination branch. Returns the commit ID of the ancestor and a slice of the commits between them. If no common ancestor exists, the returned ancestorID will be an empty string. Created for use by our Merge Request functions.
type DB4SInfo ¶
type DB4SInfo struct { CAChain string `toml:"ca_chain"` Certificate string CertificateKey string `toml:"certificate_key"` Port int Server string }
Configuration info for the DB4S end point
type DBEntry ¶
type DBEntry struct { Folder string DateEntry time.Time DBName string Owner string OwnerDisplayName string `json:"display_name"` }
func UserStarredDBs ¶
Returns the list of databases starred by a user.
func UserWatchingDBs ¶
Returns the list of databases watched by a user.
func UsersStarredDB ¶
Returns the list of users who starred a database.
type DBInfo ¶
type DBInfo struct { Branch string Branches int BranchList []string Commits int CommitID string Contributors int Database string DateCreated time.Time DBEntry DBTreeEntry DefaultBranch string DefaultTable string Discussions int Downloads int Folder string Forks int FullDesc string LastModified time.Time Licence string LicenceURL string MRs int OneLineDesc string Public bool RepoModified time.Time Releases int SHA256 string Size int64 SourceURL string Stars int Tables []string Tags int Views int Watchers int }
type DBTree ¶
type DBTree struct { ID string `json:"id"` Entries []DBTreeEntry `json:"entries"` }
type DBTreeEntry ¶
type DBTreeEntryType ¶
type DBTreeEntryType string
type DiscussionCommentEntry ¶
type DiscussionCommentEntry struct { AvatarURL string `json:"avatar_url"` Body string `json:"body"` BodyRendered string `json:"body_rendered"` Commenter string `json:"commenter"` DateCreated time.Time `json:"creation_date"` EntryType DiscussionCommentType `json:"entry_type"` ID int `json:"com_id"` }
func DiscussionComments ¶
func DiscussionComments(dbOwner string, dbFolder string, dbName string, discID int, comID int) (list []DiscussionCommentEntry, err error)
Returns the list of comments for a given discussion. If a non-0 comID value is passed, it will only return the details for that specific comment in the discussion. Otherwise it will return a list of all comments for a given discussion Note - This returns a slice instead of a map. We use a slice because it lets us use an ORDER BY clause in the SQL
and preserve the returned order (maps don't preserve order). If in future we no longer need to preserve the order, it might be useful to switch to using a map instead since they're often simpler to work with.
type DiscussionCommentType ¶
type DiscussionCommentType string
type DiscussionEntry ¶
type DiscussionEntry struct { AvatarURL string `json:"avatar_url"` Body string `json:"body"` BodyRendered string `json:"body_rendered"` CommentCount int `json:"comment_count"` Creator string `json:"creator"` DateCreated time.Time `json:"creation_date"` ID int `json:"disc_id"` LastModified time.Time `json:"last_modified"` MRDetails MergeRequestEntry `json:"mr_details"` Open bool `json:"open"` Title string `json:"title"` Type DiscussionType `json:"discussion_type"` }
func Discussions ¶
func Discussions(dbOwner string, dbFolder string, dbName string, discType DiscussionType, discID int) (list []DiscussionEntry, err error)
Returns the list of discussions or MRs for a given database. If a non-0 discID value is passed, it will only return the details for that specific discussion/MR. Otherwise it will return a list of all discussions or MRs for a given database Note - This returns a slice of DiscussionEntry, instead of a map. We use a slice because it lets us use an ORDER
BY clause in the SQL and preserve the returned order (maps don't preserve order). If in future we no longer need to preserve the order, it might be useful to switch to using a map instead since they're often simpler to work with.
type DiscussionType ¶
type DiscussionType int
const ( DISCUSSION DiscussionType = 0 // These are not iota, as it would be seriously bad for these numbers to change MERGE_REQUEST = 1 )
type EventDetails ¶
type EventDetails struct { DBName string `json:"database_name"` DiscID int `json:"discussion_id"` Folder string `json:"database_folder"` ID string `json:"event_id"` Message string `json:"message"` Owner string `json:"database_owner"` Timestamp time.Time `json:"event_timestamp"` Title string `json:"title"` Type EventType `json:"event_type"` URL string `json:"event_url"` UserName string `json:"username"` }
type EventProcessingInfo ¶
type EventProcessingInfo struct { Delay time.Duration `toml:"delay"` EmailQueueDir string `toml:"email_queue_dir"` EmailQueueProcessingDelay time.Duration `toml:"email_queue_processing_delay"` }
Event processing loop
type ForkEntry ¶
type ForkEntry struct { DBName string `json:"database_name"` Folder string `json:"database_folder"` ForkedFrom int `json:"forked_from"` IconList []ForkType `json:"icon_list"` ID int `json:"id"` Owner string `json:"database_owner"` Processed bool `json:"processed"` Public bool `json:"public"` Deleted bool `json:"deleted"` }
type LicenceEntry ¶
type LicenceInfo ¶ added in v0.0.5
type LicenceInfo struct {
LicenceDir string `toml:"licence_dir"`
}
Path to the licence files
type MemcacheInfo ¶
type MemcacheInfo struct { DefaultCacheTime int `toml:"default_cache_time"` Server string `toml:"server"` ViewCountFlushDelay time.Duration `toml:"view_count_flush_delay"` }
Memcached connection parameters
type MergeRequestEntry ¶
type MergeRequestEntry struct { Commits []CommitEntry `json:"commits"` DestBranch string `json:"destination_branch"` SourceBranch string `json:"source_branch"` SourceDBID int64 `json:"source_database_id"` SourceDBName string `json:"source_database_name"` SourceFolder string `json:"source_folder"` SourceOwner string `json:"source_owner"` State MergeRequestState `json:"state"` }
type MergeRequestState ¶
type MergeRequestState int
type MinioInfo ¶
type MinioInfo struct { AccessKey string `toml:"access_key"` HTTPS bool Secret string Server string }
Minio connection parameters
type PGInfo ¶
type PGInfo struct { Database string NumConnections int `toml:"num_connections"` Port int Password string Server string SSL bool Username string }
PostgreSQL connection parameters
type RedashColumnMeta ¶ added in v0.0.5
type RedashColumnMeta struct { Name string `json:"name"` Type string `json:"type"` FriendlyName string `json:"friendly_name"` }
When SQLite data is prepared for sending to Redash (as JSON), the RedashColumnMeta and RedashTableData structures are used to hold it
type RedashTableData ¶ added in v0.0.5
type RedashTableData struct { Columns []RedashColumnMeta `json:"columns"` Rows []map[string]interface{} `json:"rows"` }
func ReadSQLiteDBRedash ¶ added in v0.0.5
func ReadSQLiteDBRedash(sdb *sqlite.Conn, dbTable string) (dash RedashTableData, err error)
This is a specialised variation of the ReadSQLiteDB() function, just for our Redash JSON exporting code. It'll probably need to be merged with the above function at some point.
type ReleaseEntry ¶
type SQLiteDBinfo ¶
type SQLiteRecordSet ¶
type SQLiteRecordSet struct { ColCount int ColNames []string Offset int Records []DataRow RowCount int SortCol string SortDir string Tablename string TotalRows int }
func ReadSQLiteDB ¶
func ReadSQLiteDB(sdb *sqlite.Conn, dbTable string, maxRows int, sortCol string, sortDir string, rowOffset int) (SQLiteRecordSet, error)
Reads up to maxRows number of rows from a given SQLite database table. If maxRows < 0 (eg -1), then read all rows.
type SigningInfo ¶
type SigningInfo struct { CertDaysValid int `toml:"cert_days_valid"` IntermediateCert string `toml:"intermediate_cert"` IntermediateKey string `toml:"intermediate_key"` }
Used for signing DB4S client certificates
type StatusUpdateEntry ¶
type TomlConfig ¶
type TomlConfig struct { Admin AdminInfo Auth0 Auth0Info DB4S DB4SInfo Environment EnvInfo DiskCache DiskCacheInfo Event EventProcessingInfo Licence LicenceInfo Memcache MemcacheInfo Minio MinioInfo Pg PGInfo Sign SigningInfo Web WebInfo }
Configuration file
var ( // Our configuration info Conf TomlConfig )
type UserDetails ¶
type WebInfo ¶
type WebInfo struct { BaseDir string `toml:"base_dir"` BindAddress string `toml:"bind_address"` Certificate string `toml:"certificate"` CertificateKey string `toml:"certificate_key"` RequestLog string `toml:"request_log"` ServerName string `toml:"server_name"` SessionStorePassword string `toml:"session_store_password"` }