Skip to content

Commit

Permalink
PC-10142: Remove models from SDK (#132)
Browse files Browse the repository at this point in the history
* remove models from SDK

* hide stringinterpolation
  • Loading branch information
nieomylnieja authored Sep 27, 2023
1 parent 1403f59 commit 296c046
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 71 deletions.
24 changes: 12 additions & 12 deletions manifest/v1alpha/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ type AlertMetadata struct {

// AlertSpec represents content of Alert's Spec
type AlertSpec struct {
AlertPolicy Metadata `json:"alertPolicy"`
SLO Metadata `json:"slo"`
Service Metadata `json:"service"`
Objective AlertObjective `json:"objective"`
Severity string `json:"severity" validate:"required,severity" example:"High"`
Status string `json:"status" example:"Resolved"`
TriggeredMetricTime string `json:"triggeredMetricTime"`
TriggeredClockTime string `json:"triggeredClockTime"`
ResolvedClockTime *string `json:"resolvedClockTime,omitempty"`
ResolvedMetricTime *string `json:"resolvedMetricTime,omitempty"`
CoolDown string `json:"coolDown"`
Conditions []AlertCondition `json:"conditions"`
AlertPolicy AlertPolicyMetadata `json:"alertPolicy"`
SLO SLOMetadata `json:"slo"`
Service ServiceMetadata `json:"service"`
Objective AlertObjective `json:"objective"`
Severity string `json:"severity" validate:"required,severity" example:"High"`
Status string `json:"status" example:"Resolved"`
TriggeredMetricTime string `json:"triggeredMetricTime"`
TriggeredClockTime string `json:"triggeredClockTime"`
ResolvedClockTime *string `json:"resolvedClockTime,omitempty"`
ResolvedMetricTime *string `json:"resolvedMetricTime,omitempty"`
CoolDown string `json:"coolDown"`
Conditions []AlertCondition `json:"conditions"`
}

type AlertObjective struct {
Expand Down
11 changes: 8 additions & 3 deletions manifest/v1alpha/alert_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ type AlertMethodMetadata struct {
// PublicAlertMethod represents the configuration required to send a notification to an external service
// when an alert is triggered.
type PublicAlertMethod struct {
ObjectHeader `json:",inline"`
Spec PublicAlertMethodSpec `json:"spec"`
Status *PublicAlertMethodStatus `json:"status,omitempty"`
APIVersion string `json:"apiVersion"`
Kind manifest.Kind `json:"kind"`
Metadata AlertMethodMetadata `json:"metadata"`
Spec PublicAlertMethodSpec `json:"spec"`
Status *PublicAlertMethodStatus `json:"status,omitempty"`

Organization string `json:"organization,omitempty"`
ManifestSource string `json:"manifestSrc,omitempty"`
}

// PublicAlertMethodStatus represents content of Status optional for PublicAlertMethod Object
Expand Down
54 changes: 0 additions & 54 deletions manifest/v1alpha/models.go

This file was deleted.

7 changes: 5 additions & 2 deletions manifest/v1alpha/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2237,14 +2237,17 @@ func isValidTimeSliceTargetValue(tsv float64) bool {
return tsv > 0.0 && tsv <= 1.00
}

// stringInterpolationPlaceholder common symbol to use in strings for interpolation e.g. "My amazing {} Service"
const stringInterpolationPlaceholder = "{}"

func isValidObjectNameWithStringInterpolation(fl v.FieldLevel) bool {
toCheck := fl.Field().String()
if !strings.Contains(toCheck, StringInterpolationPlaceholder) {
if !strings.Contains(toCheck, stringInterpolationPlaceholder) {
return false
}
// During actual interpolation {} will be replaced with previous validated name,
// replace here with test because valid DNS1123Label cannot contain {} and check
toCheck = StringInterpolation(toCheck, "test")
toCheck = strings.ReplaceAll(toCheck, stringInterpolationPlaceholder, "test")
return len(IsDNS1123Label(toCheck)) == 0
}

Expand Down

0 comments on commit 296c046

Please sign in to comment.