Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions backend/.credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
{Credo.Check.Design.AliasUsage, [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
Expand Down
2 changes: 1 addition & 1 deletion backend/.formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
:skogsra,
:nimble_parsec
],
plugins: [Spark.Formatter],
plugins: [Spark.Formatter, Styler],
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"],
locals_without_parens: [
Expand Down
3 changes: 1 addition & 2 deletions backend/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ config :azurex, Azurex.Blob.Config,
api_url: "http://localhost:10000/devstoreaccount1",
default_container: "edgehog",
storage_account_name: "devstoreaccount1",
storage_account_key:
"Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
storage_account_key: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="

# Configure your database
config :edgehog, Edgehog.Repo,
Expand Down
3 changes: 1 addition & 2 deletions backend/lib/edgehog/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ defmodule Edgehog.Application do
# Start the Campaigns supervisor
Edgehog.Campaigns.Supervisor,
# Start the Tenant Reconciler Supervisor
{Edgehog.Tenants.Reconciler.Supervisor,
tenant_to_trigger_url_fun: tenant_to_trigger_url_fun},
{Edgehog.Tenants.Reconciler.Supervisor, tenant_to_trigger_url_fun: tenant_to_trigger_url_fun},
# Start Containers reconciler
{Registry, keys: :unique, name: Edgehog.Containers.Reconciler.Registry},
# Start the Endpoint (http/https)
Expand Down
4 changes: 2 additions & 2 deletions backend/lib/edgehog/astarte/cluster/validations/url.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ defmodule Edgehog.Astarte.Cluster.Validations.URL do
end
end

@impl Ash.Resource.Validation
@impl Validation
def batch_callbacks?(_changeset, _opts, _context), do: false

@impl Ash.Resource.Validation
@impl Validation
def has_batch_validate?, do: false
end
4 changes: 1 addition & 3 deletions backend/lib/edgehog/astarte/device/cellular_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ defmodule Edgehog.Astarte.Device.CellularConnection do
# type Object Aggregate.
# For details, see https://github.com/astarte-platform/astarte/issues/630
with {:ok, %{"data" => data}} <-
AppEngine.Devices.get_datastream_data(client, device_id, @status_interface,
query: [limit: 1]
) do
AppEngine.Devices.get_datastream_data(client, device_id, @status_interface, query: [limit: 1]) do
modems = parse_status_data(data)

{:ok, modems}
Expand Down
3 changes: 1 addition & 2 deletions backend/lib/edgehog/astarte/device/forwarder_session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ defmodule Edgehog.Astarte.Device.ForwarderSession do
forwarder_port,
forwarder_secure_sessions?
)
when is_binary(session_token) and is_binary(forwarder_hostname) and
is_integer(forwarder_port) and
when is_binary(session_token) and is_binary(forwarder_hostname) and is_integer(forwarder_port) and
is_boolean(forwarder_secure_sessions?) do
data = %{
session_token: session_token,
Expand Down
4 changes: 1 addition & 3 deletions backend/lib/edgehog/astarte/device/wifi_scan_result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ defmodule Edgehog.Astarte.Device.WiFiScanResult do

def get(%AppEngine{} = client, device_id) do
with {:ok, %{"data" => data}} <-
AppEngine.Devices.get_datastream_data(client, device_id, @interface,
query: [limit: 1000]
) do
AppEngine.Devices.get_datastream_data(client, device_id, @interface, query: [limit: 1000]) do
wifi_scan_results =
data
|> Map.get("ap", [])
Expand Down
18 changes: 6 additions & 12 deletions backend/lib/edgehog/base_images/base_image/base_image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,10 @@ defmodule Edgehog.BaseImages.BaseImage do
change Changes.HandleFileUpload
change manage_relationship(:base_image_collection_id, :base_image_collection, type: :append)

change {UpsertLocalizedAttribute,
input_argument: :localized_descriptions, target_attribute: :description}
change {UpsertLocalizedAttribute, input_argument: :localized_descriptions, target_attribute: :description}

change {UpsertLocalizedAttribute,
input_argument: :localized_release_display_names,
target_attribute: :release_display_name}
input_argument: :localized_release_display_names, target_attribute: :release_display_name}
end

create :create_fixture do
Expand All @@ -106,12 +104,10 @@ defmodule Edgehog.BaseImages.BaseImage do

change manage_relationship(:base_image_collection_id, :base_image_collection, type: :append)

change {UpsertLocalizedAttribute,
input_argument: :localized_descriptions, target_attribute: :description}
change {UpsertLocalizedAttribute, input_argument: :localized_descriptions, target_attribute: :description}

change {UpsertLocalizedAttribute,
input_argument: :localized_release_display_names,
target_attribute: :release_display_name}
input_argument: :localized_release_display_names, target_attribute: :release_display_name}
end

update :update do
Expand All @@ -132,12 +128,10 @@ defmodule Edgehog.BaseImages.BaseImage do

accept [:starting_version_requirement]

change {UpsertLocalizedAttribute,
input_argument: :localized_descriptions, target_attribute: :description}
change {UpsertLocalizedAttribute, input_argument: :localized_descriptions, target_attribute: :description}

change {UpsertLocalizedAttribute,
input_argument: :localized_release_display_names,
target_attribute: :release_display_name}
input_argument: :localized_release_display_names, target_attribute: :release_display_name}
end

destroy :destroy do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ defmodule Edgehog.BaseImages.BaseImage.Validations.BaseImageNotInUse do
@moduledoc false
use Ash.Resource.Validation

alias Ash.Resource.Validation
alias Edgehog.Campaigns.Campaign

require Ash.Query

@impl Ash.Resource.Validation
@impl Validation
def validate(changeset, _opts, %{tenant: tenant}) do
resource = changeset.data

Expand Down Expand Up @@ -52,15 +53,13 @@ defmodule Edgehog.BaseImages.BaseImage.Validations.BaseImageNotInUse do
campaign_names = Enum.map_join(campaigns, ", ", & &1.name)

{:error,
field: :id,
message:
"Base image is currently in use by the following running campaigns: #{campaign_names}"}
field: :id, message: "Base image is currently in use by the following running campaigns: #{campaign_names}"}
end
end

@impl Ash.Resource.Validation
@impl Validation
def batch_callbacks?(_changeset, _opts, _context), do: false

@impl Ash.Resource.Validation
@impl Validation
def has_batch_validate?, do: false
end
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ defmodule Edgehog.Campaigns.Campaign.Changes.ComputeCampaignTargets do
end
end

defp resolve_target_devices(changeset, action, mechanism, tenant)
when action in @deployment_mechanisms do
defp resolve_target_devices(changeset, action, mechanism, tenant) when action in @deployment_mechanisms do
with {:ok, release} <- fetch_release(changeset, mechanism, tenant),
{:ok, channel} <- fetch_channel(changeset, tenant) do
devices =
Expand Down Expand Up @@ -111,16 +110,14 @@ defmodule Edgehog.Campaigns.Campaign.Changes.ComputeCampaignTargets do
defp fetch_base_image(changeset, campaign_mechanism, tenant) do
with {:error, _reason} <-
Ash.get(BaseImage, campaign_mechanism.base_image_id, tenant: tenant) do
{:error,
Ash.Changeset.add_error(changeset, field: :base_image_id, message: "could not be found")}
{:error, Ash.Changeset.add_error(changeset, field: :base_image_id, message: "could not be found")}
end
end

defp fetch_release(changeset, campaign_mechanism, tenant) do
with {:error, _reason} <-
Ash.get(Release, campaign_mechanism.release_id, tenant: tenant) do
{:error,
Ash.Changeset.add_error(changeset, field: :release_id, message: "could not be found")}
{:error, Ash.Changeset.add_error(changeset, field: :release_id, message: "could not be found")}
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ defmodule Edgehog.Campaigns.Campaign.Validations.RequireCampaignMechanism do
use Ash.Resource.Validation

alias Ash.Error.Changes
alias Ash.Resource.Validation

@impl Ash.Resource.Validation
@impl Validation
def validate(changeset, _opts, _context) do
case Ash.Changeset.get_attribute(changeset, :campaign_mechanism) do
%{type: _, value: _} ->
Expand All @@ -40,9 +41,9 @@ defmodule Edgehog.Campaigns.Campaign.Validations.RequireCampaignMechanism do
end
end

@impl Ash.Resource.Validation
@impl Validation
def batch_callbacks?(_changeset, _opts, _context), do: false

@impl Ash.Resource.Validation
@impl Validation
def has_batch_validate?, do: false
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ defmodule Edgehog.Campaigns.Campaign.Validations.ValidateOperationTypeRequiremen
"""
use Ash.Resource.Validation

alias Ash.Resource.Validation
alias Edgehog.Containers.Release

@impl Ash.Resource.Validation
@impl Validation
def validate(changeset, _opts, context) do
%{type: campaign_type, value: campaign_mechanism} =
Ash.Changeset.get_attribute(changeset, :campaign_mechanism)
Expand All @@ -59,10 +60,10 @@ defmodule Edgehog.Campaigns.Campaign.Validations.ValidateOperationTypeRequiremen
end
end

@impl Ash.Resource.Validation
@impl Validation
def batch_callbacks?(_changeset, _opts, _context), do: false

@impl Ash.Resource.Validation
@impl Validation
def has_batch_validate?, do: false

defp validate_upgrade_requirements(campaign_mechanism, %{tenant: tenant}) do
Expand All @@ -89,8 +90,7 @@ defmodule Edgehog.Campaigns.Campaign.Validations.ValidateOperationTypeRequiremen
if current_release.application_id == target_release.application_id do
:ok
else
{:error,
field: :target_release_id, message: "must belong to the same application as the release"}
{:error, field: :target_release_id, message: "must belong to the same application as the release"}
end
end

Expand All @@ -100,9 +100,7 @@ defmodule Edgehog.Campaigns.Campaign.Validations.ValidateOperationTypeRequiremen
if Version.compare(target_version, current_version) == :gt do
:ok
else
{:error,
field: :target_release_id,
message: "must be a newer release than the currently installed version"}
{:error, field: :target_release_id, message: "must be a newer release than the currently installed version"}
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ defmodule Edgehog.Campaigns.Campaign.Validations.ValidateStatus do
use Ash.Resource.Validation

alias Ash.Error.Changes
alias Ash.Resource.Validation

@impl Ash.Resource.Validation
@impl Validation
def validate(changeset, opts, _context) do
operation = Keyword.fetch!(opts, :operation)
status = Ash.Changeset.get_attribute(changeset, :status)

validate_transition(status, operation)
end

@impl Ash.Resource.Validation
@impl Validation
def batch_callbacks?(_changeset, _opts, _context), do: false

@impl Ash.Resource.Validation
@impl Validation
def has_batch_validate?, do: false

defp validate_transition(status, :pause) do
Expand All @@ -52,8 +53,7 @@ defmodule Edgehog.Campaigns.Campaign.Validations.ValidateStatus do
{:error,
Changes.InvalidAttribute.exception(
field: :status,
message:
"Cannot pause campaign. Campaign must be in progress (current status: #{status})"
message: "Cannot pause campaign. Campaign must be in progress (current status: #{status})"
)}
end
end
Expand Down
6 changes: 2 additions & 4 deletions backend/lib/edgehog/campaigns/campaign_mechanism/core.ex
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,12 @@ defimpl Edgehog.Campaigns.CampaignMechanism.Core, for: Any do
"Failed to contact Astarte API for device #{device_id}"
end

def error_message(_mechanism, %APIError{status: status} = error, device_id)
when status in 400..499 do
def error_message(_mechanism, %APIError{status: status} = error, device_id) when status in 400..499 do
# Client error, assume it's always going to fail
"Device #{device_id} failed Astarte API call: received status #{status} (#{error.response})"
end

def error_message(_mechanism, %APIError{status: status} = error, device_id)
when status in 500..599 do
def error_message(_mechanism, %APIError{status: status} = error, device_id) when status in 500..599 do
# Server error, assume temporary error
"Device #{device_id} failed Astarte API call: received status #{status} (#{error.response})"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ defimpl Edgehog.Campaigns.CampaignMechanism.Core,
end
end

defp maybe_delete(%Deployment{state: :starting}, _updated_target),
do: {:error, :deployment_starting}
defp maybe_delete(%Deployment{state: :starting}, _updated_target), do: {:error, :deployment_starting}

defp maybe_delete(%Deployment{state: :stopping}, _updated_target),
do: {:error, :deployment_stopping}
defp maybe_delete(%Deployment{state: :stopping}, _updated_target), do: {:error, :deployment_stopping}

defp maybe_delete(deployment, updated_target) do
deployment_result =
Expand Down Expand Up @@ -250,9 +248,7 @@ defimpl Edgehog.Campaigns.CampaignMechanism.Core,
nil -> "Could not find any error event."
end

Logger.notice(
"Device #{operation.device_id} #{mechanism.type} operation failed: #{latest_error_message}"
)
Logger.notice("Device #{operation.device_id} #{mechanism.type} operation failed: #{latest_error_message}")
end

defp get_latest_error_for_deployment!(tenant_id, deployment_id) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ defimpl Edgehog.Campaigns.CampaignMechanism.Core,
nil -> "Could not find any error event."
end

Logger.notice(
"Device #{operation.device_id} #{mechanism.type} operation failed: #{latest_error_message}"
)
Logger.notice("Device #{operation.device_id} #{mechanism.type} operation failed: #{latest_error_message}")
end

defp get_latest_error_for_deployment!(tenant_id, deployment_id) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,9 @@ defimpl Edgehog.Campaigns.CampaignMechanism.Core,
end
end

defp maybe_start(%Deployment{state: :started}, _updated_target),
do: {:ok, :already_in_desired_state}
defp maybe_start(%Deployment{state: :started}, _updated_target), do: {:ok, :already_in_desired_state}

defp maybe_start(%Deployment{state: :deleting}, _updated_target),
do: {:ok, :deployment_deleting}
defp maybe_start(%Deployment{state: :deleting}, _updated_target), do: {:ok, :deployment_deleting}

defp maybe_start(deployment, updated_target) do
deployment_result =
Expand Down Expand Up @@ -251,9 +249,7 @@ defimpl Edgehog.Campaigns.CampaignMechanism.Core,
nil -> "Could not find any error event."
end

Logger.notice(
"Device #{operation.device_id} #{mechanism.type} operation failed: #{latest_error_message}"
)
Logger.notice("Device #{operation.device_id} #{mechanism.type} operation failed: #{latest_error_message}")
end

defp get_latest_error_for_deployment!(tenant_id, deployment_id) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ defimpl Edgehog.Campaigns.CampaignMechanism.Core,
end
end

defp maybe_stop(%Deployment{state: :stopped}, _updated_target),
do: {:ok, :already_in_desired_state}
defp maybe_stop(%Deployment{state: :stopped}, _updated_target), do: {:ok, :already_in_desired_state}

defp maybe_stop(%Deployment{state: :deleting}, _updated_target), do: {:ok, :deployment_deleting}

Expand Down Expand Up @@ -250,9 +249,7 @@ defimpl Edgehog.Campaigns.CampaignMechanism.Core,
nil -> "Could not find any error event."
end

Logger.notice(
"Device #{operation.device_id} #{mechanism.type} operation failed: #{latest_error_message}"
)
Logger.notice("Device #{operation.device_id} #{mechanism.type} operation failed: #{latest_error_message}")
end

defp get_latest_error_for_deployment!(tenant_id, deployment_id) do
Expand Down
Loading
Loading