Add label ID to get labels response (#1164)

Fixes #1065
This commit is contained in:
Zach Wasserman 2021-06-22 16:41:25 -07:00 committed by GitHub
parent 5ad1ad1ffd
commit 4800856bf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View file

@ -404,27 +404,27 @@ func setupLabelSpecsTest(t *testing.T, ds fleet.Datastore) []*fleet.LabelSpec {
}
expectedSpecs := []*fleet.LabelSpec{
&fleet.LabelSpec{
{
Name: "foo",
Query: "select * from foo",
Description: "foo description",
Platform: "darwin",
},
&fleet.LabelSpec{
{
Name: "bar",
Query: "select * from bar",
},
&fleet.LabelSpec{
{
Name: "bing",
Query: "select * from bing",
},
&fleet.LabelSpec{
{
Name: "All Hosts",
Query: "SELECT 1",
LabelType: fleet.LabelTypeBuiltIn,
LabelMembershipType: fleet.LabelMembershipTypeManual,
},
&fleet.LabelSpec{
{
Name: "Manual Label",
LabelMembershipType: fleet.LabelMembershipTypeManual,
Hosts: []string{
@ -453,14 +453,14 @@ func testApplyLabelSpecsRoundtrip(t *testing.T, ds fleet.Datastore) {
specs, err := ds.GetLabelSpecs()
require.Nil(t, err)
assert.Equal(t, expectedSpecs, specs)
test.ElementsMatchSkipTimestampsID(t, expectedSpecs, specs)
// Should be idempotent
err = ds.ApplyLabelSpecs(expectedSpecs)
require.Nil(t, err)
specs, err = ds.GetLabelSpecs()
require.Nil(t, err)
assert.Equal(t, expectedSpecs, specs)
test.ElementsMatchSkipTimestampsID(t, expectedSpecs, specs)
}
func testLabelIDsByName(t *testing.T, ds fleet.Datastore) {

View file

@ -113,7 +113,7 @@ func batchHostnames(hostnames []string) [][]string {
func (d *Datastore) GetLabelSpecs() ([]*fleet.LabelSpec, error) {
var specs []*fleet.LabelSpec
// Get basic specs
query := "SELECT name, description, query, platform, label_type, label_membership_type FROM labels"
query := "SELECT id, name, description, query, platform, label_type, label_membership_type FROM labels"
if err := d.db.Select(&specs, query); err != nil {
return nil, errors.Wrap(err, "get labels")
}

View file

@ -190,7 +190,7 @@ type LabelQueryExecution struct {
}
type LabelSpec struct {
ID uint
ID uint `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Query string `json:"query"`