diff --git a/server/datastore/mysql/migrations/tables/20210428163822_TeamAgentOptions.go b/server/datastore/mysql/migrations/tables/20210428163822_TeamAgentOptions.go new file mode 100644 index 0000000000..39e4a2fce5 --- /dev/null +++ b/server/datastore/mysql/migrations/tables/20210428163822_TeamAgentOptions.go @@ -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 +} diff --git a/server/datastore/mysql/teams.go b/server/datastore/mysql/teams.go index 2d45599be8..dd5134f8b7 100644 --- a/server/datastore/mysql/teams.go +++ b/server/datastore/mysql/teams.go @@ -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") } diff --git a/server/kolide/teams.go b/server/kolide/teams.go index 473a995278..ac7e33ef7e 100644 --- a/server/kolide/teams.go +++ b/server/kolide/teams.go @@ -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 diff --git a/server/service/service_teams.go b/server/service/service_teams.go index e33b70421b..68fb17d70b 100644 --- a/server/service/service_teams.go +++ b/server/service/service_teams.go @@ -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) }