forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rendered_job.go
64 lines (54 loc) · 1.45 KB
/
rendered_job.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 templatescompiler
import (
"fmt"
bireljob "github.com/cloudfoundry/bosh-cli/release/job"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type RenderedJob interface {
Job() bireljob.Job
Path() string // dir of multiple rendered files
Delete() error
DeleteSilently()
}
type renderedJob struct {
job bireljob.Job
path string
fs boshsys.FileSystem
logger boshlog.Logger
logTag string
}
func NewRenderedJob(
job bireljob.Job,
path string,
fs boshsys.FileSystem,
logger boshlog.Logger,
) RenderedJob {
return &renderedJob{
job: job,
path: path,
fs: fs,
logger: logger,
logTag: "renderedJob",
}
}
func (j *renderedJob) Job() bireljob.Job { return j.job }
// Path returns a parent directory with one or more sub-dirs for each job, each with one or more rendered template files
func (j *renderedJob) Path() string { return j.path }
func (j *renderedJob) Delete() error {
err := j.fs.RemoveAll(j.path)
if err != nil {
return bosherr.WrapErrorf(err, "Deleting rendered job '%s' tarball '%s'", j.job.Name, j.path)
}
return nil
}
func (j *renderedJob) DeleteSilently() {
err := j.Delete()
if err != nil {
j.logger.Error(j.logTag, "Failed to delete rendered job: %s", err.Error())
}
}
func (j *renderedJob) String() string {
return fmt.Sprintf("renderedJob{job: '%s', path: '%s'}", j.job.Name(), j.path)
}