Beispiel #1
0
func silenceSetTimeRange(sil *pb.Silence, now, start, end *timestamp.Timestamp) (*pb.Silence, error) {
	if protoBefore(end, start) {
		return nil, fmt.Errorf("end time must not be before start time")
	}
	// Validate modification based on current silence state.
	switch getState(sil, now) {
	case StateActive:
		if *start != *sil.StartsAt {
			return nil, fmt.Errorf("start time of active silence cannot be modified")
		}
		if protoBefore(end, now) {
			return nil, fmt.Errorf("end time cannot be set into the past")
		}
	case StatePending:
		if protoBefore(start, now) {
			return nil, fmt.Errorf("start time cannot be set into the past")
		}
	case StateExpired:
		return nil, fmt.Errorf("expired silence must not be modified")
	default:
		panic("unknown silence state")
	}

	sil = cloneSilence(sil)
	sil.StartsAt = start
	sil.EndsAt = end
	sil.UpdatedAt = now

	return sil, nil
}