Example #1
0
func realMain() int {

	cPath, err := vault.ConfigFile()

	if err != nil {
		panic(err)
	}

	file, err := os.Open(cPath)
	var config vault.Config
	err = vault.DecodeConfig(file, &config)

	if err != nil {
		panic(err)
	}
	file.Close()

	sConf, e := server.GetServerConfig(&config)
	if e != nil {
		panic(e)
	}
	client, err := server.NewVaultClient(&server.ClientConfig{
		ServerConfig: sConf,
	})

	if err == nil {
		err = client.Ping()
	}

	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not connect to vault\n%v\n", err)
		return 1
	}

	app := cli.NewApp()
	app.Name = "vault"

	app.Version = "0.0.1"

	app.Commands = initCommands(client)

	err = app.Run(os.Args)

	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return 1
	}

	return 0
}
Example #2
0
func loadConfig() (*vault.Config, error) {

	cPath, e := vault.ConfigFile()

	if e != nil {
		return nil, e
	}

	//cPath := filepath.Join(home, "vault.toml")

	file, err := os.Open(cPath)

	if err != nil {
		if !os.IsNotExist(err) {
			return nil, err
		}

		conf := vault.DefaultConfig()

		b, e := vault.EncodeConfig(conf)

		if e != nil {
			return nil, e
		}

		ioutil.WriteFile(cPath, b, 0755)

		return conf, nil
	} else {

	}

	defer file.Close()

	var config vault.Config
	err = vault.DecodeConfig(file, &config)

	return &config, err
}