// SaveUserConfigToFile ...
171025
func SaveUserConfigToFile(projectConf UserConfigModel) error {
	bytes, err := yaml.Marshal(projectConf)
	if err != nil {
		return fmt.Errorf("Failed to parse Project Config (should be valid YML): %s", err)
	}

	err = fileutil.WriteBytesToFile(UserConfigFilePath, bytes)
	if err != nil {
		return fmt.Errorf("Failed to write Project Config into file (%s), error: %s", UserConfigFilePath, err)
	}

	return nil
}
809082
func LoadConfigFile(fileName string, moreFiles ...string) (c *ConfigFile, err error) {
	// Append files' name together.
	fileNames := make([]string, 1, len(moreFiles)+1)
	fileNames[0] = fileName
	if len(moreFiles) > 0 {
		fileNames = append(fileNames, moreFiles...)
	}

	c = newConfigFile(fileNames)

	for _, name := range fileNames {
		if err = c.loadFile(name); err != nil {
			return nil, err
		}
	}

	return c, nil
}
889899
func (c Config) Save(file string) error {
	var s = fileOutput(c.root)
	return ioutil.WriteFile(file, []byte(s), 0666)
}
69703
func (c *Config) configFromFile(path string) error {
	_, err := toml.DecodeFile(path, c)
	return errors.Trace(err)
}
139775
func (f *JSONConfigFile) GetUserConfigForUID(u keybase1.UID) (*UserConfig, error) {

	if uc := f.copyUserConfigIfForUID(u); uc != nil {
		return uc, nil
	}

	d := f.jw.AtKey("users")
	keys, _ := d.Keys()
	for _, key := range keys {
		uc, err := f.GetUserConfigForUsername(NewNormalizedUsername(key))
		if err == nil && uc != nil && uc.GetUID().Equal(u) {
			return uc, nil
		}
	}
	return nil, nil
}
654115
func ParseConfigFile(path string) (*Config, error) {
	path, err := filepath.Abs(path)
	if err != nil {
		return nil, err
	}

	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	config, err := ParseConfig(f)
	if err != nil {
		return nil, err
	}

	return config, nil
}
1245112
func (user *User) SaveSettings(allSettings interface{}) error {

	serviceID := user.ctx.getServiceID()

	_, err := user.ctx.db.C("users").UpsertId(user.ID, bson.M{"$set": bson.M{"settings." + serviceID: allSettings}, "$setOnInsert": bson.M{"createdat": time.Now()}})

	if user.data == nil {
		user.data = &userData{}
	}
	if user.data.Settings == nil {
		user.data.Settings = make(map[string]interface{})
	}
	user.data.Settings[serviceID] = allSettings

	return err
}
127401
func LoadDefaultConfigFile(stderr io.Writer) *configfile.ConfigFile {
	configFile, err := Load(Dir())
	if err != nil {
		fmt.Fprintf(stderr, "WARNING: Error loading config file: %v\n", err)
	}
	if !configFile.ContainsAuth() {
		configFile.CredentialsStore = credentials.DetectDefaultStore(configFile.CredentialsStore)
	}
	return configFile
}
71398
func WriteDefaultConfigFile(filePath string, useSQLite bool) error {
	conf := defaultBaseConfig
	blobDir, err := osutil.CamliBlobRoot()
	if err != nil {
		return err
	}
	varDir, err := osutil.CamliVarDir()
	if err != nil {
		return err
	}
	if err := wkfs.MkdirAll(blobDir, 0700); err != nil {
		return fmt.Errorf("Could not create default blobs directory: %v", err)
	}
	conf.BlobPath = blobDir
	conf.PackRelated = true

	if useSQLite {
		conf.SQLite = filepath.Join(varDir, "index.sqlite")
	} else {
		conf.LevelDB = filepath.Join(varDir, "index.leveldb")
	}

	keyID, secretRing, err := getOrMakeKeyring()
	if err != nil {
		return err
	}
	conf.Identity = keyID
	conf.IdentitySecretRing = secretRing

	confData, err := json.MarshalIndent(conf, "", "    ")
	if err != nil {
		return fmt.Errorf("Could not json encode config file : %v", err)
	}

	if err := wkfs.WriteFile(filePath, confData, 0600); err != nil {
		return fmt.Errorf("Could not create or write default server config: %v", err)
	}

	return nil
}
904534
func DefaultConfigFile(rootless bool) (string, error) {
	if rootless {
		home, err := homeDir()
		if err != nil {
			return "", errors.Wrapf(err, "cannot determine users homedir")
		}
		return filepath.Join(home, ".config/containers/storage.conf"), nil
	}
	return defaultConfigFile, nil
}
479827
func ReadConfigFile(filePath string) error {
	data, err := ioutil.ReadFile(filePath)
	if err != nil {
		return err
	}
	return ReadConfigBytes(data)
}
56204
func (c *Config) SaveProfile(profileAliasHost, profileDir string, profileOptions ...ProfileOptions) error {
	if c.WebProxyAddr == "" {
		return nil
	}

	// The profile is saved to a directory with the name of the proxy web endpoint.
	webProxyHost, _ := c.WebProxyHostPort()
	profileDir = FullProfilePath(profileDir)
	profilePath := path.Join(profileDir, webProxyHost) + ".yaml"

	profileAliasPath := ""
	if profileAliasHost != "" {
		profileAliasPath = path.Join(profileDir, profileAliasHost) + ".yaml"
	}

	var cp ClientProfile
	cp.Username = c.Username
	cp.WebProxyAddr = c.WebProxyAddr
	cp.SSHProxyAddr = c.SSHProxyAddr
	cp.KubeProxyAddr = c.KubeProxyAddr
	cp.ForwardedPorts = c.LocalForwardPorts.String()
	cp.SiteName = c.SiteName

	// create a profile file and set it current base on the option
	var opts ProfileOptions
	if len(profileOptions) == 0 {
		// default behavior is to override the profile
		opts = ProfileMakeCurrent
	} else {
		for _, flag := range profileOptions {
			opts |= flag
		}
	}
	if err := cp.SaveTo(ProfileLocation{
		AliasPath: profileAliasPath,
		Path:      profilePath,
		Options:   opts,
	}); err != nil {
		return trace.Wrap(err)
	}
	return nil
}
404968
func (configJSON ConfigJSON) ConfigFromFile(configPath string, config interface{}) {
	configBytes, err := ioutil.ReadFile(configPath)
	if err == nil {
		json.Unmarshal(configBytes, config)
	}
}
764425
func (g *Generator) SaveToFile(path string, exportOpts ExportOptions) error {
	f, err := os.Create(path)
	if err != nil {
		return err
	}
	defer f.Close()
	return g.Save(f, exportOpts)
}
224139
func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error {
	// Encode sensitive data into a new/temp struct
	tmpAuthConfigs := make(map[string]types.AuthConfig, len(configFile.AuthConfigs))
	for k, authConfig := range configFile.AuthConfigs {
		authCopy := authConfig
		// encode and save the authstring, while blanking out the original fields
		authCopy.Auth = encodeAuth(&authCopy)
		authCopy.Username = ""
		authCopy.Password = ""
		authCopy.ServerAddress = ""
		tmpAuthConfigs[k] = authCopy
	}

	saveAuthConfigs := configFile.AuthConfigs
	configFile.AuthConfigs = tmpAuthConfigs
	defer func() { configFile.AuthConfigs = saveAuthConfigs }()

	data, err := json.MarshalIndent(configFile, "", "\t")
	if err != nil {
		return err
	}
	_, err = writer.Write(data)
	return err
}
654355
func InstallDefaultUserConfig() error {
	err := os.MkdirAll(path.Dir(GetUserConfigFilePath()), 0755)
	if err != nil {
		return err
	}

	return ioutil.WriteFile(GetUserConfigFilePath(), []byte(DefaultConfigFileContent), 0644)
}
784988
func (a *API) SetUserConfig(user int, key string, value string) (string, error) {
	url := a.BuildURL("/v2/user/%d/config/%s/", user, key)
	return a.putTextPlain(url, Params{}, value)
}