core

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: GPL-3.0, GPL-3.0-or-later Imports: 19 Imported by: 0

Documentation

Overview

core contains the most central elements of mvoCI, except the webserver. it contains the global config object and the database connection. could be used without the webserver to have the same backend for e.g. CLI UI

Index

Constants

View Source
const (
	DEBUG = 0 // debug log level
	INFO  = 1 // info log level
	WARN  = 2 // warning log level
	FAIL  = 3 // failure log level
)
View Source
const ConfigFile string = "mvo.cfg"

configuration file

Variables

View Source
var BuildTime string = ""

build time entered by the linker (see Makefile)

View Source
var Compiler string = ""

Compiler version entered by the linker (see Makefile)

View Source
var Console lwrapper

Console is the main logging facility in mvoCI

View Source
var GitHash string = ""

git commit hash entered by the linker (see Makefile)

View Source
var LogFileEnable bool = false

is file logging enabled?

View Source
var LogStderrEnable bool = false

is stderr loggin enabled?

View Source
var LogStdoutEnable bool = true

is stdout logging enabled?

View Source
var Version string = "development"

version entered by the linker (see Makefile), either release number or git-sha

Functions

func ConfigWrite

func ConfigWrite(cfg *Config, filename string) error

write the config to the a file

func DBConnect

func DBConnect(cfg *Config) (*gorm.DB, error)

creates the database connection and creates the tables if they don't exist already depends on the following settings in the configuration ile:

  • database_provider : sets the type of database server, i.e. postgres, sqlite3, mssql, mysql
  • database_username : username for the database connection
  • database_password : the password for the database connection
  • database_host : if mysql, postgres or mssql - host of the database
  • database_filename : only sqlite3 - file (can be :memory)
  • database_port : communication port of the DB
  • database_dbname : the name of the database to use

func GenericJSONDecode

func GenericJSONDecode(rd io.Reader, pl interface{}) error

helper function for parsing JSON-files into an object of our choosing

func LogClose

func LogClose()

close the logger

Types

type AuthProvider

type AuthProvider struct {
	ID     uint   `gorm:"primary_key"`
	Name   string // name of the auth provider
	Type   string // name of the auth provider module
	Extra  string // information of the auth provider used for verification
	UserId uint   // reference to the according user
	User   User   // the user object
}

structure for an auth provider for a single user (not shared!)

type Build

type Build struct {
	ID            uint       `gorm:"primary_key"` // database ID
	CreatedAt     time.Time  // starting time of the build
	UpdatedAt     time.Time  // structure last updated
	StartedAt     time.Time  // the point when a build worker started the build
	FinishedAt    time.Time  // time of the moment the build finished
	Duration      string     `gorm:"-"` // duration, will not be created in database, used for calculating the duration of a build
	Status        string     // the status of the Build (started, finished, failed)
	Log           string     // build log
	CommitSha     string     // stores the commit reference
	CommitAuthor  string     // author of a commit
	CommitMessage string     // message of a commit
	CommitUrl     string     // url to view the commit in the CVS-interface
	Event         string     // event string, why the build was built
	Branch        string     // stores the branch built
	Zip           string     // keeps the name of the zipped Build
	Repository    Repository // link to the Repository
	RepositoryID  uint
	Api           string // build because of which api?
	ApiUrl        string
	BuildScript   BuildScript
	BuildScriptID uint
}

structure representing a Build of Repositories

type BuildScript

type BuildScript struct {
	ID           uint `gorm:"primary_key"`
	CreatedAt    time.Time
	UpdatedAt    time.Time
	EventType    string // script for which event?
	ShellScript  string // shell script to be executed
	RepositoryID uint
	Repository   Repository
}

structure for build scripts

type Config

type Config struct {
	AppTitle             string // title of the application (defaults to mvoCI)
	Install              bool   // is the application currently in installation mode
	Debug                bool   // set it into debug mode
	HttpPort             int    // the http port to be used
	HttpHost             string // the http host to be used
	LogFile              string // path to the log file
	LogServer            string // log file for the echo webserver
	LogFileEnable        bool   // enable the file-log
	LogMode              string // writing logs to stdout or stderr?
	LoginTokenDuration   int    // how long does a loginToken survive if inactive?
	LoginTokenInvalidate bool   // invalidate all loginTokens at start-up?
	ParallelBuilds       int    // number of parallel workers to be spawned
	CompressionMethod    string // compression method to be used for the artifacts (file-ending to be used with tar command)
	RepoSecretShow       bool   // should the repo-page show the secret or a placeholder?
	Directory            ConfigDirectory
	Author               ConfigAuthor
	Database             ConfigDatabase
	WebHookLog           bool // log events of the webhook for debugging purposes?
	PublicEnable         bool // have a page with the publically visible repositories?
	Api                  ConfigApi
	Build                ConfigBuild
	GiteaApi             ConfigOauth
	Auth                 ConfigAuth
}

global config structure

func ConfigDefault

func ConfigDefault() Config

generate the default configuration

func ConfigRead

func ConfigRead(filename string) (Config, error)

reads the configuration from file to a KeyValueStore-object

func (Config) Reflect

func (cfg Config) Reflect(q string) string

reflect into the config-object for using config in the templates

type ConfigApi

type ConfigApi struct {
	Enable           bool // is the API feature enabled?
	ListingEnable    bool // should a listing of the API be available
	ListingNeedsAuth bool // is authentication needed for showing the listing of the API?
}

information about the API Enable the api for more elegant page refresh on ongoing builds and a search feature on repos

type ConfigAuth

type ConfigAuth struct {
	TOTPEnable   bool // is totp enabled?
	NativeEnable bool // is native password auth enabled?
}

information about the authentication providers

type ConfigAuthor

type ConfigAuthor struct {
	Email   string // email address of the webmaster
	Name    string // name of the webmaster
	Street  string // address information
	Zip     string // zip code
	City    string // the city
	Privacy string // privacy and gdpr information text
}

information about the author for the impress

type ConfigBuild

type ConfigBuild struct {
	RefreshPage     bool // whether or not the page should be refreshed automagically at all
	RefreshInterval int  // interval in seconds at which the page should be refreshed automagically
}

configuration about the build page, with an ongoing build if the api is enabled, this gives the pace at which the pace at which query will be sent by javascript

type ConfigDatabase

type ConfigDatabase struct {
	Provider    string // database provider, i.e. sqlite, mssql, mysql or postgres (supported by gorm.io)
	Username    string // username for auth at the database
	Password    string // password for auth at the database
	Port        int    // port of the databases socket
	Host        string // host, as it may be on another machine
	Dbname      string // name of the database to use
	Filename    string // filename of the sqlite database if used
	PostgresSSL string // whether or not postgres should use ssl/tsl encryption
}

configuration about the database connection

type ConfigDirectory

type ConfigDirectory struct {
	Repo  string // directory for checkout of the repositories for building
	Build string // directory for storing the build artifacts
}

structure for directory configurations

type ConfigOauth

type ConfigOauth struct {
	OauthClientId     string // OAuth Client ID
	OauthClientSecret string // OAuth Secret
}

information about (a single) OAuth token

type Group

type Group struct {
	gorm.Model
	User []*User `gorm:"many2many:user_groups"` // a list of users in this group
}

group information TODO: is that used?

type LogWrapper

type LogWrapper interface {
	Debug(...interface{})
	Debugf(string, ...interface{})
	Log(...interface{})
	Logf(string, ...interface{})
	Warn(...interface{})
	Warnf(string, ...interface{})
	Fail(...interface{})
	Failf(string, ...interface{})
}

structure containing callback for different log levels

func LogInit

func LogInit(lf string) (LogWrapper, error)

initialize the logging facility

type LoginToken

type LoginToken struct {
	ID        uint      `gorm:"primary_key"` // database ID
	CreatedAt time.Time // date of creation
	ExpiresAt time.Time // Expiration Date of the loginToken
	Name      string    // name of that LoginToken, e.g. for API tokens
	UserID    uint      // Link to the user holding the Token
	User      User
	Type      string // api or login-token?
	Secret    string // a secret string
	Step      string // auth step, at which this loginToken sits
	StepExtra string // extra information of the authProvider of the next step, e.g. for storing seeds for the next try
}

structure for LoginTokens, used for authentification after login

type OauthToken

type OauthToken struct {
	ID           uint `gorm:"primary_key"`
	CreatedAt    time.Time
	UpdatedAt    time.Time
	State        string
	Name         string
	Api          string
	Url          string
	UserID       uint
	ClientId     string
	ClientSecret string
	ClientToken  string
	RedirectUri  string
}

OAuthToken for the gitea release-hook

type Repository

type Repository struct {
	ID               uint `gorm:"primary_key"`
	CreatedAt        time.Time
	UpdatedAt        time.Time
	Name             string        // name of the repository
	Secret           string        // secret of the repository to be used with the webhook feature of gitea, gogs, etc.
	CloneUrl         string        // the clone url is to be used when building the repository for cloning and for finding out which repo needs to be build when receiving a webhook event.
	BuildCount       uint          // number of bulds of this repository. TODO: is that used?
	DefaultBranch    string        // default branch to be build when nothing else is specified (master or main)
	BuildScript      string        // TODO: remove. OBSOLETE! WILL BE REMOVED SOON
	BuildScripts     []BuildScript // list of buildScripts for more advanced building (release vs. debug,...)
	WebHookEnable    bool          // enable webhook events for this repository
	LocalBuildEnable bool          // enable local build events from cli. TODO: do I need this feature?
	KeepBuilds       bool          // keep build artifacts?
	UserID           uint
	User             User
	Public           bool // is this repository to be shown on the Public Repository page? Only successful builds are shown there. Needs cfg.PublicEnable
}

structure representing a Repository

type ServerLogger

type ServerLogger struct {
	// contains filtered or unexported fields
}

ServerLogger for the echo web server

func ServerLoggerNew

func ServerLoggerNew(logfile string) (*ServerLogger, error)

create a new server logger by opening the logfile

func (ServerLogger) Close

func (s ServerLogger) Close()

close the server logger on shutdown

func (ServerLogger) Write

func (s ServerLogger) Write(p []byte) (n int, err error)

write into the server logger

type Thread

type Thread uintptr

func Pthread_create

func Pthread_create(cb ThreadCallback) Thread

initializes a thread using pthread_create

func (Thread) Pthread_join

func (t Thread) Pthread_join()

func (Thread) Pthread_kill

func (t Thread) Pthread_kill()

signals the thread in question to terminate

func (Thread) Running

func (t Thread) Running() bool

determines if the thread is running

type ThreadCallback

type ThreadCallback func()

type User

type User struct {
	ID                uint      `gorm:"primary_key"` // database ID
	CreatedAt         time.Time // time the record was created
	UpdatedAt         time.Time // time the record was last updated
	Name              string    // the username of the user
	Passhash          string    // a hashed password
	Email             string    // email address of the user
	Superuser         bool      // is the user a superuser or not?
	Group             []*Group  `gorm:"many2many:user_groups"`
	AuthProvider      string    // name of the main auth provider
	AuthProviderExtra string    // extra information for the main auth provider
	AuthExtra         string    // extra information for the main auth provider
}

structure representing a user

func (*User) Reset

func (u *User) Reset()

resets a user structure to a null-value TODO: is that used? Maybe replace with u = core.User{} ?

type WebHookLog

type WebHookLog struct {
	ID             uint `gorm:"primary_key"`
	CreatedAt      time.Time
	Status         string     // of the webhook event, successful or not?
	API            string     // which api endpoint was used?
	Request        string     // the request body of the webhook request
	ResponseBody   string     // body of the response sent by mvoCI
	ResponseStatus int        // status of the response (ideally 200 if successful)
	Repository     Repository // link to the Repository
	RepositoryID   uint
	Build          Build // link to the Build
	BuildID        uint
}

log entry for webhook events

Jump to

Keyboard shortcuts

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