github.com/wtfutil/wtf@v0.43.0/modules/gerrit/settings.go (about)

     1  package gerrit
     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     = "Gerrit"
    13  )
    14  
    15  type colors struct {
    16  	rows struct {
    17  		even string `help:"Define the foreground color for even-numbered rows." values:"Any X11 color name." optional:"true"`
    18  		odd  string `help:"Define the foreground color for odd-numbered rows." values:"Any X11 color name." optional:"true"`
    19  	}
    20  }
    21  
    22  type Settings struct {
    23  	colors
    24  	*cfg.Common
    25  
    26  	domain                  string        `help:"Your Gerrit corporate domain."`
    27  	password                string        `help:"Your Gerrit HTTP Password."`
    28  	projects                []interface{} `help:"A list of Gerrit project names to fetch data for."`
    29  	username                string        `help:"Your Gerrit username."`
    30  	verifyServerCertificate bool          `help:"Determines whether or not the server’s certificate chain and host name are verified." values:"true or false" optional:"true"`
    31  }
    32  
    33  func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
    34  	settings := Settings{
    35  		Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
    36  
    37  		domain:                  ymlConfig.UString("domain", ""),
    38  		password:                ymlConfig.UString("password", os.Getenv("WTF_GERRIT_PASSWORD")),
    39  		projects:                ymlConfig.UList("projects"),
    40  		username:                ymlConfig.UString("username", ""),
    41  		verifyServerCertificate: ymlConfig.UBool("verifyServerCertificate", true),
    42  	}
    43  
    44  	cfg.ModuleSecret(name, globalConfig, &settings.password).
    45  		Service(settings.domain).Load()
    46  
    47  	settings.colors.rows.even = ymlConfig.UString("colors.rows.even", "white")
    48  	settings.colors.rows.odd = ymlConfig.UString("colors.rows.odd", "blue")
    49  
    50  	return &settings
    51  }