Remove some options and add docs
* Remove the unused CondifGir option * Add docs for the default section * Move some docs from other files Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
73096dd5e6
commit
f5978f82d3
15 changed files with 185 additions and 159 deletions
|
|
@ -47,9 +47,6 @@ func NewConfig(cfgFile string) (*Config, error) {
|
|||
if _, err := toml.DecodeFile(cfgFile, &config); err != nil {
|
||||
return nil, errors.Wrap(err, "decoding toml")
|
||||
}
|
||||
if config.Default.ConfigDir == "" {
|
||||
config.Default.ConfigDir = appdefaults.DefaultConfigDir
|
||||
}
|
||||
if err := config.Validate(); err != nil {
|
||||
return nil, errors.Wrap(err, "validating config")
|
||||
}
|
||||
|
|
@ -108,10 +105,6 @@ func (c *Config) Validate() error {
|
|||
}
|
||||
|
||||
type Default struct {
|
||||
// ConfigDir is the folder where the runner may save any aditional files
|
||||
// or configurations it may need. Things like auto-generated SSH keys that
|
||||
// may be used to access the runner instances.
|
||||
ConfigDir string `toml:"config_dir,omitempty" json:"config-dir,omitempty"`
|
||||
// CallbackURL is the URL where the instances can send back status reports.
|
||||
CallbackURL string `toml:"callback_url" json:"callback-url"`
|
||||
// MetadataURL is the URL where instances can fetch information they may need
|
||||
|
|
@ -139,14 +132,6 @@ func (d *Default) Validate() error {
|
|||
return errors.Wrap(err, "validating metadata_url")
|
||||
}
|
||||
|
||||
if d.ConfigDir == "" {
|
||||
return fmt.Errorf("config_dir cannot be empty")
|
||||
}
|
||||
|
||||
if _, err := os.Stat(d.ConfigDir); err != nil {
|
||||
return errors.Wrap(err, "accessing config dir")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ var (
|
|||
|
||||
func getDefaultSectionConfig(configDir string) Default {
|
||||
return Default{
|
||||
ConfigDir: configDir,
|
||||
CallbackURL: "https://garm.example.com/",
|
||||
MetadataURL: "https://garm.example.com/api/v1/metadata",
|
||||
LogFile: filepath.Join(configDir, "garm.log"),
|
||||
|
|
@ -152,7 +151,6 @@ func TestDefaultSectionConfig(t *testing.T) {
|
|||
cfg: Default{
|
||||
CallbackURL: "",
|
||||
MetadataURL: cfg.MetadataURL,
|
||||
ConfigDir: cfg.ConfigDir,
|
||||
},
|
||||
errString: "missing callback_url",
|
||||
},
|
||||
|
|
@ -161,25 +159,14 @@ func TestDefaultSectionConfig(t *testing.T) {
|
|||
cfg: Default{
|
||||
CallbackURL: cfg.CallbackURL,
|
||||
MetadataURL: "",
|
||||
ConfigDir: cfg.ConfigDir,
|
||||
},
|
||||
errString: "missing metadata-url",
|
||||
},
|
||||
{
|
||||
name: "ConfigDir cannot be empty",
|
||||
cfg: Default{
|
||||
CallbackURL: cfg.CallbackURL,
|
||||
MetadataURL: cfg.MetadataURL,
|
||||
ConfigDir: "",
|
||||
},
|
||||
errString: "config_dir cannot be empty",
|
||||
},
|
||||
{
|
||||
name: "config_dir must exist and be accessible",
|
||||
cfg: Default{
|
||||
CallbackURL: cfg.CallbackURL,
|
||||
MetadataURL: cfg.MetadataURL,
|
||||
ConfigDir: "/i/do/not/exist",
|
||||
},
|
||||
errString: "accessing config dir: stat /i/do/not/exist:.*",
|
||||
},
|
||||
|
|
@ -560,7 +547,6 @@ func TestNewConfig(t *testing.T) {
|
|||
require.Nil(t, err)
|
||||
require.NotNil(t, cfg)
|
||||
require.Equal(t, "https://garm.example.com/", cfg.Default.CallbackURL)
|
||||
require.Equal(t, "./testdata", cfg.Default.ConfigDir)
|
||||
require.Equal(t, "0.0.0.0", cfg.APIServer.Bind)
|
||||
require.Equal(t, 9998, cfg.APIServer.Port)
|
||||
require.Equal(t, false, cfg.APIServer.UseTLS)
|
||||
|
|
@ -574,31 +560,6 @@ func TestNewConfig(t *testing.T) {
|
|||
require.Equal(t, timeToLive("48h"), cfg.JWTAuth.TimeToLive)
|
||||
}
|
||||
|
||||
func TestNewConfigEmptyConfigDir(t *testing.T) {
|
||||
dirPath, err := os.MkdirTemp("", "garm-config-test")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temporary directory: %s", err)
|
||||
}
|
||||
defer os.RemoveAll(dirPath)
|
||||
appdefaults.DefaultConfigDir = dirPath
|
||||
|
||||
cfg, err := NewConfig("testdata/test-empty-config-dir.toml")
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, cfg)
|
||||
require.Equal(t, cfg.Default.ConfigDir, dirPath)
|
||||
require.Equal(t, "https://garm.example.com/", cfg.Default.CallbackURL)
|
||||
require.Equal(t, "0.0.0.0", cfg.APIServer.Bind)
|
||||
require.Equal(t, 9998, cfg.APIServer.Port)
|
||||
require.Equal(t, false, cfg.APIServer.UseTLS)
|
||||
require.Equal(t, DBBackendType("mysql"), cfg.Database.DbBackend)
|
||||
require.Equal(t, "test", cfg.Database.MySQL.Username)
|
||||
require.Equal(t, "test", cfg.Database.MySQL.Password)
|
||||
require.Equal(t, "127.0.0.1", cfg.Database.MySQL.Hostname)
|
||||
require.Equal(t, "garm", cfg.Database.MySQL.DatabaseName)
|
||||
require.Equal(t, "bocyasicgatEtenOubwonIbsudNutDom", cfg.JWTAuth.Secret)
|
||||
require.Equal(t, timeToLive("48h"), cfg.JWTAuth.TimeToLive)
|
||||
}
|
||||
|
||||
func TestNewConfigInvalidTomlPath(t *testing.T) {
|
||||
cfg, err := NewConfig("this is not a file path")
|
||||
require.Nil(t, cfg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue