Fixing unreleased spec bug in team host status webhook feature. (#17502)

Fixing unreleased spec bug in team host status webhook feature #17094.
Bug #17498
# Checklist for submitter

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [ ] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
  - Not needed. Part of new feature.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
This commit is contained in:
Victor Lyuboslavsky
2024-03-08 15:09:33 -06:00
committed by GitHub
parent b667227ce3
commit b174a476a2
7 changed files with 20 additions and 22 deletions
+2 -2
View File
@@ -411,7 +411,7 @@ spec:
DestinationURL: "https://example.com",
Enable: true,
HostPercentage: 25,
}, teamsByName["team1"].Config.WebhookSettings.HostStatusWebhook,
}, *teamsByName["team1"].Config.WebhookSettings.HostStatusWebhook,
)
assert.Equal(t, fleet.FailingPoliciesWebhookSettings{}, teamsByName["team1"].Config.WebhookSettings.FailingPoliciesWebhook)
// enroll secret not cleared since not provided
@@ -437,7 +437,7 @@ spec:
DestinationURL: "https://example.com",
Enable: true,
HostPercentage: 25,
}, teamsByName["team1"].Config.WebhookSettings.HostStatusWebhook,
}, *teamsByName["team1"].Config.WebhookSettings.HostStatusWebhook,
)
}
+2 -12
View File
@@ -12,12 +12,7 @@
"host_expiry_window": 0
},
"webhook_settings": {
"host_status_webhook": {
"enable_host_status_webhook": false,
"destination_url": "",
"host_percentage": 0,
"days_count": 0
},
"host_status_webhook": null,
"failing_policies_webhook": {
"enable_failing_policies_webhook": false,
"destination_url": "",
@@ -87,12 +82,7 @@
"host_expiry_window": 15
},
"webhook_settings": {
"host_status_webhook": {
"enable_host_status_webhook": false,
"destination_url": "",
"host_percentage": 0,
"days_count": 0
},
"host_status_webhook": null,
"failing_policies_webhook": {
"enable_failing_policies_webhook": false,
"destination_url": "",
+3 -3
View File
@@ -887,10 +887,10 @@ func (svc *Service) createTeamFromSpec(
hostExpirySettings = *spec.HostExpirySettings
}
hostStatusWebhook := fleet.HostStatusWebhookSettings{}
var hostStatusWebhook *fleet.HostStatusWebhookSettings
if spec.WebhookSettings.HostStatusWebhook != nil {
fleet.ValidateEnabledHostStatusIntegrations(*spec.WebhookSettings.HostStatusWebhook, invalid)
hostStatusWebhook = *spec.WebhookSettings.HostStatusWebhook
hostStatusWebhook = spec.WebhookSettings.HostStatusWebhook
}
if invalid.HasErrors() {
return nil, ctxerr.Wrap(ctx, invalid)
@@ -1066,7 +1066,7 @@ func (svc *Service) editTeamFromSpec(
// If host status webhook is not provided, do not change it
if spec.WebhookSettings.HostStatusWebhook != nil {
fleet.ValidateEnabledHostStatusIntegrations(*spec.WebhookSettings.HostStatusWebhook, invalid)
team.Config.WebhookSettings.HostStatusWebhook = *spec.WebhookSettings.HostStatusWebhook
team.Config.WebhookSettings.HostStatusWebhook = spec.WebhookSettings.HostStatusWebhook
}
if invalid.HasErrors() {
return ctxerr.Wrap(ctx, invalid)
+9 -1
View File
@@ -148,7 +148,8 @@ type TeamConfig struct {
}
type TeamWebhookSettings struct {
HostStatusWebhook HostStatusWebhookSettings `json:"host_status_webhook"`
// HostStatusWebhook can be nil to match the TeamSpec webhook settings
HostStatusWebhook *HostStatusWebhookSettings `json:"host_status_webhook"`
FailingPoliciesWebhook FailingPoliciesWebhookSettings `json:"failing_policies_webhook"`
}
@@ -436,6 +437,12 @@ func TeamSpecFromTeam(t *Team) (*TeamSpec, error) {
mdmSpec.MacOSSetup = t.Config.MDM.MacOSSetup
mdmSpec.EnableDiskEncryption = optjson.SetBool(t.Config.MDM.EnableDiskEncryption)
mdmSpec.WindowsSettings = t.Config.MDM.WindowsSettings
var webhookSettings TeamSpecWebhookSettings
if t.Config.WebhookSettings.HostStatusWebhook != nil {
webhookSettings.HostStatusWebhook = t.Config.WebhookSettings.HostStatusWebhook
}
return &TeamSpec{
Name: t.Name,
AgentOptions: agentOptions,
@@ -443,5 +450,6 @@ func TeamSpecFromTeam(t *Team) (*TeamSpec, error) {
Secrets: secrets,
MDM: mdmSpec,
HostExpirySettings: &t.Config.HostExpirySettings,
WebhookSettings: webhookSettings,
}, nil
}
@@ -1317,7 +1317,7 @@ func (s *integrationEnterpriseTestSuite) TestExternalIntegrationsTeamConfig() {
Enable: true,
DestinationURL: "http://example.com",
},
HostStatusWebhook: fleet.HostStatusWebhookSettings{
HostStatusWebhook: &fleet.HostStatusWebhookSettings{
Enable: true,
DestinationURL: "http://example.com/host_status_webhook",
},
+2 -2
View File
@@ -90,11 +90,11 @@ func triggerTeamHostStatusWebhook(ctx context.Context, ds fleet.Datastore, logge
multiErr = multierror.Append(multiErr, ctxerr.Wrap(ctx, err, "getting team"))
continue
}
if !team.Config.WebhookSettings.HostStatusWebhook.Enable {
if team.Config.WebhookSettings.HostStatusWebhook == nil || !team.Config.WebhookSettings.HostStatusWebhook.Enable {
continue
}
level.Debug(logger).Log("team", id, "enable_host_status_webhook", "true")
err = processWebhook(ctx, ds, &id, team.Config.WebhookSettings.HostStatusWebhook)
err = processWebhook(ctx, ds, &id, *team.Config.WebhookSettings.HostStatusWebhook)
if err != nil {
multiErr = multierror.Append(multiErr, ctxerr.Wrap(ctx, err, "processing webhook"))
}
+1 -1
View File
@@ -125,7 +125,7 @@ func TestTriggerHostStatusWebhookTeam(t *testing.T) {
ID: 1,
Config: fleet.TeamConfig{
WebhookSettings: fleet.TeamWebhookSettings{
HostStatusWebhook: teamSettings,
HostStatusWebhook: &teamSettings,
},
},
}, nil