From e2df7758a1d5dfec395dc33f20df622afb732500 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Sun, 23 Jul 2023 16:18:02 +0200 Subject: [PATCH] refactor(be): config struct --- lib/GitClientFactory.go | 6 ++++-- util/config.go | 44 ++++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/GitClientFactory.go b/lib/GitClientFactory.go index 0042a2d73..c7c986449 100644 --- a/lib/GitClientFactory.go +++ b/lib/GitClientFactory.go @@ -3,9 +3,11 @@ package lib import "github.com/ansible-semaphore/semaphore/util" func CreateDefaultGitClient() GitClient { - switch util.Config.GitClient { - case "go_git": + switch util.Config.GitClientId { + case util.GoGitClientId: return CreateGoGitClient() + case util.CmdGitClientId: + return CreateCmdGitClient() default: return CreateCmdGitClient() } diff --git a/util/config.go b/util/config.go index e30321646..03464832c 100644 --- a/util/config.go +++ b/util/config.go @@ -71,6 +71,17 @@ type oidcProvider struct { EmailClaim string `json:"email_claim"` } +type GitClientId string + +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 GitClientId = "go_git" + // CmdGitClientId is external Git client. + // Default Git client. It is use external Git binary to clone repositories. + CmdGitClientId GitClientId = "cmd_git" +) + // ConfigType mapping between Config and the json file that sets it type ConfigType struct { MySQL DbConfig `json:"mysql"` @@ -90,6 +101,10 @@ type ConfigType struct { // semaphore stores ephemeral projects here TmpPath string `json:"tmp_path"` + // SshConfigPath is a path to the custom SSH config file. + // Default path is ~/.ssh/config. + SshConfigPath string `json:"ssh_config_path"` + // cookie hashing & encryption CookieHash string `json:"cookie_hash"` CookieEncryption string `json:"cookie_encryption"` @@ -122,29 +137,22 @@ type ConfigType struct { // telegram alerting TelegramChat string `json:"telegram_chat"` TelegramToken string `json:"telegram_token"` - - // slack alerting - SlackUrl string `json:"slack_url"` + SlackUrl string `json:"slack_url"` // task concurrency MaxParallelTasks int `json:"max_parallel_tasks"` - // configType field ordering with bools at end reduces struct size - // (maligned check) - // feature switches - EmailAlert bool `json:"email_alert"` - EmailSecure bool `json:"email_secure"` - TelegramAlert bool `json:"telegram_alert"` - SlackAlert bool `json:"slack_alert"` - LdapEnable bool `json:"ldap_enable"` - LdapNeedTLS bool `json:"ldap_needtls"` - - SshConfigPath string `json:"ssh_config_path"` - - DemoMode bool `json:"demo_mode"` - - GitClient string `json:"git_client"` + EmailAlert bool `json:"email_alert"` + EmailSecure bool `json:"email_secure"` + TelegramAlert bool `json:"telegram_alert"` + SlackAlert bool `json:"slack_alert"` + LdapEnable bool `json:"ldap_enable"` + LdapNeedTLS bool `json:"ldap_needtls"` + PasswordLoginDisabled bool `json:"password_login_disable"` + DemoMode bool `json:"demo_mode"` + + GitClientId GitClientId `json:"git_client"` } // Config exposes the application configuration storage for use in the application