Esempio n. 1
0
func readBox(key string) (*secret.Box, error) {
	keyB, err := secret.KeyFromString(key)
	if err != nil {
		return nil, fmt.Errorf("failed to read encryption key: %s", err)
	}
	return secret.NewBox(keyB)
}
Esempio n. 2
0
func (s *Service) newBox() (*secret.Box, error) {
	if s.options.SealKey == "" {
		return nil, nil
	}
	key, err := secret.KeyFromString(s.options.SealKey)
	if err != nil {
		return nil, err
	}
	return secret.NewBox(key)
}
Esempio n. 3
0
func (s *EtcdSuite) SetUpTest(c *C) {
	// Initiate a backend with a registry

	key, err := secret.KeyFromString(s.key)
	c.Assert(err, IsNil)

	box, err := secret.NewBox(key)
	c.Assert(err, IsNil)

	engine, err := New(
		s.nodes,
		s.etcdPrefix,
		registry.GetRegistry(),
		Options{
			EtcdConsistency: s.consistency,
			Box:             box,
		})
	c.Assert(err, IsNil)
	s.ng = engine.(*ng)
	s.client = s.ng.client
	s.context = context.Background()

	// Delete all values under the given prefix
	_, err = s.client.Get(s.context, s.etcdPrefix)
	if err != nil {
		// There's no key like this
		if !notFound(err) {
			// We haven't expected this error, oops
			c.Assert(err, IsNil)
		}
	} else {
		_, err = s.ng.client.Delete(s.context, s.etcdPrefix, etcd.WithPrefix())
		c.Assert(err, IsNil)
	}

	s.changesC = make(chan interface{})
	s.stopC = make(chan bool)

	//find current index, so we only watch from now onwards
	response, err := s.ng.client.Get(s.ng.context, "/")
	c.Assert(response, NotNil)
	c.Assert(err, IsNil)

	go s.ng.Subscribe(s.changesC, uint64(response.Header.Revision+1), s.stopC)

	s.suite.ChangesC = s.changesC
	s.suite.Engine = engine
}
Esempio n. 4
0
func (s *VESuite) SetUpSuite(c *C) {
	log.InitWithConfig(log.Config{Name: "console"})

	etcdNodes := os.Getenv("VULCAND_TEST_ETCD_NODES")
	if etcdNodes == "" {
		c.Skip("This test requires running Etcd, please provide url via VULCAND_TEST_ETCD_NODES environment variable")
		return
	}
	s.etcdNodes = strings.Split(etcdNodes, ",")
	s.client = etcd.NewClient(s.etcdNodes)

	s.etcdPrefix = os.Getenv("VULCAND_TEST_ETCD_PREFIX")
	if s.etcdPrefix == "" {
		c.Skip("This test requires Etcd prefix, please provide url via VULCAND_TEST_ETCD_PREFIX environment variable")
		return
	}

	s.apiUrl = os.Getenv("VULCAND_TEST_API_URL")
	if s.apiUrl == "" {
		c.Skip("This test requires running vulcand daemon, provide API url via VULCAND_TEST_API_URL environment variable")
		return
	}

	s.serviceUrl = os.Getenv("VULCAND_TEST_SERVICE_URL")
	if s.serviceUrl == "" {
		c.Skip("This test requires running vulcand daemon, provide API url via VULCAND_TEST_SERVICE_URL environment variable")
		return
	}

	s.sealKey = os.Getenv("VULCAND_TEST_SEAL_KEY")
	if s.sealKey == "" {
		c.Skip("This test requires running vulcand daemon, provide API url via VULCAND_TEST_SEAL_KEY environment variable")
		return
	}

	key, err := secret.KeyFromString(s.sealKey)
	c.Assert(err, IsNil)

	box, err := secret.NewBox(key)
	c.Assert(err, IsNil)

	s.box = box
}
Esempio n. 5
0
func (s *EtcdSuite) SetUpTest(c *C) {
	// Initiate a backend with a registry

	key, err := secret.KeyFromString(s.key)
	c.Assert(err, IsNil)

	box, err := secret.NewBox(key)
	c.Assert(err, IsNil)

	engine, err := New(
		s.nodes,
		s.etcdPrefix,
		registry.GetRegistry(),
		Options{
			EtcdConsistency: s.consistency,
			Box:             box,
		})
	c.Assert(err, IsNil)
	s.ng = engine.(*ng)
	s.client = s.ng.client
	s.kapi = s.ng.kapi

	// Delete all values under the given prefix
	_, err = s.kapi.Get(s.context, s.etcdPrefix, &etcd.GetOptions{Recursive: false, Sort: false})
	if err != nil {
		// There's no key like this
		if !notFound(err) {
			// We haven't expected this error, oops
			c.Assert(err, IsNil)
		}
	} else {
		_, err = s.ng.kapi.Delete(s.context, s.etcdPrefix, &etcd.DeleteOptions{Recursive: true})
		c.Assert(err, IsNil)
	}

	s.changesC = make(chan interface{})
	s.stopC = make(chan bool)
	go s.ng.Subscribe(s.changesC, s.stopC)

	s.suite.ChangesC = s.changesC
	s.suite.Engine = engine
}