Skip to content

Commit

Permalink
change config handling (needs tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
djdv committed Sep 12, 2019
1 parent c653fc5 commit b6d1506
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions plugin/plugins/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package filesystem
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -59,15 +60,17 @@ func (fs *FileSystemPlugin) Init(env *plugin.Environment) error {
}

cfg := &Config{}
if env.Config != nil {
byteRep, err := json.Marshal(env.Config)
if err != nil {
return err
}
if err = json.Unmarshal(byteRep, cfg); err != nil {
// config not being set is okay and will load defalts
// config being set with malformed data is not okay and will instruct the daemon to halt-and-catch-fire
rawConf, ok := (env.Config).(json.RawMessage)
if ok {
if err := json.Unmarshal(rawConf, cfg); err != nil {
return err
}
} else {
if env.Config != nil {
return fmt.Errorf("plugin config does not appear to be correctly formatted: %#v", env.Config)
}
cfg = defaultConfig(env.Repo)
}

Expand Down

0 comments on commit b6d1506

Please sign in to comment.