コード例 #1
0
ファイル: core.go プロジェクト: bottkars/rexray
func init() {
	initDrivers()
	gofig.SetGlobalConfigPath(util.EtcDirPath())
	gofig.SetUserConfigPath(fmt.Sprintf("%s/.rexray", gotil.HomeDir()))
	gofig.Register(globalRegistration())
	gofig.Register(driverRegistration())
}
コード例 #2
0
ファイル: config.go プロジェクト: emccode/libstorage
// NewConfig returns a new configuration instance.
func NewConfig() (gofig.Config, error) {
	config := registry.NewConfig()

	etcYML := types.Etc.Join("config.yml")
	etcYAML := types.Etc.Join("config.yaml")

	userHomeDir := gotil.HomeDir()
	usrYML := path.Join(userHomeDir, "config.yml")
	usrYAML := path.Join(userHomeDir, "config.yaml")

	if err := readConfigFile(config, etcYML); err != nil {
		return nil, err
	}
	if err := readConfigFile(config, etcYAML); err != nil {
		return nil, err
	}
	if err := readConfigFile(config, usrYML); err != nil {
		return nil, err
	}
	if err := readConfigFile(config, usrYAML); err != nil {
		return nil, err
	}

	types.BackCompat(config)

	return config, nil
}
コード例 #3
0
ファイル: types_paths.go プロジェクト: emccode/libstorage
func initPaths() {

	thisExeDir, thisExeName, thisExeAbsPath = gotil.GetThisPathParts()

	if libstorageHome == "" {
		libstorageHome = "/"
	}

	// if not root and home is /, change home to user's home dir
	if os.Geteuid() != 0 && libstorageHome == "/" {
		libstorageHome = path.Join(gotil.HomeDir(), ".libstorage")
	}

	for i := Home; i < maxFileKey; i++ {
		if i.isFileKeyMarker() {
			continue
		}

		// this initialized the value
		_ = i.String()

		if Debug {
			log.WithField(i.key(), i.String()).Info("libStorage path")
		}
	}
}
コード例 #4
0
ファイル: usage.go プロジェクト: codenrhoden/rexray
func (c *CLI) initUsageTemplates() {

	var ut string
	utPath := fmt.Sprintf("%s/.rexray/usage.template", gotil.HomeDir())
	log.WithField("path", utPath).Debug("usage template path")

	if gotil.FileExists(utPath) {
		dat, err := ioutil.ReadFile(utPath)
		if err != nil {
			panic(err)
		}
		log.WithField("source", utPath).Debug("loaded usage template")
		ut = string(dat)
	} else {
		log.WithField("source", "UsageTemplate").Debug("loaded usage template")
		ut = usageTemplate
	}

	c.c.SetUsageTemplate(ut)
	c.c.SetHelpTemplate(ut)

	cobra.AddTemplateFuncs(template.FuncMap{
		"af":    c.additionalFlags,
		"afs":   c.additionalFlagSets,
		"hf":    hasFlags,
		"lf":    c.localFlags,
		"gf":    c.globalFlags,
		"df":    c.driverFlags,
		"ihf":   isHelpFlag,
		"ivf":   isVerboseFlag,
		"saf":   c.sansAdditionalFlags,
		"cmds":  commands,
		"rtrim": rtrim,
	})
}
コード例 #5
0
ファイル: types_paths.go プロジェクト: emccode/libstorage
func (k fileKey) init() {

	if k == Home {
		if !checkPerms(k, false) {
			failedPath := k.get()
			libstorageHome = path.Join(gotil.HomeDir(), ".libstorage")
			log.WithFields(log.Fields{
				"failedPath": failedPath,
				"newPath":    k.get(),
			}).Debug("first make homedir failed, trying again")
			checkPerms(k, true)
		}
		return
	}

	checkPerms(k, true)
}
コード例 #6
0
ファイル: rexray.go プロジェクト: akutz/rexray
func init() {
	gofigCore.SetGlobalConfigPath(util.EtcDirPath())
	gofigCore.SetUserConfigPath(path.Join(gotil.HomeDir(), util.DotDirName))
	r := gofigCore.NewRegistration("Global")
	r.SetYAML(`
rexray:
    logLevel: warn
`)
	r.Key(gofig.String, "h", "",
		"The libStorage host.", "rexray.host",
		"host")
	r.Key(gofig.String, "s", "",
		"The libStorage service.", "rexray.service",
		"service")
	r.Key(gofig.String, "l", "warn",
		"The log level (error, warn, info, debug)", "rexray.logLevel",
		"logLevel")
	gofigCore.Register(r)
}
コード例 #7
0
ファイル: util.go プロジェクト: akutz/rexray
// NewConfig returns a new config object.
func NewConfig(ctx apitypes.Context) gofig.Config {
	const cfgFileExt = "yml"

	loadConfig := func(
		allExists, usrExists, ignoreExists bool,
		allPath, usrPath, name string) (gofig.Config, bool) {
		fields := log.Fields{
			"buildType":              core.BuildType,
			"ignoreExists":           ignoreExists,
			"configFileName":         name,
			"globalConfigFilePath":   allPath,
			"userConfigFilePath":     usrPath,
			"globalConfigFileExists": allExists,
			"userConfigFileExists":   usrExists,
		}
		ctx.WithFields(fields).Debug("loading config")
		if ignoreExists {
			ctx.WithFields(fields).Debug("disabled config file exist check")
		} else if !allExists && !usrExists {
			ctx.WithFields(fields).Debug("cannot find global or user file")
			return nil, false
		}
		if allExists {
			ctx.WithFields(fields).Debug("validating global config")
			ValidateConfig(allPath)
		}
		if usrExists {
			ctx.WithFields(fields).Debug("validating user config")
			ValidateConfig(usrPath)
		}
		ctx.WithFields(fields).Debug("created new config")
		return gofigCore.NewConfig(
			allExists || ignoreExists,
			usrExists || ignoreExists,
			name, cfgFileExt), true
	}

	// load build-type specific config
	switch core.BuildType {
	case "client", "agent", "controller":
		var (
			fileName    = BinFileName
			fileNameExt = fileName + "." + cfgFileExt
			allFilePath = EtcFilePath(fileNameExt)
			usrFilePath = path.Join(gotil.HomeDir(), DotDirName, fileNameExt)
		)
		if config, ok := loadConfig(
			gotil.FileExists(allFilePath),
			gotil.FileExists(usrFilePath),
			false,
			allFilePath, usrFilePath,
			fileName); ok {
			return config
		}
	}

	// load config from rexray.yml?
	{
		var (
			fileName    = "rexray"
			fileNameExt = fileName + "." + cfgFileExt
			allFilePath = EtcFilePath(fileNameExt)
			usrFilePath = path.Join(gotil.HomeDir(), DotDirName, fileNameExt)
		)
		if config, ok := loadConfig(
			gotil.FileExists(allFilePath),
			gotil.FileExists(usrFilePath),
			false,
			allFilePath, usrFilePath,
			fileName); ok {
			return config
		}
	}

	// load default config
	{
		var (
			fileName    = "config"
			fileNameExt = fileName + "." + cfgFileExt
			allFilePath = EtcFilePath(fileNameExt)
			usrFilePath = path.Join(gotil.HomeDir(), DotDirName, fileNameExt)
		)
		config, _ := loadConfig(
			gotil.FileExists(allFilePath),
			gotil.FileExists(usrFilePath),
			true,
			allFilePath, usrFilePath,
			fileName)
		return config
	}
}