-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline_config.go
67 lines (53 loc) · 1.58 KB
/
pipeline_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package types
import (
"time"
"github.com/calyptia/api/types/errs"
fluentbitconfig "github.com/calyptia/go-fluentbit-config/v2"
)
type ConfigFormat string
const (
ConfigFormatINI ConfigFormat = "ini"
ConfigFormatJSON ConfigFormat = "json"
ConfigFormatYAML ConfigFormat = "yaml"
)
// PipelineConfig model.
type PipelineConfig struct {
ID string `json:"id" yaml:"id"`
RawConfig string `json:"rawConfig" yaml:"rawConfig"`
ConfigFormat ConfigFormat `json:"configFormat"`
CreatedAt time.Time `json:"createdAt" yaml:"createdAt"`
}
func (c *PipelineConfig) ApplyFormat(format ConfigFormat) error {
if c.ConfigFormat == "" {
c.ConfigFormat = ConfigFormatINI
}
if c.ConfigFormat == format {
return nil
}
parsed, err := fluentbitconfig.ParseAs(c.RawConfig, fluentbitconfig.Format(c.ConfigFormat))
if err != nil {
return errs.NewDetailedError(errs.InvalidPipelineConfig, err.Error())
}
raw, err := parsed.DumpAs(fluentbitconfig.Format(format))
if err != nil {
return errs.NewDetailedError(errs.InvalidPipelineConfig, err.Error())
}
c.RawConfig = raw
c.ConfigFormat = format
return nil
}
type CreatePipelineConfig struct {
RawConfig string `json:"rawConfig"`
ConfigFormat ConfigFormat `json:"configFormat"`
}
// PipelineConfigHistoryParams request payload for querying the pipeline config history.
type PipelineConfigHistoryParams struct {
Last *uint
Before *string
ConfigFormat *ConfigFormat
}
// PipelineConfigHistory paginated list.
type PipelineConfigHistory struct {
Items []PipelineConfig
EndCursor *string
}