forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_registry.go
37 lines (29 loc) · 892 Bytes
/
file_registry.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
package infrastructure
import (
"encoding/json"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type fileRegistry struct {
registryFilePath string
fs boshsys.FileSystem
}
func NewFileRegistry(registryFilePath string, fs boshsys.FileSystem) Registry {
return &fileRegistry{
registryFilePath: registryFilePath,
fs: fs,
}
}
func (r *fileRegistry) GetSettings() (boshsettings.Settings, error) {
var settings boshsettings.Settings
contents, err := r.fs.ReadFile(r.registryFilePath)
if err != nil {
return settings, bosherr.WrapError(err, "Read settings file")
}
err = json.Unmarshal([]byte(contents), &settings)
if err != nil {
return settings, bosherr.WrapError(err, "Unmarshal json settings")
}
return settings, nil
}