Skip to content

Commit

Permalink
Add API for setting file permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris authored and spf13 committed Apr 4, 2019
1 parent 9e56dac commit fccfc2c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ type Viper struct {
remoteProviders []*defaultRemoteProvider

// Name of file to look for inside the path
configName string
configFile string
configType string
envPrefix string
configName string
configFile string
configType string
configPermissions os.FileMode
envPrefix string

automaticEnvApplied bool
envKeyReplacer *strings.Replacer
Expand All @@ -210,6 +211,7 @@ func New() *Viper {
v := new(Viper)
v.keyDelim = "."
v.configName = "config"
v.configPermissions = os.FileMode(0644)
v.fs = afero.NewOsFs()
v.config = make(map[string]interface{})
v.override = make(map[string]interface{})
Expand Down Expand Up @@ -1328,7 +1330,7 @@ func (v *Viper) writeConfig(filename string, force bool) error {
return fmt.Errorf("File: %s exists. Use WriteConfig to overwrite.", filename)
}
}
f, err := v.fs.OpenFile(filename, flags, os.FileMode(0644))
f, err := v.fs.OpenFile(filename, flags, v.configPermissions)
if err != nil {
return err
}
Expand Down Expand Up @@ -1765,6 +1767,12 @@ func (v *Viper) SetConfigType(in string) {
}
}

// SetConfigPermissions sets the permissions for the config file.
func SetConfigPermissions(perm os.FileMode) { v.SetConfigPermissions(perm) }
func (v *Viper) SetConfigPermissions(perm os.FileMode) {
v.configPermissions = perm.Perm()
}

func (v *Viper) getConfigType() string {
if v.configType != "" {
return v.configType
Expand Down

0 comments on commit fccfc2c

Please sign in to comment.