-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
var ErrIncidentStartDateInFuture = errors.New("event start_date should not be in the future")
example:
func validateEventCreation(incData IncidentData, logger *zap.Logger) error {
if err := validateEventCreationImpact(incData); err != nil {
return err
}
if err := validateEventCreationTimes(incData, logger); err != nil {
return err
}
if len(incData.Updates) != 0 {
return apiErrors.ErrIncidentUpdatesShouldBeEmpty
}
return nil
}
func validateEventCreationImpact(incData IncidentData) error {
if (incData.Type == event.TypeMaintenance || incData.Type == event.TypeInformation) && *incData.Impact != 0 {
return apiErrors.ErrIncidentTypeImpactMismatch
}
if incData.Type == event.TypeIncident && *incData.Impact == 0 {
return apiErrors.ErrIncidentTypeImpactMismatch
}
return nil
}
func validateEventCreationTimes(incData IncidentData, logger *zap.Logger) error {
// you can't create an incident with the end_date
if incData.Type == event.TypeIncident && incData.EndDate != nil {
return apiErrors.ErrIncidentEndDateShouldBeEmpty
}
// you can't create an incident in the future
if incData.Type == event.TypeIncident && incData.StartDate.After(time.Now().UTC()) { //nolint:revive
now := time.Now().UTC()
logger.Debug("start_date validation failed: start_date is in the future",
zap.Time("start_date", incData.StartDate),
zap.Time("current_time", now),
zap.Duration("difference", incData.StartDate.Sub(now)),
)
return apiErrors.ErrIncidentStartDateInFuture
}
if incData.Type == event.TypeMaintenance && incData.EndDate == nil {
return apiErrors.ErrMaintenanceEndDateEmpty
}
return nil
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels