Go API Documentation

github.com/semaphoreui/semaphore/util

No package summary is available.

Package

Files: 8. Third party imports: 5. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

Vars

Config exposes the application configuration storage for use in the application

Cookie is a runtime generated secure cookie used for authentication

WebHostURL is the public route to the semaphore server

ansiCodeRE is a regex to remove ANSI escape sequences from a string. ANSI escape sequences are typically in the form: \x1b[<parameters><letter>

https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang

Types

App

This type doesn't have documentation.

Field name Field type Comment
Active

bool

No comment on field.
Priority

int

No comment on field.
Title

string

No comment on field.
Icon

string

No comment on field.
Color

string

No comment on field.
DarkColor

string

No comment on field.
AppPath

string

No comment on field.
AppArgs

[]string

No comment on field.

AuthConfig

This type doesn't have documentation.

Field name Field type Comment
Totp

*TotpConfig

No comment on field.

ClaimsProvider

This type doesn't have documentation.

Field name Field type Comment
type

any

No comment on field.

ConfigLog

This type doesn't have documentation.

Field name Field type Comment
Events

*EventLogType

No comment on field.
Tasks

*TaskLogType

No comment on field.

ConfigProcess

This type doesn't have documentation.

Field name Field type Comment
User

string

No comment on field.
UID

*int

No comment on field.
Chroot

string

No comment on field.
GID

*int

No comment on field.

ConfigType

ConfigType mapping between Config and the json file that sets it

Field name Field type Comment
MySQL

*DbConfig

No comment on field.
BoltDb

*DbConfig

No comment on field.
Postgres

*DbConfig

No comment on field.
Dialect

string

No comment on field.
Port

string

Format :port_num eg, :3000 if : is missing it will be corrected

TLS

*TLSConfig

No comment on field.
Auth

*AuthConfig

No comment on field.
Interface

string

Interface ip, put in front of the port. defaults to empty

TmpPath

string

semaphore stores ephemeral projects here

SshConfigPath

string

SshConfigPath is a path to the custom SSH config file. Default path is ~/.ssh/config.

GitClientId

string

No comment on field.
WebHost

string

web host

CookieHash

string

cookie hashing & encryption

CookieEncryption

string

No comment on field.
AccessKeyEncryption

string

AccessKeyEncryption is BASE64 encoded byte array used for encrypting and decrypting access keys stored in database.

EmailAlert

bool

email alerting

EmailSender

string

No comment on field.
EmailHost

string

No comment on field.
EmailPort

string

No comment on field.
EmailUsername

string

No comment on field.
EmailPassword

string

No comment on field.
EmailSecure

bool

No comment on field.
EmailTls

bool

No comment on field.
EmailTlsMinVersion

string

No comment on field.
LdapEnable

bool

ldap settings

LdapBindDN

string

No comment on field.
LdapBindPassword

string

No comment on field.
LdapServer

string

No comment on field.
LdapSearchDN

string

No comment on field.
LdapSearchFilter

string

No comment on field.
LdapMappings

*LdapMappings

No comment on field.
LdapNeedTLS

bool

No comment on field.
TelegramAlert

bool

Telegram, Slack, Rocket.Chat, Microsoft Teams, DingTalk, and Gotify alerting

TelegramChat

string

No comment on field.
TelegramToken

string

No comment on field.
SlackAlert

bool

No comment on field.
SlackUrl

string

No comment on field.
RocketChatAlert

bool

No comment on field.
RocketChatUrl

string

No comment on field.
MicrosoftTeamsAlert

bool

No comment on field.
MicrosoftTeamsUrl

string

No comment on field.
DingTalkAlert

bool

No comment on field.
DingTalkUrl

string

No comment on field.
GotifyAlert

bool

No comment on field.
GotifyUrl

string

No comment on field.
GotifyToken

string

No comment on field.
OidcProviders

map[string]OidcProvider

oidc settings

MaxTaskDurationSec

int

No comment on field.
MaxTasksPerTemplate

int

No comment on field.
MaxParallelTasks

int

task concurrency

RunnerRegistrationToken

string

No comment on field.
PasswordLoginDisable

bool

feature switches

NonAdminCanCreateProject

bool

No comment on field.
UseRemoteRunner

bool

No comment on field.
IntegrationAlias

string

No comment on field.
Apps

map[string]App

No comment on field.
Runner

*RunnerConfig

No comment on field.
EnvVars

map[string]string

No comment on field.
ForwardedEnvVars

[]string

No comment on field.
Log

*ConfigLog

No comment on field.
Process

*ConfigProcess

No comment on field.
Schedule

*ScheduleConfig

No comment on field.
Debugging

*DebuggingConfig

No comment on field.

DbConfig

This type doesn't have documentation.

Field name Field type Comment
Dialect

string

No comment on field.
Hostname

string

No comment on field.
Username

string

No comment on field.
Password

string

No comment on field.
DbName

string

No comment on field.
Options

map[string]string

No comment on field.

DebuggingConfig

This type doesn't have documentation.

Field name Field type Comment
ApiDelay

string

No comment on field.
PprofDumpDir

string

No comment on field.

EventLogAction

This type doesn't have documentation.

Field name Field type Comment
type

string

No comment on field.

EventLogRecord

This type doesn't have documentation.

Field name Field type Comment
Action

string

No comment on field.
UserID

*int

No comment on field.
IntegrationID

*int

No comment on field.
ProjectID

*int

No comment on field.
Description

*string

No comment on field.

EventLogType

This type doesn't have documentation.

Field name Field type Comment
Format

FileLogFormat

No comment on field.
Enabled

bool

No comment on field.
Logger

*lumberjack.Logger

No comment on field.

FileLogFormat

This type doesn't have documentation.

Field name Field type Comment
type

string

No comment on field.

LdapMappings

This type doesn't have documentation.

Field name Field type Comment
DN

string

No comment on field.
Mail

string

No comment on field.
UID

string

No comment on field.
CN

string

No comment on field.

OidcProvider

This type doesn't have documentation.

Field name Field type Comment
ClientID

string

No comment on field.
ClientIDFile

string

No comment on field.
ClientSecret

string

No comment on field.
ClientSecretFile

string

No comment on field.
RedirectURL

string

No comment on field.
Scopes

[]string

No comment on field.
DisplayName

string

No comment on field.
Color

string

No comment on field.
Icon

string

No comment on field.
AutoDiscovery

string

No comment on field.
Endpoint

oidcEndpoint

No comment on field.
UsernameClaim

string

No comment on field.
NameClaim

string

No comment on field.
EmailClaim

string

No comment on field.
Order

int

No comment on field.

RunnerConfig

This type doesn't have documentation.

Field name Field type Comment
RegistrationToken

string

No comment on field.
Token

string

No comment on field.
TokenFile

string

No comment on field.
PrivateKeyFile

string

No comment on field.
OneOff

bool

OneOff indicates than runner runs only one job and exit. It is very useful for dynamic runners. How it works? Example:

  1. User starts the task.
  2. Semaphore found runner for task and calls runner's webhook if it provided.
  3. Your server or lambda handling the call and starts the one-off runner.
  4. The runner connects to the Semaphore server and handles the enqueued task(s).
Webhook

string

No comment on field.
MaxParallelTasks

int

No comment on field.

ScheduleConfig

This type doesn't have documentation.

Field name Field type Comment
Timezone

string

No comment on field.

TLSConfig

This type doesn't have documentation.

Field name Field type Comment
Enabled

bool

No comment on field.
CertFile

string

No comment on field.
KeyFile

string

No comment on field.
HTTPRedirectPort

*int

No comment on field.

TaskLogRecord

This type doesn't have documentation.

Field name Field type Comment
Username

string

No comment on field.
TaskID

int

No comment on field.
ProjectID

int

No comment on field.
TemplateID

int

No comment on field.
TemplateName

string

No comment on field.
UserID

*int

No comment on field.
Description

*string

No comment on field.
RunnerID

*int

No comment on field.
Status

task_logger.TaskStatus

No comment on field.

TaskLogType

This type doesn't have documentation.

Field name Field type Comment
Enabled

bool

No comment on field.
Format

FileLogFormat

No comment on field.
Logger

*lumberjack.Logger

No comment on field.
ResultLogger

*lumberjack.Logger

No comment on field.

TotpConfig

This type doesn't have documentation.

Field name Field type Comment
Enabled

bool

No comment on field.
AllowRecovery

bool

No comment on field.

oidcEndpoint

This type doesn't have documentation.

Field name Field type Comment
IssuerURL

string

No comment on field.
AuthURL

string

No comment on field.
TokenURL

string

No comment on field.
UserInfoURL

string

No comment on field.
JWKSURL

string

No comment on field.
Algorithms

[]string

No comment on field.

Functions

func AnsibleVersion

Uses: exec.Command.

func AssignMapToStruct

Uses: reflect.ValueOf.

func CastValueToKind

Uses: fmt.Sprintf, reflect.Bool, reflect.Int, reflect.String, reflect.ValueOf.

func CheckUpdate

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

Uses: context.TODO, github.NewClient.

func ClearDir

Uses: os.IsNotExist, os.Open, os.RemoveAll, path.Join, strings.HasPrefix.

func ClearFromAnsiCodes

func ConfigInit

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

Uses: base64.StdEncoding, fmt.Println, os.ReadFile, securecookie.New, strings.TrimSpace, url.Parse.

func FindSemaphore

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

Uses: exec.LookPath, filepath.Abs, os.Args.

func GeneratePrivateKey

Uses: bufio.NewWriter, bytes.Buffer, pem.Block, pem.Encode, rand.Reader, rsa.GenerateKey, x509.MarshalPKCS1PrivateKey, x509.MarshalPKCS1PublicKey.

func GenerateRecoveryCode

Uses: base32.NoPadding, base32.StdEncoding, bcrypt.DefaultCost, bcrypt.GenerateFromPassword, io.ReadFull, rand.Reader.

func GetPublicAliasURL

Uses: strings.HasSuffix.

func GetPublicHost

Uses: strings.HasPrefix.

func Goid

Uses: log.Debug, runtime.Stack, strconv.Atoi, strings.Fields, strings.TrimPrefix.

func LogDebugF

LogDebugF logs a debug with added field context if error

Uses: log.WithFields.

func LogError

LogError logs an error with arbitrary field if error

Uses: log.Fields.

func LogErrorF

LogErrorF logs a error with added field context if error

Uses: log.WithFields.

func LogGoid

Uses: log.Info.

func LogPanic

LogPanic logs and panics with arbitrary field if error

Uses: log.Fields.

func LogPanicF

LogPanicF logs and panics with added field context if error

Uses: log.WithFields.

func LogWarning

LogWarning logs a warning with arbitrary field if error

Uses: log.Fields.

func LogWarningF

LogWarningF logs a warning with added field context if error

Uses: log.WithFields.

func LookupDefaultApps

Uses: exec.LookPath.

func NewConfigType

func RandString

func VerifyRecoveryCode

Uses: bcrypt.CompareHashAndPassword.

func Version

Uses: strings.Join.

func (*ConfigType) ClearProjectTmpDir

func (*ConfigType) ClearTmpDir

func (*ConfigType) GenerateSecrets

GenerateSecrets generates cookie secret during setup

Uses: base64.StdEncoding, securecookie.GenerateRandomKey.

func (*ConfigType) GetDBConfig

Uses: errors.New.

func (*ConfigType) GetDialect

Uses: errors.New.

func (*ConfigType) GetProjectTmpDir

Uses: fmt.Sprintf, path.Join.

func (*ConfigType) GetSysProcAttr

Uses: strconv.Atoi, syscall.Credential, syscall.SysProcAttr, user.Lookup.

func (*ConfigType) PrintDbInfo

PrintDbInfo prints the database connection information based on the current configuration. It retrieves the database dialect and prints the corresponding connection details. If the dialect is not found, it panics with an error message.

Uses: fmt.Errorf, fmt.Printf.

func (*ConfigType) ToJSON

ToJSON returns a JSON string of the config

Uses: json.MarshalIndent.

func (*DbConfig) GetConnectionString

GetConnectionString constructs the database connection string based on the current configuration. It supports MySQL, BoltDB, and PostgreSQL dialects. If the dialect is unsupported, it returns an error.

Parameters:

  • includeDbName: a boolean indicating whether to include the database name in the connection string.

Returns:

  • connectionString: the constructed database connection string.
  • err: an error if the dialect is unsupported.

Uses: fmt.Errorf, fmt.Sprintf, url.QueryEscape.

func (*DbConfig) GetDbName

Uses: os.Getenv.

func (*DbConfig) GetHostname

Uses: os.Getenv.

func (*DbConfig) GetPassword

Uses: os.Getenv.

func (*DbConfig) GetUsername

Uses: os.Getenv.

func (*DbConfig) HasSupportMultipleDatabases

func (*DbConfig) IsPresent

func (*EventLogType) Write

func (*LdapMappings) GetEmailClaim

func (*LdapMappings) GetNameClaim

func (*LdapMappings) GetUsernameClaim

func (*OidcProvider) GetEmailClaim

func (*OidcProvider) GetNameClaim

func (*OidcProvider) GetUsernameClaim

func (*TaskLogType) Write

Private functions

func assignMapToStructRecursive

References: fmt.Errorf, reflect.MakeMap, reflect.Map, reflect.New, reflect.Struct, reflect.Value, reflect.ValueOf, strings.Split.

func castStringToBool

References: strings.ToLower.

func castStringToInt

References: strconv.Atoi.

func cloneStruct

References: reflect.New.

func decodeConfig

References: fmt.Println, json.NewDecoder.

func exitOnConfigError

References: fmt.Println, os.Exit.

func exitOnConfigFileError

func getConfigValue

References: fmt.Errorf, fmt.Sprintf, reflect.Indirect, reflect.Invalid, reflect.Pointer, reflect.Struct, reflect.ValueOf, strings.Split.

func loadConfigDefaults

func loadConfigEnvironment

func loadConfigFile

References: os.File, os.Getenv, os.Getwd, os.Open, os.Stat, path.Join.

func loadDefaultsToObject

References: reflect.Indirect, reflect.Map, reflect.New, reflect.Ptr, reflect.Struct, reflect.TypeOf, reflect.ValueOf.

func loadEnvironmentToObject

References: os.LookupEnv, reflect.Indirect, reflect.New, reflect.Ptr, reflect.Struct, reflect.TypeOf, reflect.ValueOf.

func mapToQueryString

func setConfigValue

References: fmt.Errorf, json.Unmarshal, reflect.Map, reflect.New, reflect.Slice, reflect.ValueOf.

func validate

References: fmt.Errorf, reflect.Indirect, reflect.Int, reflect.Ptr, reflect.TypeOf, reflect.Uint, reflect.ValueOf, regexp.MatchString, strconv.FormatInt, strconv.FormatUint, strings.Contains, strings.ToLower.

func validateConfig


Tests

Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 12. Benchmarks: 0.

Test functions

TestCastStringToBool

TestCastStringToInt

TestConfigInitialization

TestGetConfigValue

References: fmt.Sprintf.

TestLoadConfigDefaults

TestLoadConfigEnvironmet

References: os.Setenv.

TestLoadEnvironmentToObject

References: os.Setenv.

TestLoadEnvironmentToObject_Arr

References: os.Setenv.

TestLoadEnvironmentToObject_Map

References: os.Setenv.

TestSetConfigValue

References: reflect.ValueOf, strconv.Itoa.

TestValidate

TestValidateConfig