-
Notifications
You must be signed in to change notification settings - Fork 115
/
update_settings.go
86 lines (70 loc) · 2.32 KB
/
update_settings.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package action
import (
"errors"
"encoding/json"
"github.com/cloudfoundry/bosh-agent/platform"
"github.com/cloudfoundry/bosh-agent/platform/cert"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
"github.com/cloudfoundry/bosh-utils/logger"
"path/filepath"
)
type UpdateSettingsAction struct {
trustedCertManager cert.Manager
logger logger.Logger
settingsService boshsettings.Service
platform platform.Platform
}
func NewUpdateSettings(service boshsettings.Service, platform platform.Platform, trustedCertManager cert.Manager, logger logger.Logger) UpdateSettingsAction {
return UpdateSettingsAction{
trustedCertManager: trustedCertManager,
logger: logger,
settingsService: service,
platform: platform,
}
}
func (a UpdateSettingsAction) IsAsynchronous(_ ProtocolVersion) bool {
return true
}
func (a UpdateSettingsAction) IsPersistent() bool {
return false
}
func (a UpdateSettingsAction) IsLoggable() bool {
return true
}
func (a UpdateSettingsAction) Run(newUpdateSettings boshsettings.UpdateSettings) (string, error) {
err := a.settingsService.LoadSettings()
if err != nil {
return "", err
}
for _, diskAssociation := range newUpdateSettings.DiskAssociations {
diskSettingsToAssociate, err := a.settingsService.GetPersistentDiskSettings(diskAssociation.DiskCID)
if err != nil {
return "", bosherr.WrapError(err, "Fetching disk settings")
}
err = a.platform.AssociateDisk(diskAssociation.Name, diskSettingsToAssociate)
if err != nil {
return "", err
}
}
err = a.trustedCertManager.UpdateCertificates(newUpdateSettings.TrustedCerts)
if err != nil {
return "", err
}
updateSettingsJSON, err := json.Marshal(newUpdateSettings)
if err != nil {
return "", bosherr.WrapError(err, "Marshalling updateSettings json")
}
updateSettingsPath := filepath.Join(a.platform.GetDirProvider().BoshDir(), "update_settings.json")
err = a.platform.GetFs().WriteFile(updateSettingsPath, updateSettingsJSON)
if err != nil {
return "", bosherr.WrapError(err, "writing update settings json")
}
return "updated", nil
}
func (a UpdateSettingsAction) Resume() (interface{}, error) {
return nil, errors.New("not supported")
}
func (a UpdateSettingsAction) Cancel() error {
return errors.New("not supported")
}