Example #1
0
File: config.go Project: pirater/os
func (c *CloudConfig) Save() error {
	files := append([]string{OsConfigFile, OemConfigFile}, CloudConfigDirFiles()...)
	files = util.FilterStrings(files, func(x string) bool { return x != CloudConfigPrivateFile })
	exCfg, err := ChainCfgFuncs(nil,
		func(_ *CloudConfig) (*CloudConfig, error) {
			return ReadConfig(nil, true, files...)
		},
		readCmdline,
		amendNils)
	if err != nil {
		return err
	}
	exData := map[interface{}]interface{}{}
	if err := util.Convert(exCfg, &exData); err != nil {
		return err
	}

	data := map[interface{}]interface{}{}
	if err := util.Convert(c, &data); err != nil {
		return err
	}

	data = util.MapsDifference(data, exData)
	log.WithFields(log.Fields{"diff": data}).Debug("The diff we're about to save")
	if err := saveToDisk(data); err != nil {
		return err
	}
	return nil
}
Example #2
0
File: config.go Project: pirater/os
func (c *CloudConfig) Merge(values map[interface{}]interface{}) (*CloudConfig, error) {
	d := map[interface{}]interface{}{}
	if err := util.Convert(c, &d); err != nil {
		return c, err
	}
	r := util.MapsUnion(d, StringifyValues(values))
	t := &CloudConfig{}
	if err := util.Convert(r, t); err != nil {
		return c, err
	}
	return t, nil
}
Example #3
0
File: config.go Project: Jdesk/os
func (c *CloudConfig) Merge(values map[interface{}]interface{}) (*CloudConfig, error) {
	t := *c
	if err := util.Convert(values, &t); err != nil {
		return c, err
	}
	return &t, nil
}
Example #4
0
func TestUserDocker(t *testing.T) {
	assert := require.New(t)

	config := &CloudConfig{
		Rancher: RancherConfig{
			Docker: DockerConfig{
				TLS: true,
			},
		},
	}

	bytes, err := yaml.Marshal(config)
	assert.Nil(err)

	config = NewConfig()
	err = yaml.Unmarshal(bytes, config)
	assert.Nil(err)

	data := map[interface{}]map[interface{}]interface{}{}
	util.Convert(config, &data)

	fmt.Println(data)

	val, ok := data["rancher"]["docker"]
	assert.True(ok)

	m, ok := val.(map[interface{}]interface{})
	assert.True(ok)
	v, ok := m["tls"]
	assert.True(ok)
	assert.True(v.(bool))

}
Example #5
0
File: config.go Project: pirater/os
func (c *CloudConfig) Get(key string) (interface{}, error) {
	data := map[interface{}]interface{}{}
	if err := util.Convert(c, &data); err != nil {
		return nil, err
	}

	v, _ := getOrSetVal(key, data, nil)
	return v, nil
}
Example #6
0
File: config.go Project: pirater/os
func (c *CloudConfig) Set(key string, value interface{}) (*CloudConfig, error) {
	data := map[interface{}]interface{}{}
	if err := util.Convert(c, &data); err != nil {
		return c, err
	}

	_, data = getOrSetVal(key, data, value)

	return c.Merge(data)
}
Example #7
0
File: disk.go Project: pirater/os
func ReadConfig(bytes []byte, substituteMetadataVars bool, files ...string) (*CloudConfig, error) {
	if data, err := readConfig(bytes, substituteMetadataVars, files...); err == nil {
		c := &CloudConfig{}
		if err := util.Convert(data, c); err != nil {
			return nil, err
		}
		c, _ = amendNils(c)
		c, _ = amendContainerNames(c)
		return c, nil
	} else {
		return nil, err
	}
}
Example #8
0
File: config.go Project: Jdesk/os
func (c *CloudConfig) Import(bytes []byte) (*CloudConfig, error) {
	data, err := readConfig(bytes, false, CloudConfigPrivateFile)
	if err != nil {
		return c, err
	}

	cfg := NewConfig()
	if err := util.Convert(data, cfg); err != nil {
		return c, err
	}

	return cfg, nil
}