Пример #1
0
// setDirs sets the Dirs for the template resource.
// All keys are grouped based on their directory path names.
// For example, /upstream/app1 and upstream/app2 will be grouped as
//    {
//        "upstream": []Node{
//            {"app1": value}},
//            {"app2": value}},
//         }
//    }
//
// Dirs are exposed to resource templated to enable iteration.
func (t *TemplateResource) setDirs(vars map[string]interface{}) {
	d := node.NewDirectory()
	for k, v := range vars {
		directory := filepath.Dir(filepath.Join("/", strings.TrimPrefix(k, config.Prefix())))
		d.Add(pathToKey(directory, config.Prefix()), node.Node{filepath.Base(k), v})
	}
	t.Dirs = d
}
Пример #2
0
// setVars sets the Vars for template resource.
func (t *TemplateResource) setVars() error {
	var err error
	log.Debug("Retrieving keys from etcd")
	log.Debug("Key prefix set to " + config.Prefix())
	t.Vars, err = etcdutil.GetValues(t.etcdClient, config.Prefix(), t.Keys)
	if err != nil {
		return err
	}
	return nil
}
Пример #3
0
// setVars sets the Vars for template resource.
func (t *TemplateResource) setVars() error {
	var err error
	log.Debug("Retrieving keys from store")
	log.Debug("Key prefix set to " + config.Prefix())
	vars, err := t.storeClient.GetValues(appendPrefix(config.Prefix(), t.Keys))
	if err != nil {
		return err
	}
	t.Vars = cleanKeys(vars)
	return nil
}
Пример #4
0
// cleanKeys is used to transform the path based keys we
// get from the StoreClient to a more friendly format.
func cleanKeys(vars map[string]interface{}) map[string]interface{} {
	clean := make(map[string]interface{}, len(vars))
	prefix := config.Prefix()
	for key, val := range vars {
		clean[pathToKey(key, prefix)] = val
	}
	return clean
}
Пример #5
0
func (t *TemplateResource) prefix() string {
	return path.Join(config.Prefix(), t.Prefix)
}