mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
Add agent options on a per-team basis (#696)
Solely API implementation. Does not yet handle returning the options during agent requests.
This commit is contained in:
parent
596e017d44
commit
b2b53ecbbe
4 changed files with 41 additions and 5 deletions
|
|
@ -0,0 +1,26 @@
|
|||
package tables
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
MigrationClient.AddMigration(Up_20210428163822, Down_20210428163822)
|
||||
}
|
||||
|
||||
func Up_20210428163822(tx *sql.Tx) error {
|
||||
sql := `
|
||||
ALTER TABLE teams
|
||||
ADD COLUMN agent_options JSON
|
||||
`
|
||||
if _, err := tx.Exec(sql); err != nil {
|
||||
return errors.Wrap(err, "add column agent_options")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Down_20210428163822(tx *sql.Tx) error {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -14,12 +14,14 @@ func (d *Datastore) NewTeam(team *kolide.Team) (*kolide.Team, error) {
|
|||
query := `
|
||||
INSERT INTO teams (
|
||||
name,
|
||||
agent_options,
|
||||
description
|
||||
) VALUES ( ?, ? )
|
||||
) VALUES ( ?, ?, ? )
|
||||
`
|
||||
result, err := d.db.Exec(
|
||||
query,
|
||||
team.Name,
|
||||
team.AgentOptions,
|
||||
team.Description,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
@ -128,10 +130,11 @@ func (d *Datastore) SaveTeam(team *kolide.Team) (*kolide.Team, error) {
|
|||
query := `
|
||||
UPDATE teams SET
|
||||
name = ?,
|
||||
agent_options = ?,
|
||||
description = ?
|
||||
WHERE id = ?
|
||||
`
|
||||
_, err := d.db.Exec(query, team.Name, team.Description, team.ID)
|
||||
_, err := d.db.Exec(query, team.Name, team.AgentOptions, team.Description, team.ID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "saving team")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package kolide
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -40,8 +41,9 @@ type TeamService interface {
|
|||
}
|
||||
|
||||
type TeamPayload struct {
|
||||
Name *string `json:"name"`
|
||||
Description *string `json:"description"`
|
||||
Name *string `json:"name"`
|
||||
Description *string `json:"description"`
|
||||
AgentOptions *json.RawMessage `json:"agent_options"`
|
||||
}
|
||||
|
||||
// Team is the data representation for the "Team" concept (group of hosts and
|
||||
|
|
@ -57,6 +59,8 @@ type Team struct {
|
|||
Name string `json:"name" db:"name"`
|
||||
// Description is an optional description for the team.
|
||||
Description string `json:"description" db:"description"`
|
||||
// AgentOptions is the options for osquery and Orbit.
|
||||
AgentOptions *json.RawMessage `json:"agent_options" db:"agent_options"`
|
||||
|
||||
// Derived from JOINs
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
func (svc service) NewTeam(ctx context.Context, p kolide.TeamPayload) (*kolide.Team, error) {
|
||||
team := &kolide.Team{}
|
||||
team := &kolide.Team{AgentOptions: p.AgentOptions}
|
||||
|
||||
if p.Name == nil {
|
||||
return nil, newInvalidArgumentError("name", "missing required argument")
|
||||
|
|
@ -43,6 +43,9 @@ func (svc service) ModifyTeam(ctx context.Context, id uint, payload kolide.TeamP
|
|||
if payload.Description != nil {
|
||||
team.Description = *payload.Description
|
||||
}
|
||||
if payload.AgentOptions != nil {
|
||||
team.AgentOptions = payload.AgentOptions
|
||||
}
|
||||
|
||||
return svc.ds.SaveTeam(team)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue