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

Method Status

cmd/crowdsec-cli/clipapi/papi.go:59–98  ·  view source on GitHub ↗
(ctx context.Context, out io.Writer, db *database.Client)

Source from the content-addressed store, hash-verified

57}
58
59func (cli *cliPapi) Status(ctx context.Context, out io.Writer, db *database.Client) error {
60 cfg := cli.cfg()
61
62 apic, err := apiserver.NewAPIC(ctx, cfg.API.Server.OnlineClient, db, cfg.API.Server.ConsoleConfig, cfg.API.Server.CapiWhitelists)
63 if err != nil {
64 return fmt.Errorf("unable to initialize API client: %w", err)
65 }
66
67 papiLogger := cfg.API.Server.NewPAPILogger()
68 papi, err := apiserver.NewPAPI(apic, db, cfg.API.Server.ConsoleConfig, papiLogger)
69 if err != nil {
70 return fmt.Errorf("unable to initialize PAPI client: %w", err)
71 }
72
73 perms, err := papi.GetPermissions(ctx)
74 if err != nil {
75 return fmt.Errorf("unable to get PAPI permissions: %w", err)
76 }
77
78 lastTimestampStr, err := db.GetConfigItem(ctx, apiserver.PapiPullKey)
79 if err != nil {
80 lastTimestampStr = "never"
81 }
82
83 // both can and did happen
84 if lastTimestampStr == "" || lastTimestampStr == "0001-01-01T00:00:00Z" {
85 lastTimestampStr = "never"
86 }
87
88 fmt.Fprint(out, "You can successfully interact with Polling API (PAPI)\n")
89 fmt.Fprintf(out, "Console plan: %s\n", perms.Plan)
90 fmt.Fprintf(out, "Last order received: %s\n", lastTimestampStr)
91 fmt.Fprint(out, "PAPI subscriptions:\n")
92
93 for _, sub := range perms.Categories {
94 fmt.Fprintf(out, " - %s\n", sub)
95 }
96
97 return nil
98}
99
100func (cli *cliPapi) newStatusCmd() *cobra.Command {
101 cmd := &cobra.Command{

Callers 1

newStatusCmdMethod · 0.95

Calls 6

NewAPICFunction · 0.92
NewPAPIFunction · 0.92
cfgMethod · 0.80
NewPAPILoggerMethod · 0.80
GetPermissionsMethod · 0.80
GetConfigItemMethod · 0.80

Tested by

no test coverage detected