github.com/wtfutil/wtf@v0.43.0/modules/gitlab/settings.go (about) 1 package gitlab 2 3 import ( 4 "os" 5 6 "github.com/olebedev/config" 7 "github.com/wtfutil/wtf/cfg" 8 ) 9 10 const ( 11 defaultFocusable = true 12 defaultTitle = "GitLab" 13 ) 14 15 // Settings defines the configuration properties for this module 16 type Settings struct { 17 *cfg.Common 18 19 apiKey string `help:"A GitLab personal access token. Requires at least api access."` 20 domain string `help:"Your GitLab corporate domain."` 21 projects []string `help:"A list of key/value pairs each describing a GitLab project to fetch data for." values:"Key: The name of the project. Value: The namespace of the project."` 22 username string `help:"Your GitLab username. Used to figure out which requests require your approval"` 23 } 24 25 // NewSettingsFromYAML creates a new settings instance from a YAML config block 26 func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { 27 settings := Settings{ 28 Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), 29 30 apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_GITLAB_TOKEN"))), 31 domain: ymlConfig.UString("domain", "https://gitlab.com"), 32 username: ymlConfig.UString("username"), 33 } 34 35 cfg.ModuleSecret(name, globalConfig, &settings.apiKey). 36 Service(settings.domain).Load() 37 38 settings.projects = cfg.ParseAsMapOrList(ymlConfig, "projects") 39 40 return &settings 41 }