MCPcopy Create free account
hub / github.com/crowdsecurity/crowdsec / queryLAPIStatus

Function queryLAPIStatus

cmd/crowdsec-cli/clilapi/status.go:26–56  ·  view source on GitHub ↗

queryLAPIStatus checks if the Local API is reachable, and if the credentials are correct.

(ctx context.Context, hub *cwhub.Hub, credURL string, login string, password string)

Source from the content-addressed store, hash-verified

24
25// queryLAPIStatus checks if the Local API is reachable, and if the credentials are correct.
26func queryLAPIStatus(ctx context.Context, hub *cwhub.Hub, credURL string, login string, password string) (bool, error) {
27 apiURL, err := url.Parse(credURL)
28 if err != nil {
29 return false, err
30 }
31
32 client, err := apiclient.NewDefaultClient(apiURL,
33 LAPIURLPrefix,
34 "",
35 nil)
36 if err != nil {
37 return false, err
38 }
39
40 pw := strfmt.Password(password)
41
42 itemsForAPI := hub.GetInstalledListForAPI()
43
44 t := models.WatcherAuthRequest{
45 MachineID: &login,
46 Password: &pw,
47 Scenarios: itemsForAPI,
48 }
49
50 _, _, err = client.Auth.AuthenticateWatcher(ctx, t)
51 if err != nil {
52 return false, err
53 }
54
55 return true, nil
56}
57
58func (cli *cliLapi) Status(ctx context.Context, out io.Writer, hub *cwhub.Hub) error {
59 cfg := cli.cfg()

Callers 1

StatusMethod · 0.85

Calls 5

NewDefaultClientFunction · 0.92
PasswordMethod · 0.80
AuthenticateWatcherMethod · 0.80
ParseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…