Skip to content

Commit

Permalink
feat: Provide time.Parse and time.Now while evaluating trigger condition
Browse files Browse the repository at this point in the history
  • Loading branch information
d.mann committed Aug 21, 2022
1 parent 69fd80c commit 468fab7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion utils/record/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func NewAPIFactorySettings() api.Settings {
ConfigMapName: NotificationConfigMap,
InitGetVars: func(cfg *api.Config, configMap *corev1.ConfigMap, secret *corev1.Secret) (api.GetVars, error) {
return func(obj map[string]interface{}, dest services.Destination) map[string]interface{} {
return map[string]interface{}{"rollout": obj}
return map[string]interface{}{"rollout": obj, "time": newTimeExprs()}
}, nil
},
}
Expand Down Expand Up @@ -353,3 +353,22 @@ func translateReasonToTrigger(reason string) string {
trigger = matchAllCap.ReplaceAllString(trigger, "${1}-${2}")
return "on-" + strings.ToLower(trigger)
}

func newTimeExprs() map[string]interface{} {
return map[string]interface{}{
"Parse": parse,
"Now": now,
}
}

func parse(timestamp string) time.Time {
res, err := time.Parse(time.RFC3339, timestamp)
if err != nil {
panic(err)
}
return res
}

func now() time.Time {
return time.Now()
}

0 comments on commit 468fab7

Please sign in to comment.