forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment_repo.go
49 lines (39 loc) · 1.2 KB
/
deployment_repo.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
package config
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type DeploymentRepo interface {
UpdateCurrent(manifestSHA string) error
FindCurrent() (manifestSHA string, found bool, err error)
}
type deploymentRepo struct {
deploymentStateService DeploymentStateService
}
func NewDeploymentRepo(deploymentStateService DeploymentStateService) DeploymentRepo {
return deploymentRepo{
deploymentStateService: deploymentStateService,
}
}
func (r deploymentRepo) FindCurrent() (string, bool, error) {
deploymentState, err := r.deploymentStateService.Load()
if err != nil {
return "", false, bosherr.WrapError(err, "Loading existing config")
}
currentManifestSHA := deploymentState.CurrentManifestSHA
if currentManifestSHA != "" {
return currentManifestSHA, true, nil
}
return "", false, nil
}
func (r deploymentRepo) UpdateCurrent(manifestSHA string) error {
deploymentState, err := r.deploymentStateService.Load()
if err != nil {
return bosherr.WrapError(err, "Loading existing config")
}
deploymentState.CurrentManifestSHA = manifestSHA
err = r.deploymentStateService.Save(deploymentState)
if err != nil {
return bosherr.WrapError(err, "Saving new config")
}
return nil
}