-
Notifications
You must be signed in to change notification settings - Fork 115
/
file_settings_source.go
57 lines (43 loc) · 1.23 KB
/
file_settings_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package infrastructure
import (
"encoding/json"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
)
type FileSettingsSource struct {
settingsFilePath string
fs boshsys.FileSystem
logger boshlog.Logger
logTag string
}
func NewFileSettingsSource(
settingsFilePath string,
fs boshsys.FileSystem,
logger boshlog.Logger,
) *FileSettingsSource {
return &FileSettingsSource{
settingsFilePath: settingsFilePath,
fs: fs,
logTag: "FileSettingsSource",
logger: logger,
}
}
func (s *FileSettingsSource) PublicSSHKeyForUsername(string) (string, error) {
return "", nil
}
func (s *FileSettingsSource) Settings() (boshsettings.Settings, error) {
var settings boshsettings.Settings
contents, err := s.fs.ReadFileWithOpts(s.settingsFilePath, boshsys.ReadOpts{Quiet: true})
if err != nil {
return settings, bosherr.WrapErrorf(
err, "Reading from file '%s'", s.settingsFilePath)
}
err = json.Unmarshal(contents, &settings)
if err != nil {
return settings, bosherr.WrapErrorf(
err, "Parsing file settings from '%s'", s.settingsFilePath)
}
return settings, nil
}