Skip to content

Commit

Permalink
Create audit logs when setting deployment (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
nshoes authored Jan 7, 2025
1 parent 87c652d commit 24151c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/nerves_hub/audit_logs/templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,22 @@ defmodule NervesHub.AuditLogs.Templates do
"#{user.name} set #{device.identifier}'s deployment to #{deployment.name}"
)
end

@spec audit_device_deployment_update(Device.t(), Deployment.t(), :one_found | :multiple_found) ::
AuditLog.t()
def audit_set_deployment(device, deployment, :one_found) do
AuditLogs.audit!(
device,
device,
"Updating #{device.identifier}'s deployment to #{deployment.name}"
)
end

def audit_set_deployment(device, deployment, :multiple_found) do
AuditLogs.audit!(
device,
device,
"Multiple matching deployments found, updating #{device.identifier}'s deployment to #{deployment.name}"
)
end
end
5 changes: 5 additions & 0 deletions lib/nerves_hub/deployments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule NervesHub.Deployments do
require Logger

alias NervesHub.AuditLogs
alias NervesHub.AuditLogs.Templates
alias NervesHub.Deployments.Deployment
alias NervesHub.Deployments.InflightDeploymentCheck
alias NervesHub.Devices
Expand Down Expand Up @@ -364,13 +365,17 @@ defmodule NervesHub.Deployments do
[deployment] ->
set_deployment_telemetry(:one_found, device, deployment)

Templates.audit_set_deployment(device, deployment, :one_found)

device
|> Devices.update_deployment(deployment)
|> preload_with_firmware_and_archive(true)

[deployment | _] ->
set_deployment_telemetry(:multiple_found, device, deployment)

Templates.audit_set_deployment(device, deployment, :multiple_found)

device
|> Devices.update_deployment(deployment)
|> preload_with_firmware_and_archive(true)
Expand Down

0 comments on commit 24151c8

Please sign in to comment.