fleet/server/service/service_agent_options.go
Zach Wasserman b1a98a6e91
Update agent options storage for teams (#754)
- Allow agent options to be set on per-team basis.
- Move global agent options into app configs.
- Update logic for calculating agent options for hosts.
- Updates to relevant testing.
2021-05-11 18:15:16 -07:00

42 lines
1.1 KiB
Go

package service
import (
"context"
"encoding/json"
"github.com/fleetdm/fleet/server/kolide"
"github.com/pkg/errors"
)
func (svc service) AgentOptionsForHost(ctx context.Context, host *kolide.Host) (json.RawMessage, error) {
// If host has a team and team has non-empty options, prioritize that.
if host.TeamID.Valid {
team, err := svc.ds.Team(uint(host.TeamID.Int64))
if err != nil {
return nil, errors.Wrap(err, "load team for host")
}
if team.AgentOptions != nil && len(*team.AgentOptions) > 0 {
var options kolide.AgentOptions
if err := json.Unmarshal(*team.AgentOptions, &options); err != nil {
return nil, errors.Wrap(err, "unmarshal team agent options")
}
return options.ForPlatform(host.Platform), nil
}
}
// Otherwise return the appropriate override for global options.
appConfig, err := svc.ds.AppConfig()
if err != nil {
return nil, errors.Wrap(err, "load global agent options")
}
var options kolide.AgentOptions
if err := json.Unmarshal(appConfig.AgentOptions, &options); err != nil {
return nil, errors.Wrap(err, "unmarshal global agent options")
}
return options.ForPlatform(host.Platform), nil
}