-
Notifications
You must be signed in to change notification settings - Fork 25
/
lifecycle.go
57 lines (46 loc) · 1.54 KB
/
lifecycle.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
package lifecycles
import (
"strings"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/resources"
"github.com/go-playground/validator/v10"
)
type Lifecycle struct {
Description string `json:"Description,omitempty"`
Name string `json:"Name" validate:"required"`
Phases []*Phase `json:"Phases,omitempty"`
ReleaseRetentionPolicy *core.RetentionPeriod `json:"ReleaseRetentionPolicy,omitempty"`
SpaceID string `json:"SpaceId,omitempty"`
TentacleRetentionPolicy *core.RetentionPeriod `json:"TentacleRetentionPolicy,omitempty"`
resources.Resource
}
const (
RetentionUnitDays string = "Days"
RetentionUnitItems string = "Items"
)
func NewLifecycle(name string) *Lifecycle {
return &Lifecycle{
Name: strings.TrimSpace(name),
Phases: []*Phase{},
ReleaseRetentionPolicy: core.NewRetentionPeriod(30, RetentionUnitDays, false),
TentacleRetentionPolicy: core.NewRetentionPeriod(30, RetentionUnitDays, false),
Resource: *resources.NewResource(),
}
}
// Validate checks the state of the lifecycle and returns an error if invalid.
func (l *Lifecycle) Validate() error {
validate := validator.New()
err := validate.Struct(l)
if err != nil {
return err
}
if l.Phases != nil {
for _, phase := range l.Phases {
phaseErr := validate.Struct(phase)
if phaseErr != nil {
return phaseErr
}
}
}
return nil
}