Add All Linux label (#1582)
* Add All Linux label * Change name to Linux instead of All Linux to see if e2e likes it better * Revert "Change name to Linux instead of All Linux to see if e2e likes it better" This reverts commit 26b79f214e3b744e73270c544f89bb698575f6ea. * Fix all linux label insert
This commit is contained in:
@@ -0,0 +1 @@
|
||||
* Add a new built in label "All Linux" to target all hosts that run any linux flavor.
|
||||
@@ -855,6 +855,7 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
|
||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
|
||||
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
|
||||
github.com/zwass/kit v0.0.0-20210625184505-ec5b5c5cce9c h1:TWQ2UvXPkhPxI2KmApKBOCaV6yD2N4mlvqFQ/DlPtpQ=
|
||||
github.com/zwass/kit v0.0.0-20210625184505-ec5b5c5cce9c/go.mod h1:OYYulo9tUqRadRLwB0+LE914sa1ui2yL7OrcU3Q/1XY=
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/fleetdm/fleet/v4/server/fleet"
|
||||
)
|
||||
|
||||
func init() {
|
||||
MigrationClient.AddMigration(Up_20210806135609, Down_20210806135609)
|
||||
}
|
||||
|
||||
func Up_20210806135609(tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`
|
||||
INSERT INTO labels (
|
||||
name,
|
||||
description,
|
||||
query,
|
||||
platform,
|
||||
label_type
|
||||
) VALUES (?, ?, ?, ?, ?)`,
|
||||
"All Linux", "All Linux distributions",
|
||||
"SELECT 1 FROM osquery_info WHERE build_platform LIKE '%ubuntu%' OR build_distro LIKE '%centos%';",
|
||||
"",
|
||||
fleet.LabelTypeBuiltIn,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Down_20210806135609(tx *sql.Tx) error {
|
||||
return nil
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/fleetdm/fleet/v4/server/fleet"
|
||||
"github.com/fleetdm/fleet/v4/server/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetLabel(t *testing.T) {
|
||||
@@ -27,3 +28,17 @@ func TestGetLabel(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, label.ID, labelVerify.ID)
|
||||
}
|
||||
|
||||
func TestGetLabels(t *testing.T) {
|
||||
ds := mysql.CreateMySQLDS(t)
|
||||
defer ds.Close()
|
||||
|
||||
require.NoError(t, ds.MigrateTables())
|
||||
require.NoError(t, ds.MigrateData())
|
||||
|
||||
svc := newTestService(ds, nil, nil)
|
||||
|
||||
labels, err := svc.ListLabels(test.UserContext(test.UserAdmin), fleet.ListOptions{Page: 0, PerPage: 1000})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, labels, 7)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user