plugin-sdk
plugin-sdk copied to clipboard
feat: Add Time configtype
Summary
This adds a new Time type to be used in plugin specs that can represent either fixed times or relative times. A future PR should extend the duration parsing to handle days, etc.
kind: source
spec:
name: "orb"
registry: "grpc"
path: "localhost:7777"
version: "v1.0.0"
tables:
["*"]
destinations:
- "sqlite"
spec:
api_key: "${CQ_ORB_API_KEY}"
timeframe_start: 10 days ago
timeframe_end: "2024-09-25T03:52:40.14157935-04:00"
Here timeframe_start
and timeframe_end
are both configtype.Time types. Using mixed relative/fixed timestamps for timeframes isn't really useful here as the relative one will be relative to the run-time of the sync but in this example having
timeframe_start: 10 days ago
timeframe_end: now
or even omitting timeframe_end
entirely is more useful
timeframe_start: 10 days ago
The plugin is free to define default like so
type Spec struct {
// TimeframeStart is the beginning of the timeframe in which to fetch cost data.
TimeframeStart configtype.Time `json:"timeframe_start"`
// TimeframeEnd is the beginning of the timeframe in which to fetch cost data.
TimeframeEnd configtype.Time `json:"timeframe_end"`
// ...
}
func (s *Spec) SetDefaults() {
if s.TimeframeStart.IsZero() {
s.TimeframeStart = configtype.NewRelativeTime(-1 * 365 * 24 * time.Hour)
}
if s.TimeframeEnd.IsZero() {
s.TimeframeEnd = configtype.NewRelativeTime(0)
}
}