MCPcopy
hub / github.com/crowdsecurity/crowdsec / wizard

Method wizard

cmd/crowdsec-cli/clisetup/wizard.go:90–265  ·  view source on GitHub ↗
(ctx context.Context, detectConfig *setup.DetectConfig, opts setup.DetectOptions, acquisDir string, interactive bool, dryRun bool, logger logrus.FieldLogger)

Source from the content-addressed store, hash-verified

88}
89
90func (cli *cliSetup) wizard(ctx context.Context, detectConfig *setup.DetectConfig, opts setup.DetectOptions, acquisDir string, interactive bool, dryRun bool, logger logrus.FieldLogger) error {
91 cfg := cli.cfg()
92
93 if err := require.Agent(cfg); err != nil {
94 return err
95 }
96
97 userAcquisFiles, err := filterGeneratedAcquis(cfg.Crowdsec.AcquisitionFiles, logger)
98 if err != nil {
99 return err
100 }
101
102 if dryRun {
103 fmt.Fprintln(os.Stdout, color.YellowString("Dry run mode enabled. No changes will be made."))
104 fmt.Fprintln(os.Stdout)
105 }
106
107 detect := true
108
109 if !dryRun && len(userAcquisFiles) != 0 {
110 fmt.Fprintln(os.Stdout, "The following acquisition files were not generated by crowdsec, or were altered:")
111
112 for _, f := range userAcquisFiles {
113 fmt.Fprintln(os.Stdout, " - "+f)
114 }
115
116 if !interactive {
117 fmt.Fprintln(os.Stdout, "The automatic setup will not proceed to avoid any conflict with the above files. To add new services, run 'cscli setup' in a shell.")
118 return nil
119 }
120
121 fmt.Fprintln(os.Stdout)
122 fmt.Fprintln(os.Stdout, "After the setup, make sure that these files don't conflict with the new acquisition configuration. In particular, don't parse the same log files multiple times.")
123 fmt.Fprintln(os.Stdout)
124
125 // change to a safe default to avoid overwriting anything without user consent
126 detect = false
127 }
128
129 if interactive {
130 prompt := survey.Confirm{
131 Message: "Detect and configure services?",
132 Default: detect,
133 }
134
135 if err := survey.AskOne(&prompt, &detect); err != nil {
136 return err
137 }
138 }
139
140 fmt.Fprintln(os.Stdout)
141
142 if !detect {
143 leavingMessage(os.Stdout)
144 return nil
145 }
146
147 units := setup.UnitMap{}

Callers 2

newUnattendedCmdMethod · 0.95
newInteractiveCmdMethod · 0.95

Calls 14

installMethod · 0.95
acquisitionMethod · 0.95
AgentFunction · 0.92
DetectSystemdUnitsFunction · 0.92
DetectProcessesFunction · 0.92
BuildSetupFunction · 0.92
UserMessageFunction · 0.92
filterGeneratedAcquisFunction · 0.85
leavingMessageFunction · 0.85
cfgMethod · 0.80
DetectedServicesMethod · 0.80
CollectHubSpecsMethod · 0.80

Tested by

no test coverage detected