## Overview `dibble` is a one-stop CLI for seeding a Fleet server with test data — users, teams, policies, reports, labels, scripts, MDM profiles, software, secrets, CAs, and vulns — replacing ~8 ad-hoc seeding tools with a single binary. It makes it easy to: - **Spin up a populated dev/test server in one command** — `dibble all` plants everything with sensible, idempotent defaults. - **Skip the flag-memorization** — running `dibble` with no args launches an interactive wizard that prompts for Fleet URL, API token, theme, and which entities to seed, and offers to save the config to `~/.dibble.yaml`. - **Seed individual entity types** — `dibble users`, `dibble teams`, `dibble policies`, etc., when you only need one slice. - **Get themed, recognizable test data** — pick a theme (hitchhikers, tng, lotr, ghibli, parksrec, …) so seeded names are easy to eyeball in the UI. Hosts are intentionally out of scope — `cmd/osquery-perf` still owns that. `dibble hosts` is a thin convenience wrapper that picks a fleet, fetches its enroll secret, and prints/runs the osquery-perf invocation for you. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Dibble: a CLI tool to seed realistic test data, including an interactive wizard and subcommands for teams/users/software/policies/scripts/reports/profiles/labels/activities/enroll-secrets/hosts/vulns, plus theme-driven “cas” and “ping”. * Theme system: multiple curated themes to generate consistent seeded identities, policies, software, labels, and scripts. * **Chores** * Ignored the built dibble binary and added a Makefile build target to compile the dibble tool. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package command
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/fleetdm/fleet/v4/tools/dibble/pkg/seed"
|
|
)
|
|
|
|
func newPoliciesCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "policies",
|
|
Short: "Seed global policies (and a couple per existing team)",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if err := requireConfig(); err != nil {
|
|
return err
|
|
}
|
|
c, err := newClientFromViper()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
theme, err := currentTheme()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
count, _ := cmd.Flags().GetInt("count")
|
|
teams, err := listExistingTeams(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
res := seed.Policies(c, seederLogger{}, theme, teams, count)
|
|
printf("%s", res.Summary())
|
|
return reportErrors(res.Errors)
|
|
},
|
|
}
|
|
cmd.Flags().Int("count", 5, "How many global policies to seed (plus 2 per team)")
|
|
return cmd
|
|
}
|
|
|
|
// listExistingTeams asks Fleet for the team list so subcommands invoked on
|
|
// their own (without prior `dibble teams`) can still scope per-team work.
|
|
func listExistingTeams(c *Client) ([]seed.Team, error) {
|
|
var resp struct {
|
|
Teams []struct {
|
|
ID uint `json:"id"`
|
|
Name string `json:"name"`
|
|
} `json:"teams"`
|
|
Fleets []struct {
|
|
ID uint `json:"id"`
|
|
Name string `json:"name"`
|
|
} `json:"fleets"`
|
|
}
|
|
if err := c.Get("/api/latest/fleet/fleets?per_page=500", &resp); err != nil {
|
|
return nil, err
|
|
}
|
|
out := make([]seed.Team, 0, len(resp.Teams)+len(resp.Fleets))
|
|
for _, t := range resp.Teams {
|
|
out = append(out, seed.Team{ID: t.ID, Name: t.Name})
|
|
}
|
|
for _, t := range resp.Fleets {
|
|
out = append(out, seed.Team{ID: t.ID, Name: t.Name})
|
|
}
|
|
return out, nil
|
|
}
|