NewApp constructs a new bootstrap application with the specified configuration and a list of options. The configuration is passed from individual command work functions.
(cfg *config.Config, options ...Option)
| 106 | // and a list of options. The configuration is passed from individual command work |
| 107 | // functions. |
| 108 | func NewApp(cfg *config.Config, options ...Option) (*App, error) { |
| 109 | if err := InitConfigAndLogger(cfg); err != nil { |
| 110 | return nil, err |
| 111 | } |
| 112 | var opts opts |
| 113 | var sigs chan struct{} |
| 114 | for _, opt := range options { |
| 115 | opt(&opts) |
| 116 | } |
| 117 | if cfg.DebugPrivilege && opts.setDebugPrivilege { |
| 118 | sys.SetDebugPrivilege() |
| 119 | } |
| 120 | if opts.installSignals { |
| 121 | sigs = signals.Install() |
| 122 | } |
| 123 | if opts.isCaptureReplay { |
| 124 | reader, err := cap.NewReader(cfg.CapFile, cfg) |
| 125 | if err != nil { |
| 126 | return nil, err |
| 127 | } |
| 128 | app := &App{ |
| 129 | config: cfg, |
| 130 | reader: reader, |
| 131 | signals: sigs, |
| 132 | } |
| 133 | return app, nil |
| 134 | } |
| 135 | |
| 136 | hsnap := handle.NewSnapshotter(cfg, opts.handleSnapshotFn) |
| 137 | psnap := ps.NewSnapshotter(hsnap, cfg) |
| 138 | |
| 139 | var engine *rules.Engine |
| 140 | var rs *config.RulesCompileResult |
| 141 | |
| 142 | if cfg.Filters.Rules.Enabled && !cfg.ForwardMode && !cfg.IsCaptureSet() && !cfg.IsFilamentSet() { |
| 143 | engine = rules.NewEngine(psnap, cfg) |
| 144 | var err error |
| 145 | rs, err = engine.Compile() |
| 146 | if err != nil { |
| 147 | return nil, err |
| 148 | } |
| 149 | if rs != nil { |
| 150 | log.Infof("rules compile summary: %s", rs) |
| 151 | } |
| 152 | } else { |
| 153 | log.Info("rule engine is disabled") |
| 154 | } |
| 155 | |
| 156 | evs := NewEventSourceControl(psnap, hsnap, cfg, rs) |
| 157 | |
| 158 | app := &App{ |
| 159 | config: cfg, |
| 160 | evs: evs, |
| 161 | engine: engine, |
| 162 | hsnap: hsnap, |
| 163 | psnap: psnap, |
| 164 | signals: sigs, |
| 165 | } |
no test coverage detected