-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kubaceg
committed
Feb 6, 2024
1 parent
efbd0d9
commit 7636972
Showing
16 changed files
with
470 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ DataExport | |
RoleBinding | ||
Annotation | ||
UserGroup | ||
BudgetAdjustment | ||
)*/ | ||
type Kind int | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package budgetadjustment | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/nobl9/nobl9-go/manifest" | ||
) | ||
|
||
//go:generate go run ../../../scripts/generate-object-impl.go BudgetAdjustment | ||
|
||
func New(metadata Metadata, spec Spec) BudgetAdjustment { | ||
return BudgetAdjustment{ | ||
APIVersion: manifest.VersionV1alpha, | ||
Kind: manifest.KindBudgetAdjustment, | ||
Metadata: metadata, | ||
Spec: spec, | ||
} | ||
} | ||
|
||
// BudgetAdjustment represents a object for manipulating budget adjustments. | ||
type BudgetAdjustment struct { | ||
APIVersion manifest.Version `json:"apiVersion"` | ||
Kind manifest.Kind `json:"kind"` | ||
Metadata Metadata `json:"metadata"` | ||
Spec Spec `json:"spec"` | ||
|
||
Organization string `json:"organization,omitempty"` | ||
ManifestSource string `json:"manifestSrc,omitempty"` | ||
} | ||
|
||
type Metadata struct { | ||
Name string `json:"name"` | ||
DisplayName string `json:"displayName,omitempty"` | ||
} | ||
|
||
// Spec represents content of BudgetAdjustment's Spec. | ||
type Spec struct { | ||
Description string `json:"description,omitempty"` | ||
FirstEventStart time.Time `json:"firstEventStart"` | ||
Duration time.Duration `json:"duration"` | ||
Rrule string `json:"rrule,omitempty"` | ||
Filters Filters `json:"filters"` | ||
} | ||
|
||
type Filters struct { | ||
Slos []Slo `json:"slos"` | ||
} | ||
|
||
type Slo struct { | ||
Name string `json:"name"` | ||
Project string `json:"project"` | ||
} |
49 changes: 49 additions & 0 deletions
49
manifest/v1alpha/budgetAdjustment/budget_adjustment_object.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
manifest/v1alpha/budgetAdjustment/test_data/expected_metadata_error.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Validation for BudgetAdjustment 'MY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENST' has failed for the following fields: | ||
- 'metadata.name' with value 'MY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUSTMENSTMY BUDGET ADJUST...': | ||
- length must be between 1 and 63 | ||
- string does not match regular expression: '^[a-z0-9]([-a-z0-9]*[a-z0-9])?$' (e.g. 'my-name', '123-abc'); a DNS-1123 compliant name must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character | ||
- 'metadata.displayName' with value 'my-budgetadjustmentmy-budgetadjustmentmy-budgetadjustmentmy-budgetadjustmentmy-budgetadjustmentmy-bu...': | ||
- length must be between 0 and 63 | ||
- 'spec.firstEventStart': | ||
- property is required but was empty | ||
- 'spec.duration': | ||
- property is required but was empty | ||
- 'spec.filters.slos': | ||
- length must be greater than or equal to 1 | ||
Manifest source: /home/me/budgetadjustment.yaml |
4 changes: 4 additions & 0 deletions
4
manifest/v1alpha/budgetAdjustment/test_data/invalid-duration-resolution.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Validation for BudgetAdjustment 'my-budget-adjustement' has failed for the following fields: | ||
- 'spec.duration' with value '1m1s': | ||
- duration must be in whole minutes without seconds | ||
Manifest source: /home/me/budgetadjustment.yaml |
4 changes: 4 additions & 0 deletions
4
manifest/v1alpha/budgetAdjustment/test_data/invalid-rrule.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Validation for BudgetAdjustment 'my-budget-adjustement' has failed for the following fields: | ||
- 'spec.rrule' with value 'FREQ=WEKLY;INTERVAL=2': | ||
- invalid rrule: undefined frequency: WEKLY | ||
Manifest source: /home/me/budgetadjustment.yaml |
4 changes: 4 additions & 0 deletions
4
manifest/v1alpha/budgetAdjustment/test_data/no-slo-filters.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Validation for BudgetAdjustment 'my-budget-adjustement' has failed for the following fields: | ||
- 'spec.filters.slos': | ||
- length must be greater than or equal to 1 | ||
Manifest source: /home/me/budgetadjustment.yaml |
4 changes: 4 additions & 0 deletions
4
manifest/v1alpha/budgetAdjustment/test_data/slo-without-name.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Validation for BudgetAdjustment 'my-budget-adjustement' has failed for the following fields: | ||
- 'spec.filters.slos[0].name': | ||
- property is required but was empty | ||
Manifest source: /home/me/budgetadjustment.yaml |
4 changes: 4 additions & 0 deletions
4
manifest/v1alpha/budgetAdjustment/test_data/slo-without-project.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Validation for BudgetAdjustment 'my-budget-adjustement' has failed for the following fields: | ||
- 'spec.filters.slos[0].project': | ||
- property is required but was empty | ||
Manifest source: /home/me/budgetadjustment.yaml |
4 changes: 4 additions & 0 deletions
4
manifest/v1alpha/budgetAdjustment/test_data/too-short-duration.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Validation for BudgetAdjustment 'my-budget-adjustement' has failed for the following fields: | ||
- 'spec.duration' with value '1s': | ||
- duration must be in whole minutes without seconds | ||
Manifest source: /home/me/budgetadjustment.yaml |
4 changes: 4 additions & 0 deletions
4
manifest/v1alpha/budgetAdjustment/test_data/wrong-rrule-format.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Validation for BudgetAdjustment 'my-budget-adjustement' has failed for the following fields: | ||
- 'spec.rrule' with value 'some test': | ||
- invalid rrule: wrong format | ||
Manifest source: /home/me/budgetadjustment.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package budgetadjustment | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/teambition/rrule-go" | ||
|
||
validationV1Alpha "github.com/nobl9/nobl9-go/internal/manifest/v1alpha" | ||
"github.com/nobl9/nobl9-go/internal/validation" | ||
"github.com/nobl9/nobl9-go/manifest/v1alpha" | ||
) | ||
|
||
var budgetAdjustmentValidation = validation.New[BudgetAdjustment]( | ||
validation.For(func(b BudgetAdjustment) Metadata { return b.Metadata }). | ||
Include(metadataValidation), | ||
validation.For(func(b BudgetAdjustment) Spec { return b.Spec }). | ||
WithName("spec"). | ||
Include(specValidation), | ||
) | ||
|
||
var metadataValidation = validation.New[Metadata]( | ||
validationV1Alpha.FieldRuleMetadataName(func(m Metadata) string { return m.Name }), | ||
validationV1Alpha.FieldRuleMetadataDisplayName(func(m Metadata) string { return m.DisplayName }), | ||
) | ||
|
||
var specValidation = validation.New[Spec]( | ||
validation.For(func(s Spec) string { return s.Description }). | ||
WithName("description"). | ||
Rules(validation.StringDescription()), | ||
validation.For(func(s Spec) time.Time { return s.FirstEventStart }). | ||
WithName("firstEventStart"). | ||
Required(), | ||
validation.For(func(s Spec) time.Duration { return s.Duration }). | ||
WithName("duration"). | ||
Required(). | ||
Rules(durationValidationRule()), | ||
validation.For(func(s Spec) string { return s.Rrule }). | ||
WithName("rrule"). | ||
Rules(rruleValidationRule()), | ||
validation.For(func(s Spec) Filters { return s.Filters }). | ||
WithName("filters"). | ||
Include(filtersValidationRule), | ||
) | ||
|
||
var filtersValidationRule = validation.New[Filters]( | ||
validation.ForEach(func(f Filters) []Slo { return f.Slos }). | ||
WithName("slos"). | ||
Rules(validation.SliceMinLength[[]Slo](1)). | ||
IncludeForEach(sloValidationRule), | ||
) | ||
|
||
var sloValidationRule = validation.New[Slo]( | ||
validation.For(func(s Slo) string { return s.Project }). | ||
WithName("project"). | ||
Required(), | ||
validation.For(func(s Slo) string { return s.Name }). | ||
WithName("name"). | ||
Required(), | ||
) | ||
|
||
func durationValidationRule() validation.SingleRule[time.Duration] { | ||
return validation.NewSingleRule(func(v time.Duration) error { | ||
if v.Truncate(time.Minute) != v { | ||
return errors.New("duration must be in whole minutes without seconds") | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
func rruleValidationRule() validation.SingleRule[string] { | ||
return validation.NewSingleRule(func(v string) error { | ||
if len(v) == 0 { | ||
return nil | ||
} | ||
|
||
_, err := rrule.StrToRRule(v) | ||
if err != nil { | ||
return errors.Wrap(err, "invalid rrule") | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
func validate(b BudgetAdjustment) *v1alpha.ObjectError { | ||
return v1alpha.ValidateObject(budgetAdjustmentValidation, b) | ||
} |
Oops, something went wrong.