Configuration - Fixed default file mode
This commit is contained in:
parent
44eb5c5356
commit
54a808386e
2 changed files with 13 additions and 4 deletions
|
@ -143,7 +143,7 @@ func (b *tCertificateBuilder) MustWrite(force bool) bool {
|
||||||
// Write the file's data
|
// Write the file's data
|
||||||
func (b *tCertificateBuilder) WriteFile() error {
|
func (b *tCertificateBuilder) WriteFile() error {
|
||||||
log.WithField("file", b.Config.Path).Info("Writing certificate data to file")
|
log.WithField("file", b.Config.Path).Info("Writing certificate data to file")
|
||||||
err := ioutil.WriteFile(b.Config.Path, b.text, b.Config.Mode)
|
err := ioutil.WriteFile(b.Config.Path, b.text, b.Config.FileMode())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
b.changed = true
|
b.changed = true
|
||||||
}
|
}
|
||||||
|
@ -152,9 +152,9 @@ func (b *tCertificateBuilder) WriteFile() error {
|
||||||
|
|
||||||
// Update the file's owner and group
|
// Update the file's owner and group
|
||||||
func (b *tCertificateBuilder) UpdatePrivileges() error {
|
func (b *tCertificateBuilder) UpdatePrivileges() error {
|
||||||
update_mode := !b.changed && b.existing.mode != b.Config.Mode
|
update_mode := !b.changed && b.existing.mode != b.Config.FileMode()
|
||||||
if update_mode {
|
if update_mode {
|
||||||
err := os.Chmod(b.Config.Path, b.Config.Mode)
|
err := os.Chmod(b.Config.Path, b.Config.FileMode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
11
config.go
11
config.go
|
@ -75,7 +75,7 @@ type (
|
||||||
// Certificate file configuration.
|
// Certificate file configuration.
|
||||||
tCertificateFileConfig struct {
|
tCertificateFileConfig struct {
|
||||||
Path string `yaml:"path"`
|
Path string `yaml:"path"`
|
||||||
Mode os.FileMode `yaml:"mode"`
|
Mode *os.FileMode `yaml:"mode"`
|
||||||
Owner string `yaml:"owner"`
|
Owner string `yaml:"owner"`
|
||||||
Group string `yaml:"group"`
|
Group string `yaml:"group"`
|
||||||
PrependFiles []string `yaml:"prepend_files"`
|
PrependFiles []string `yaml:"prepend_files"`
|
||||||
|
@ -258,6 +258,15 @@ func (c *tCertFileUpdateConfig) Validate(handlers *tHandlers) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the mode of a certificate file
|
||||||
|
func (c *tCertificateFileConfig) FileMode() os.FileMode {
|
||||||
|
if c.Mode == nil {
|
||||||
|
return 0640
|
||||||
|
} else {
|
||||||
|
return *c.Mode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Validate a certificate file configuration entry
|
// Validate a certificate file configuration entry
|
||||||
func (c *tCertificateFileConfig) Validate(handlers *tHandlers) error {
|
func (c *tCertificateFileConfig) Validate(handlers *tHandlers) error {
|
||||||
if !valid.IsUnixFilePath(c.Path) {
|
if !valid.IsUnixFilePath(c.Path) {
|
||||||
|
|
Loading…
Reference in a new issue