Пример #1
0
func TestGenerateKey(t *testing.T) {
	testStartKeys(t)
	defer testKillService(t, "keys", true)

	address := testsGenAKey()

	lsOut := new(bytes.Buffer)
	config.GlobalConfig.Writer = lsOut
	do := def.NowDo()
	do.Name = "keys"
	do.Operations.Interactive = false
	do.Operations.ContainerNumber = 1
	path := path.Join(ErisContainerRoot, "keys", "data")

	do.Operations.Args = []string{"ls", path}
	if err := srv.ExecService(do); err != nil {
		fatal(t, err)
	}

	lsOutBytes := lsOut.Bytes()

	output := trimString(string(lsOutBytes))

	if address != output {
		fatal(t, fmt.Errorf("Expected (%s), got (%s)\n", address, output))
	}
}
Пример #2
0
func ImportKey(do *definitions.Do) error {

	do.Name = "keys"
	do.Operations.ContainerNumber = 1
	if err := srv.EnsureRunning(do); err != nil {
		return err
	}

	do.Operations.Interactive = false
	dir := path.Join(ErisContainerRoot, "keys", "data", do.Address)
	do.Operations.Args = []string{"mkdir", dir} //need to mkdir for import
	if err := srv.ExecService(do); err != nil {
		return err
	}
	//src on host

	if do.Source == "" {
		do.Source = filepath.Join(KeysPath, "data", do.Address, do.Address)
	}
	//dest in container
	do.Destination = dir

	if err := data.ImportData(do); err != nil {
		return err
	}
	return nil
}
Пример #3
0
func ExecService(cmd *cobra.Command, args []string) {
	IfExit(ArgCheck(1, "ge", cmd, args))

	do.Name = args[0]
	args = args[1:]
	if len(args) == 1 {
		args = strings.Split(args[0], " ")
	}
	do.Args = args

	IfExit(srv.ExecService(do))
}
Пример #4
0
func ConvertKey(do *definitions.Do) error {

	do.Name = "keys"
	if err := srv.EnsureRunning(do); err != nil {
		return err
	}

	do.Operations.Args = []string{"mintkey", "mint", do.Address}
	if err := srv.ExecService(do); err != nil {
		return err
	}
	return nil
}
Пример #5
0
func GenerateKey(do *definitions.Do) error {
	do.Name = "keys"
	do.Operations.ContainerNumber = 1

	if err := srv.EnsureRunning(do); err != nil {
		return err
	}
	do.Operations.Interactive = false
	do.Operations.Args = []string{"eris-keys", "gen", "--no-pass"}

	if err := srv.ExecService(do); err != nil {
		return err
	}
	return nil
}
Пример #6
0
func GetPubKey(do *definitions.Do) error {

	do.Name = "keys"
	do.Operations.ContainerNumber = 1
	if err := srv.EnsureRunning(do); err != nil {
		return err
	}

	do.Operations.Interactive = false
	do.Operations.Args = []string{"eris-keys", "pub", "--addr", do.Address}

	if err := srv.ExecService(do); err != nil {
		return err
	}
	return nil
}
Пример #7
0
func ExecService(cmd *cobra.Command, args []string) {
	IfExit(ArgCheck(1, "ge", cmd, args))

	do.Name = args[0]
	// if interactive, we ignore args. if not, run args as command
	args = args[1:]
	if !do.Operations.Interactive {
		if len(args) == 0 {
			Exit(fmt.Errorf("Non-interactive exec sessions must provide arguments to execute"))
		}
	}
	if len(args) == 1 {
		args = strings.Split(args[0], " ")
	}
	do.Operations.Args = args
	IfExit(srv.ExecService(do))
}
Пример #8
0
func ListKeys(do *definitions.Do) error {
	if do.Host {
		keysPath := filepath.Join(KeysPath, "data")
		addrs, err := ioutil.ReadDir(keysPath)
		if err != nil {
			return err
		}
		hostAddrs := make([]string, len(addrs))
		for i, addr := range addrs {
			hostAddrs[i] = addr.Name()
		}
		do.Result = strings.Join(hostAddrs, ",")
		log.WithField("=>", hostAddrs[0]).Warn("The keys on your host kind marmot:")
		hostAddrs = append(hostAddrs[:0], hostAddrs[1:]...)
		for _, addr := range hostAddrs {
			log.WithField("=>", addr).Warn()
		}
	}

	if do.Container {
		keysOut := new(bytes.Buffer)
		config.GlobalConfig.Writer = keysOut
		do.Name = "keys"
		do.Operations.ContainerNumber = 1
		if err := srv.EnsureRunning(do); err != nil {
			return err
		}

		do.Operations.Interactive = false
		do.Operations.Args = []string{"ls", "/home/eris/.eris/keys/data"}

		if err := srv.ExecService(do); err != nil {
			return err
		}
		keysOutString := strings.Split(util.TrimString(string(keysOut.Bytes())), "\n")
		do.Result = strings.Join(keysOutString, ",")
		log.WithField("=>", keysOutString[0]).Warn("The keys in your container kind marmot:")
		keysOutString = append(keysOutString[:0], keysOutString[1:]...)
		for _, addr := range keysOutString {
			log.WithField("=>", addr).Warn()
		}

	}
	return nil
}
Пример #9
0
func TestExportKeySingle(t *testing.T) {
	testStartKeys(t)
	defer testKillService(t, "keys", true) //or some clean function

	address := testsGenAKey()

	catOut := new(bytes.Buffer)
	config.GlobalConfig.Writer = catOut
	do := def.NowDo()
	do.Name = "keys"
	do.Operations.Interactive = false
	do.Operations.ContainerNumber = 1
	keyPath := path.Join(ErisContainerRoot, "keys", "data", address, address)

	//cat container contents of new key
	do.Operations.Args = []string{"cat", keyPath}
	if err := srv.ExecService(do); err != nil {
		fatal(t, err)
	}

	catOutBytes := catOut.Bytes()
	keyInCont := trimString(string(catOutBytes))

	doExp := def.NowDo()
	doExp.Address = address
	doExp.Destination = path.Join(KeysPath, "data") //is default

	//export
	if err := ExportKey(doExp); err != nil {
		fatal(t, err)
	}

	//cat host contents
	key, err := ioutil.ReadFile(path.Join(doExp.Destination, address, address))
	if err != nil {
		fatal(t, err)
	}

	keyOnHost := trimString(string(key))
	if keyInCont != keyOnHost {
		fatal(t, fmt.Errorf("Expected (%s), got (%s)\n", keyInCont, keyOnHost))
	}
}
Пример #10
0
func TestImportKeySingle(t *testing.T) {
	testStartKeys(t)
	defer testKillService(t, "keys", true) //or some clean function

	address := testsGenAKey()

	//export it
	doExp := def.NowDo()
	doExp.Address = address
	doExp.Destination = path.Join(KeysPath, "data") //is default

	if err := ExportKey(doExp); err != nil {
		fatal(t, err)
	}

	key, err := ioutil.ReadFile(path.Join(doExp.Destination, address, address))
	if err != nil {
		fatal(t, err)
	}
	//key b4 import
	keyOnHost := trimString(string(key))

	//rm key that was generated before import
	doRm := def.NowDo()
	doRm.Name = "keys"
	doRm.Operations.Interactive = false
	doRm.Operations.ContainerNumber = 1
	keyPath := path.Join(ErisContainerRoot, "keys", "data", address)

	doRm.Operations.Args = []string{"rm", "-rf", keyPath}
	if err := srv.ExecService(doRm); err != nil {
		fatal(t, err)
	}

	doImp := def.NowDo()
	doImp.Address = address
	//doImp.Destination // set in function

	if err := ImportKey(doImp); err != nil {
		fatal(t, err)
	}

	catOut := new(bytes.Buffer)
	config.GlobalConfig.Writer = catOut
	doCat := def.NowDo()
	doCat.Name = "keys"
	doCat.Operations.Interactive = false
	doCat.Operations.ContainerNumber = 1
	keyPathCat := path.Join(ErisContainerRoot, "keys", "data", address, address)

	//cat container contents of new key
	doCat.Operations.Args = []string{"cat", keyPathCat}
	if err := srv.ExecService(doCat); err != nil {
		fatal(t, err)
	}

	catOutBytes := catOut.Bytes()
	keyInCont := trimString(string(catOutBytes))

	if keyOnHost != keyInCont {
		fatal(t, fmt.Errorf("Expected (%s), got (%s)\n", keyOnHost, keyInCont))
	}
}