util

package
v0.2.54 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbDriverMySQL    = "mysql"
	DbDriverBolt     = "bolt"
	DbDriverPostgres = "postgres"
)
View Source
const (
	// GoGitClientId is builtin Git client. It is not require external dependencies and is preferred.
	// Use it if you don't need external SSH authorization.
	GoGitClientId = "go_git"
	// CmdGitClientId is external Git client.
	// Default Git client. It is use external Git binary to clone repositories.
	CmdGitClientId = "cmd_git"
)

Variables

Cookie is a runtime generated secure cookie used for authentication

View Source
var WebHostURL *url.URL

WebHostURL is the public route to the distro server

Functions

func AnsibleVersion

func AnsibleVersion() string

func CheckUpdate

func CheckUpdate() (updateAvailable *github.RepositoryRelease, err error)

CheckUpdate uses the GitHub client to check for new tags in the distro repo

func ConfigInit

func ConfigInit(configPath string)

ConfigInit reads in cli flags, and switches actions appropriately on them

func FindDistro

func FindDistro() string

FindDistro looks in the PATH for the distro variable if not found it will attempt to find the absolute path of the first os argument, the distro command, and return it

func LogError

func LogError(err error)

LogError logs an error with arbitrary field if error

func LogErrorWithFields

func LogErrorWithFields(err error, fields log.Fields)

LogErrorWithFields logs a error with added field context if error

func LogPanic

func LogPanic(err error)

LogPanic logs and panics with arbitrary field if error

func LogPanicWithFields

func LogPanicWithFields(err error, fields log.Fields)

LogPanicWithFields logs and panics with added field context if error

func LogWarning

func LogWarning(err error)

LogWarning logs a warning with arbitrary field if error

func LogWarningWithFields

func LogWarningWithFields(err error, fields log.Fields)

LogWarningWithFields logs a warning with added field context if error

func RandString

func RandString(n int) string

func SendMail

func SendMail(emailHost, mailSender, mailRecipient string, mail bytes.Buffer) error

SendMail dispatches a mail using smtp

func SendSecureMail

func SendSecureMail(emailHost, emailPort, mailSender, mailUsername, mailPassword, mailRecipient string, mail bytes.Buffer) error

SendSecureMail dispatches a mail using smtp with authentication and StartTLS

Types

type ConfigType

type ConfigType struct {
	MySQL    DbConfig `json:"mysql"`
	BoltDb   DbConfig `json:"bolt"`
	Postgres DbConfig `json:"postgres"`

	Dialect string `json:"dialect" rule:"^mysql|bolt|postgres$" env:"DISTRO_DB_DIALECT"`

	// Format `:port_num` eg, :3000
	// if : is missing it will be corrected
	Port string `json:"port" default:":3000" rule:"^:?([0-9]{1,5})$" env:"DISTRO_PORT"`

	// Interface ip, put in front of the port.
	// defaults to empty
	Interface string `json:"interface" env:"DISTRO_INTERFACE"`

	// distro stores ephemeral projects here
	TmpPath string `json:"tmp_path" default:"/tmp/distro" env:"DISTRO_TMP_PATH"`

	// SshConfigPath is a path to the custom SSH config file.
	// Default path is ~/.ssh/config.
	SshConfigPath string `json:"ssh_config_path" env:"DISTRO_TMP_PATH"`

	GitClientId string `json:"git_client" rule:"^go_git|cmd_git$" env:"DISTRO_GIT_CLIENT" default:"cmd_git"`

	// web host
	WebHost string `json:"web_host" env:"DISTRO_WEB_ROOT"`

	// cookie hashing & encryption
	CookieHash       string `json:"cookie_hash" env:"DISTRO_COOKIE_HASH"`
	CookieEncryption string `json:"cookie_encryption" env:"DISTRO_COOKIE_ENCRYPTION"`
	// AccessKeyEncryption is BASE64 encoded byte array used
	// for encrypting and decrypting access keys stored in database.
	AccessKeyEncryption string `json:"access_key_encryption" env:"DISTRO_ACCESS_KEY_ENCRYPTION"`

	// email alerting
	EmailAlert    bool   `json:"email_alert" env:"DISTRO_EMAIL_ALERT"`
	EmailSender   string `json:"email_sender" env:"DISTRO_EMAIL_SENDER"`
	EmailHost     string `json:"email_host" env:"DISTRO_EMAIL_HOST"`
	EmailPort     string `json:"email_port" rule:"^(|[0-9]{1,5})$" env:"DISTRO_EMAIL_PORT"`
	EmailUsername string `json:"email_username" env:"DISTRO_EMAIL_USERNAME"`
	EmailPassword string `json:"email_password" env:"DISTRO_EMAIL_PASSWORD"`
	EmailSecure   bool   `json:"email_secure" env:"DISTRO_EMAIL_SECURE"`

	// ldap settings
	LdapEnable       bool         `json:"ldap_enable" env:"DISTRO_LDAP_ENABLE"`
	LdapBindDN       string       `json:"ldap_binddn" env:"DISTRO_LDAP_BIND_DN"`
	LdapBindPassword string       `json:"ldap_bindpassword" env:"DISTRO_LDAP_BIND_PASSWORD"`
	LdapServer       string       `json:"ldap_server" env:"DISTRO_LDAP_SERVER"`
	LdapSearchDN     string       `json:"ldap_searchdn" env:"DISTRO_LDAP_SEARCH_DN"`
	LdapSearchFilter string       `json:"ldap_searchfilter" env:"DISTRO_LDAP_SEARCH_FILTER"`
	LdapMappings     ldapMappings `json:"ldap_mappings"`
	LdapNeedTLS      bool         `json:"ldap_needtls" env:"DISTRO_LDAP_NEEDTLS"`

	// telegram and slack alerting
	TelegramAlert bool   `json:"telegram_alert" env:"DISTRO_TELEGRAM_ALERT"`
	TelegramChat  string `json:"telegram_chat" env:"DISTRO_TELEGRAM_CHAT"`
	TelegramToken string `json:"telegram_token" env:"DISTRO_TELEGRAM_TOKEN"`
	SlackAlert    bool   `json:"slack_alert" env:"DISTRO_SLACK_ALERT"`
	SlackUrl      string `json:"slack_url" env:"DISTRO_SLACK_URL"`

	// oidc settings
	OidcProviders map[string]OidcProvider `json:"oidc_providers"`

	// task concurrency
	MaxParallelTasks int `json:"max_parallel_tasks" default:"10" rule:"^[0-9]{1,10}$" env:"DISTRO_MAX_PARALLEL_TASKS"`

	RunnerRegistrationToken string `json:"runner_registration_token" env:"DISTRO_RUNNER_REGISTRATION_TOKEN"`

	// feature switches
	PasswordLoginDisable     bool `json:"password_login_disable" env:"DISTRO_PASSWORD_LOGIN_DISABLED"`
	NonAdminCanCreateProject bool `json:"non_admin_can_create_project" env:"DISTRO_NON_ADMIN_CAN_CREATE_PROJECT"`

	UseRemoteRunner bool `json:"use_remote_runner" env:"DISTRO_USE_REMOTE_RUNNER"`

	Runner RunnerSettings `json:"runner"`
}

ConfigType mapping between Config and the json file that sets it

var Config *ConfigType

Config exposes the application configuration storage for use in the application

func (*ConfigType) GenerateSecrets

func (conf *ConfigType) GenerateSecrets()

GenerateSecrets generates cookie secret during setup

func (*ConfigType) GetDBConfig

func (conf *ConfigType) GetDBConfig() (dbConfig DbConfig, err error)

func (*ConfigType) GetDialect

func (conf *ConfigType) GetDialect() (dialect string, err error)

func (*ConfigType) PrintDbInfo

func (conf *ConfigType) PrintDbInfo()

func (*ConfigType) ToJSON

func (conf *ConfigType) ToJSON() ([]byte, error)

ToJSON returns a JSON string of the config

type DbConfig

type DbConfig struct {
	Dialect string `json:"-"`

	Hostname string            `json:"host" env:"DISTRO_DB_HOST"`
	Username string            `json:"user" env:"DISTRO_DB_USER"`
	Password string            `json:"pass" env:"DISTRO_DB_PASS"`
	DbName   string            `json:"name" env:"DISTRO_DB"`
	Options  map[string]string `json:"options"`
}

func (*DbConfig) GetConnectionString

func (d *DbConfig) GetConnectionString(includeDbName bool) (connectionString string, err error)

func (*DbConfig) GetDbName

func (d *DbConfig) GetDbName() string

func (*DbConfig) GetHostname

func (d *DbConfig) GetHostname() string

func (*DbConfig) GetPassword

func (d *DbConfig) GetPassword() string

func (*DbConfig) GetUsername

func (d *DbConfig) GetUsername() string

func (*DbConfig) HasSupportMultipleDatabases

func (d *DbConfig) HasSupportMultipleDatabases() bool

func (*DbConfig) IsPresent

func (d *DbConfig) IsPresent() bool

type OidcProvider

type OidcProvider struct {
	ClientID      string       `json:"client_id"`
	ClientSecret  string       `json:"client_secret"`
	RedirectURL   string       `json:"redirect_url"`
	Scopes        []string     `json:"scopes"`
	DisplayName   string       `json:"display_name"`
	Color         string       `json:"color"`
	Icon          string       `json:"icon"`
	AutoDiscovery string       `json:"provider_url"`
	Endpoint      oidcEndpoint `json:"endpoint"`
	UsernameClaim string       `json:"username_claim" default:"preferred_username"`
	NameClaim     string       `json:"name_claim" default:"preferred_username"`
	EmailClaim    string       `json:"email_claim" default:"email"`
}

type RunnerSettings

type RunnerSettings struct {
	ApiURL            string `json:"api_url" env:"DISTRO_RUNNER_API_URL"`
	RegistrationToken string `json:"registration_token" env:"DISTRO_RUNNER_REGISTRATION_TOKEN"`
	ConfigFile        string `json:"config_file" env:"DISTRO_RUNNER_CONFIG_FILE"`
	// OneOff indicates than runner runs only one job and exit
	OneOff bool `json:"one_off" env:"DISTRO_RUNNER_ONE_OFF"`

	Webhook          string `json:"webhook" env:"DISTRO_RUNNER_WEBHOOK"`
	MaxParallelTasks int    `json:"max_parallel_tasks" default:"1" env:"DISTRO_RUNNER_MAX_PARALLEL_TASKS"`
}

Jump to

Keyboard shortcuts

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