Skip to content

Commit b7e9146

Browse files
committed
TUN-3558: cloudflared allows empty config files
1 parent 4c1b895 commit b7e9146

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

cmd/cloudflared/config/configuration.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"fmt"
5+
"io"
56
"net/url"
67
"os"
78
"path/filepath"
@@ -392,6 +393,10 @@ func ReadConfigFile(c *cli.Context, log logger.Service) (*configFileSettings, er
392393
}
393394
defer file.Close()
394395
if err := yaml.NewDecoder(file).Decode(&configuration); err != nil {
396+
if err == io.EOF {
397+
log.Errorf("Configuration file %s was empty", configFile)
398+
return &configuration, nil
399+
}
395400
return nil, errors.Wrap(err, "error parsing YAML in config file at "+configFile)
396401
}
397402
configuration.sourceFile = configFile

cmd/cloudflared/config/manager.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"io"
45
"os"
56

67
"github.com/cloudflare/cloudflared/logger"
@@ -27,7 +28,7 @@ type FileManager struct {
2728
notifier Notifier
2829
configPath string
2930
logger logger.Service
30-
ReadConfig func(string) (Root, error)
31+
ReadConfig func(string, logger.Service) (Root, error)
3132
}
3233

3334
// NewFileManager creates a config manager
@@ -59,15 +60,15 @@ func (m *FileManager) Start(notifier Notifier) error {
5960

6061
// GetConfig reads the yaml file from the disk
6162
func (m *FileManager) GetConfig() (Root, error) {
62-
return m.ReadConfig(m.configPath)
63+
return m.ReadConfig(m.configPath, m.logger)
6364
}
6465

6566
// Shutdown stops the watcher
6667
func (m *FileManager) Shutdown() {
6768
m.watcher.Shutdown()
6869
}
6970

70-
func readConfigFromPath(configPath string) (Root, error) {
71+
func readConfigFromPath(configPath string, log logger.Service) (Root, error) {
7172
if configPath == "" {
7273
return Root{}, errors.New("unable to find config file")
7374
}
@@ -80,6 +81,10 @@ func readConfigFromPath(configPath string) (Root, error) {
8081

8182
var config Root
8283
if err := yaml.NewDecoder(file).Decode(&config); err != nil {
84+
if err == io.EOF {
85+
log.Errorf("Configuration file %s was empty", configPath)
86+
return Root{}, nil
87+
}
8388
return Root{}, errors.Wrap(err, "error parsing YAML in config file at "+configPath)
8489
}
8590

cmd/cloudflared/config/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestConfigChanged(t *testing.T) {
5757
},
5858
},
5959
}
60-
configRead := func(configPath string) (Root, error) {
60+
configRead := func(configPath string, log logger.Service) (Root, error) {
6161
return *c, nil
6262
}
6363
wait := make(chan struct{})

0 commit comments

Comments
 (0)