Skip to content

Commit

Permalink
fleetctl: allow disabling packs via apply
Browse files Browse the repository at this point in the history
* Fixes issue kolide#2240
  • Loading branch information
nyanshak committed Oct 9, 2020
1 parent 8713725 commit 0e47aff
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion cmd/fleetctl/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"

"github.com/ghodss/yaml"
"github.com/kolide/fleet/server/kolide"
Expand Down Expand Up @@ -374,11 +375,12 @@ func getPacksCommand() cli.Command {
pack.Name,
pack.Platform,
pack.Description,
strconv.FormatBool(pack.Disabled),
})
}

table := defaultTable()
table.SetHeader([]string{"name", "platform", "description"})
table.SetHeader([]string{"name", "platform", "description", "disabled"})
table.AppendBulk(data)
table.Render()

Expand Down
1 change: 1 addition & 0 deletions docs/cli/file-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ apiVersion: v1
kind: pack
spec:
name: osquery_monitoring
disabled: false
targets:
labels:
- All Hosts
Expand Down
11 changes: 6 additions & 5 deletions server/datastore/mysql/packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ func applyPackSpec(tx *sqlx.Tx, spec *kolide.PackSpec) error {
}
// Insert/update pack
query := `
INSERT INTO packs (name, description, platform)
VALUES (?, ?, ?)
INSERT INTO packs (name, description, platform, disabled)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
name = VALUES(name),
description = VALUES(description),
platform = VALUES(platform),
disabled = VALUES(disabled),
deleted = false
`
if _, err := tx.Exec(query, spec.Name, spec.Description, spec.Platform); err != nil {
if _, err := tx.Exec(query, spec.Name, spec.Description, spec.Platform, spec.Disabled); err != nil {
return errors.Wrap(err, "insert/update pack")
}

Expand Down Expand Up @@ -107,7 +108,7 @@ func applyPackSpec(tx *sqlx.Tx, spec *kolide.PackSpec) error {
func (d *Datastore) GetPackSpecs() (specs []*kolide.PackSpec, err error) {
err = d.withRetryTxx(func(tx *sqlx.Tx) error {
// Get basic specs
query := "SELECT id, name, description, platform FROM packs"
query := "SELECT id, name, description, platform, disabled FROM packs"
if err := tx.Select(&specs, query); err != nil {
return errors.Wrap(err, "get packs")
}
Expand Down Expand Up @@ -152,7 +153,7 @@ func (d *Datastore) GetPackSpec(name string) (spec *kolide.PackSpec, err error)
err = d.withRetryTxx(func(tx *sqlx.Tx) error {
// Get basic spec
var specs []*kolide.PackSpec
query := "SELECT id, name, description, platform FROM packs WHERE name = ?"
query := "SELECT id, name, description, platform, disabled FROM packs WHERE name = ?"
if err := tx.Select(&specs, query, name); err != nil {
return errors.Wrap(err, "get packs")
}
Expand Down
1 change: 1 addition & 0 deletions server/kolide/packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type PackSpec struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Platform string `json:"platform,omitempty"`
Disabled bool `json:"disabled"`
Targets PackSpecTargets `json:"targets,omitempty"`
Queries []PackSpecQuery `json:"queries,omitempty"`
}
Expand Down

0 comments on commit 0e47aff

Please sign in to comment.