This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release_repo.go
64 lines (55 loc) · 1.74 KB
/
release_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package config
import (
"github.com/cloudfoundry/bosh-cli/release"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshuuid "github.com/cloudfoundry/bosh-utils/uuid"
)
// ReleaseRepo persists releases metadata
type ReleaseRepo interface {
List() ([]ReleaseRecord, error)
Update([]release.Release) error
}
type releaseRepo struct {
deploymentStateService DeploymentStateService
uuidGenerator boshuuid.Generator
}
func NewReleaseRepo(deploymentStateService DeploymentStateService, uuidGenerator boshuuid.Generator) ReleaseRepo {
return releaseRepo{
deploymentStateService: deploymentStateService,
uuidGenerator: uuidGenerator,
}
}
func (r releaseRepo) Update(releases []release.Release) error {
newRecordIDs := []string{}
newRecords := []ReleaseRecord{}
deploymentState, err := r.deploymentStateService.Load()
if err != nil {
return bosherr.WrapError(err, "Loading existing config")
}
for _, release := range releases {
newRecord := ReleaseRecord{
Name: release.Name(),
Version: release.Version(),
}
newRecord.ID, err = r.uuidGenerator.Generate()
if err != nil {
return bosherr.WrapError(err, "Generating release id")
}
newRecords = append(newRecords, newRecord)
newRecordIDs = append(newRecordIDs, newRecord.ID)
}
deploymentState.CurrentReleaseIDs = newRecordIDs
deploymentState.Releases = newRecords
err = r.deploymentStateService.Save(deploymentState)
if err != nil {
return bosherr.WrapError(err, "Updating current release record")
}
return nil
}
func (r releaseRepo) List() ([]ReleaseRecord, error) {
deploymentState, err := r.deploymentStateService.Load()
if err != nil {
return []ReleaseRecord{}, bosherr.WrapError(err, "Loading existing config")
}
return deploymentState.Releases, nil
}