diff --git a/.credo.exs b/.credo.exs index 6d271e1c08..0280c66784 100644 --- a/.credo.exs +++ b/.credo.exs @@ -108,6 +108,7 @@ {Credo.Check.Readability.PreferImplicitTry, []}, {Credo.Check.Readability.RedundantBlankLines, []}, {Credo.Check.Readability.Semicolons, []}, + {Credo.Check.Readability.SinglePipe, []}, {Credo.Check.Readability.SpaceAfterCommas, []}, {Credo.Check.Readability.StringSigils, []}, {Credo.Check.Readability.TrailingBlankLine, []}, @@ -176,7 +177,6 @@ {Credo.Check.Readability.MultiAlias, []}, {Credo.Check.Readability.SeparateAliasRequire, []}, {Credo.Check.Readability.SingleFunctionToBlockPipe, []}, - {Credo.Check.Readability.SinglePipe, []}, {Credo.Check.Readability.Specs, []}, {Credo.Check.Readability.StrictModuleLayout, []}, {Credo.Check.Readability.WithCustomTaggedTuple, []}, diff --git a/lib/trento/application/integration/checks/adapter/runner.ex b/lib/trento/application/integration/checks/adapter/runner.ex index 1f9d5e4404..a1ee35efb9 100644 --- a/lib/trento/application/integration/checks/adapter/runner.ex +++ b/lib/trento/application/integration/checks/adapter/runner.ex @@ -48,7 +48,7 @@ defmodule Trento.Integration.Checks.Runner do end defp build_payload(execution_id, cluster_id, provider, host_settings, selected_checks) do - %{ + Jason.encode!(%{ execution_id: execution_id, cluster_id: cluster_id, provider: provider, @@ -61,8 +61,7 @@ defmodule Trento.Integration.Checks.Runner do user: host.user || host.default_user } end) - } - |> Jason.encode!() + }) end defp runner_url, diff --git a/lib/trento/application/integration/discovery/payloads/cloud_discovery_payload.ex b/lib/trento/application/integration/discovery/payloads/cloud_discovery_payload.ex index 773ae2de4a..f7292bbdad 100644 --- a/lib/trento/application/integration/discovery/payloads/cloud_discovery_payload.ex +++ b/lib/trento/application/integration/discovery/payloads/cloud_discovery_payload.ex @@ -79,10 +79,10 @@ defmodule Trento.Integration.Discovery.CloudDiscoveryPayload do :sku ]) |> cast_embed(:os_profile, - with: fn event, attrs -> event |> cast(attrs, [:admin_username]) end + with: fn event, attrs -> cast(event, attrs, [:admin_username]) end ) |> cast_embed(:storage_profile, - with: fn event, attrs -> event |> cast(attrs, [:data_disks]) end + with: fn event, attrs -> cast(event, attrs, [:data_disks]) end ) end ) diff --git a/lib/trento/application/integration/discovery/payloads/cluster/cluster_discovery_payload.ex b/lib/trento/application/integration/discovery/payloads/cluster/cluster_discovery_payload.ex index b3115d8c0a..672ca729c6 100644 --- a/lib/trento/application/integration/discovery/payloads/cluster/cluster_discovery_payload.ex +++ b/lib/trento/application/integration/discovery/payloads/cluster/cluster_discovery_payload.ex @@ -50,9 +50,9 @@ defmodule Trento.Integration.Discovery.ClusterDiscoveryPayload do end defp enrich_cluster_type(attrs), - do: attrs |> Map.put("cluster_type", parse_cluster_type(attrs)) + do: Map.put(attrs, "cluster_type", parse_cluster_type(attrs)) - defp enrich_cluster_sid(attrs), do: attrs |> Map.put("sid", parse_cluster_sid(attrs)) + defp enrich_cluster_sid(attrs), do: Map.put(attrs, "sid", parse_cluster_sid(attrs)) defp parse_cluster_type(%{"crmmon" => %{"clones" => nil}}), do: :unknown @@ -107,10 +107,10 @@ defmodule Trento.Integration.Discovery.ClusterDiscoveryPayload do end defp maybe_validate_required_fields(cluster, %{"cluster_type" => ClusterType.hana_scale_up()}), - do: cluster |> validate_required(@required_fields_hana) + do: validate_required(cluster, @required_fields_hana) defp maybe_validate_required_fields(cluster, %{"cluster_type" => ClusterType.hana_scale_out()}), - do: cluster |> validate_required(@required_fields_hana) + do: validate_required(cluster, @required_fields_hana) defp maybe_validate_required_fields(cluster, _), do: cluster diff --git a/lib/trento/application/integration/discovery/payloads/cluster/sbd_discovery_payload.ex b/lib/trento/application/integration/discovery/payloads/cluster/sbd_discovery_payload.ex index 88be77f509..93895d5c0b 100644 --- a/lib/trento/application/integration/discovery/payloads/cluster/sbd_discovery_payload.ex +++ b/lib/trento/application/integration/discovery/payloads/cluster/sbd_discovery_payload.ex @@ -32,7 +32,6 @@ defmodule Trento.Integration.Discovery.ClusterDiscoveryPayload.Sbd do end defp transform_nil_lists(%{"devices" => devices} = attrs) do - attrs - |> Map.put("devices", ListHelper.to_list(devices)) + Map.put(attrs, "devices", ListHelper.to_list(devices)) end end diff --git a/lib/trento/application/integration/discovery/payloads/sap_system_discovery_payload.ex b/lib/trento/application/integration/discovery/payloads/sap_system_discovery_payload.ex index 6112752144..cccca5e66a 100644 --- a/lib/trento/application/integration/discovery/payloads/sap_system_discovery_payload.ex +++ b/lib/trento/application/integration/discovery/payloads/sap_system_discovery_payload.ex @@ -31,9 +31,7 @@ defmodule Trento.Integration.Discovery.SapSystemDiscoveryPayload do end def changeset(sap_system, attrs) do - modified_attrs = - attrs - |> databases_to_list + modified_attrs = databases_to_list(attrs) sap_system |> cast(modified_attrs, fields()) @@ -79,9 +77,7 @@ defmodule Trento.Integration.Discovery.SapSystemDiscoveryPayload do end defp maybe_validate_required_fields(changeset, @application_type), - do: - changeset - |> validate_required(@application_required_fields) + do: validate_required(changeset, @application_required_fields) defp maybe_validate_required_fields(changeset, _), do: changeset end @@ -187,8 +183,7 @@ defmodule Trento.Integration.Discovery.SapSystemDiscoveryPayload do end defp find_property(property, %{"Properties" => properties}) do - properties - |> Enum.find_value(fn + Enum.find_value(properties, fn %{"property" => ^property, "value" => value} -> value _ -> nil end) @@ -352,8 +347,7 @@ defmodule Trento.Integration.Discovery.SapSystemDiscoveryPayload do end defp maybe_validate_replication_mode(changeset, local_site_id) do - changeset - |> validate_required([:"site/#{local_site_id}/REPLICATION_MODE"]) + validate_required(changeset, [:"site/#{local_site_id}/REPLICATION_MODE"]) end end end diff --git a/lib/trento/application/integration/discovery/policies/cluster_policy.ex b/lib/trento/application/integration/discovery/policies/cluster_policy.ex index 470209ed4b..1c2693fb59 100644 --- a/lib/trento/application/integration/discovery/policies/cluster_policy.ex +++ b/lib/trento/application/integration/discovery/policies/cluster_policy.ex @@ -105,8 +105,7 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do }, sid ) do - nodes - |> Enum.map(fn %{name: name, attributes: attributes} -> + Enum.map(nodes, fn %{name: name, attributes: attributes} -> attributes = Enum.reduce(attributes, %{}, fn %{name: name, value: value}, acc -> Map.put(acc, name, value) @@ -183,8 +182,7 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do end defp parse_cluster_fencing_type(%{resources: resources}) do - resources - |> Enum.find_value("", fn + Enum.find_value(resources, "", fn %{agent: "stonith:" <> fencing_type} -> fencing_type @@ -209,8 +207,7 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do end defp parse_sbd_devices(%{devices: devices}) do - devices - |> Enum.map(fn %{device: device, status: status} -> + Enum.map(devices, fn %{device: device, status: status} -> %{ device: device, status: status @@ -244,8 +241,8 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do groups: groups, clones: clones }) do - primitives - |> Enum.concat( + Enum.concat( + primitives, Enum.flat_map(clones, &Map.get(&1, :primitives, [])) ++ Enum.flat_map(groups, &Map.get(&1, :primitives, [])) ) @@ -255,8 +252,7 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do virtual_ip_type_suffix = get_virtual_ip_type_suffix_by_provider(provider) virtual_ip_resource_id = - node_resources - |> Enum.find_value(nil, fn %{type: virtual_ip_type, id: id} -> + Enum.find_value(node_resources, nil, fn %{type: virtual_ip_type, id: id} -> if String.ends_with?(virtual_ip_type, virtual_ip_type_suffix), do: id end) @@ -304,8 +300,8 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do groups: groups, clones: clones }) do - resources - |> Enum.concat( + Enum.concat( + resources, Enum.flat_map(clones, &Map.get(&1, :resources, [])) ++ Enum.flat_map(groups, &Map.get(&1, :resources, [])) ) diff --git a/lib/trento/application/integration/discovery/policies/sap_system_policy.ex b/lib/trento/application/integration/discovery/policies/sap_system_policy.ex index ccf7027b91..eacd3fce4f 100644 --- a/lib/trento/application/integration/discovery/policies/sap_system_policy.ex +++ b/lib/trento/application/integration/discovery/policies/sap_system_policy.ex @@ -118,8 +118,7 @@ defmodule Trento.Integration.Discovery.SapSystemPolicy do defp parse_sap_control_property(property, %Instance{ SAPControl: %SapControl{Properties: properties} }) do - properties - |> Enum.find_value(fn + Enum.find_value(properties, fn %{property: ^property, value: value} -> value _ -> nil end) @@ -129,8 +128,7 @@ defmodule Trento.Integration.Discovery.SapSystemPolicy do %Instance{SAPControl: %SapControl{Instances: instances}}, key ) do - instances - |> Enum.find_value(fn + Enum.find_value(instances, fn %{current_instance: true} = current_instance -> Map.get(current_instance, key) _ -> nil end) diff --git a/lib/trento/application/integration/grafana/grafana.ex b/lib/trento/application/integration/grafana/grafana.ex index df6090810c..711d5d3a70 100644 --- a/lib/trento/application/integration/grafana/grafana.ex +++ b/lib/trento/application/integration/grafana/grafana.ex @@ -11,8 +11,7 @@ defmodule Trento.Integration.Grafana do def init_dashboards do dashboards = Application.fetch_env!(:trento, :grafana)[:dashboards] - dashboards - |> Enum.reduce_while(:ok, fn dashboard_name, _ -> + Enum.reduce_while(dashboards, :ok, fn dashboard_name, _ -> case init_dashboard(dashboard_name) do :ok -> {:cont, :ok} diff --git a/lib/trento/application/projectors/check_result_projector.ex b/lib/trento/application/projectors/check_result_projector.ex index da997143a0..e78c8bf619 100644 --- a/lib/trento/application/projectors/check_result_projector.ex +++ b/lib/trento/application/projectors/check_result_projector.ex @@ -95,8 +95,10 @@ defmodule Trento.CheckResultProjector do }, fn multi -> hosts_executions_changeset = - %HostChecksExecutionsReadModel{cluster_id: cluster_id, host_id: host_id} - |> HostChecksExecutionsReadModel.changeset(%{reachable: reachable, msg: msg}) + HostChecksExecutionsReadModel.changeset( + %HostChecksExecutionsReadModel{cluster_id: cluster_id, host_id: host_id}, + %{reachable: reachable, msg: msg} + ) multi = Ecto.Multi.update(multi, :hosts_executions, hosts_executions_changeset) diff --git a/lib/trento/application/projectors/cluster_projector.ex b/lib/trento/application/projectors/cluster_projector.ex index 4e344a5411..63c4cb62c2 100644 --- a/lib/trento/application/projectors/cluster_projector.ex +++ b/lib/trento/application/projectors/cluster_projector.ex @@ -40,8 +40,7 @@ defmodule Trento.ClusterProjector do }, fn multi -> changeset = - %ClusterReadModel{} - |> ClusterReadModel.changeset(%{ + ClusterReadModel.changeset(%ClusterReadModel{}, %{ id: id, name: name, sid: sid, @@ -64,8 +63,7 @@ defmodule Trento.ClusterProjector do }, fn multi -> changeset = - %ClusterReadModel{id: id} - |> ClusterReadModel.changeset(%{ + ClusterReadModel.changeset(%ClusterReadModel{id: id}, %{ checks_execution: :requested }) @@ -79,8 +77,7 @@ defmodule Trento.ClusterProjector do }, fn multi -> changeset = - %ClusterReadModel{id: id} - |> ClusterReadModel.changeset(%{ + ClusterReadModel.changeset(%ClusterReadModel{id: id}, %{ checks_execution: :running }) @@ -94,8 +91,7 @@ defmodule Trento.ClusterProjector do }, fn multi -> changeset = - %ClusterReadModel{id: id} - |> ClusterReadModel.changeset(%{ + ClusterReadModel.changeset(%ClusterReadModel{id: id}, %{ checks_execution: :not_running }) @@ -116,8 +112,7 @@ defmodule Trento.ClusterProjector do }, fn multi -> changeset = - %ClusterReadModel{id: id} - |> ClusterReadModel.changeset(%{ + ClusterReadModel.changeset(%ClusterReadModel{id: id}, %{ name: name, sid: sid, provider: provider, @@ -152,9 +147,7 @@ defmodule Trento.ClusterProjector do ) project(%ClusterHealthChanged{cluster_id: cluster_id, health: health}, fn multi -> - changeset = - %ClusterReadModel{id: cluster_id} - |> ClusterReadModel.changeset(%{health: health}) + changeset = ClusterReadModel.changeset(%ClusterReadModel{id: cluster_id}, %{health: health}) Ecto.Multi.update(multi, :cluster, changeset) end) diff --git a/lib/trento/application/projectors/database_projector.ex b/lib/trento/application/projectors/database_projector.ex index a4e63584ff..d013ed7dc5 100644 --- a/lib/trento/application/projectors/database_projector.ex +++ b/lib/trento/application/projectors/database_projector.ex @@ -29,8 +29,11 @@ defmodule Trento.DatabaseProjector do %DatabaseRegistered{sap_system_id: sap_system_id, sid: sid, health: health}, fn multi -> changeset = - %DatabaseReadModel{} - |> DatabaseReadModel.changeset(%{id: sap_system_id, sid: sid, health: health}) + DatabaseReadModel.changeset(%DatabaseReadModel{}, %{ + id: sap_system_id, + sid: sid, + health: health + }) Ecto.Multi.insert(multi, :database, changeset) end @@ -43,8 +46,7 @@ defmodule Trento.DatabaseProjector do }, fn multi -> changeset = - %DatabaseReadModel{id: sap_system_id} - |> DatabaseReadModel.changeset(%{health: health}) + DatabaseReadModel.changeset(%DatabaseReadModel{id: sap_system_id}, %{health: health}) Ecto.Multi.update(multi, :database, changeset) end @@ -68,8 +70,7 @@ defmodule Trento.DatabaseProjector do }, fn multi -> database_instance_changeset = - %DatabaseInstanceReadModel{} - |> DatabaseInstanceReadModel.changeset(%{ + DatabaseInstanceReadModel.changeset(%DatabaseInstanceReadModel{}, %{ sap_system_id: sap_system_id, sid: sid, instance_number: instance_number, @@ -98,12 +99,14 @@ defmodule Trento.DatabaseProjector do }, fn multi -> changeset = - %DatabaseInstanceReadModel{ - sap_system_id: sap_system_id, - host_id: host_id, - instance_number: instance_number - } - |> DatabaseInstanceReadModel.changeset(%{health: health}) + DatabaseInstanceReadModel.changeset( + %DatabaseInstanceReadModel{ + sap_system_id: sap_system_id, + host_id: host_id, + instance_number: instance_number + }, + %{health: health} + ) Ecto.Multi.update(multi, :database_instance, changeset) end @@ -119,15 +122,17 @@ defmodule Trento.DatabaseProjector do }, fn multi -> changeset = - %DatabaseInstanceReadModel{ - sap_system_id: sap_system_id, - host_id: host_id, - instance_number: instance_number - } - |> DatabaseInstanceReadModel.changeset(%{ - system_replication: system_replication, - system_replication_status: system_replication_status - }) + DatabaseInstanceReadModel.changeset( + %DatabaseInstanceReadModel{ + sap_system_id: sap_system_id, + host_id: host_id, + instance_number: instance_number + }, + %{ + system_replication: system_replication, + system_replication_status: system_replication_status + } + ) Ecto.Multi.update(multi, :database_instance, changeset) end diff --git a/lib/trento/application/projectors/host_projector.ex b/lib/trento/application/projectors/host_projector.ex index fd7ea7fd9b..54cad7d668 100644 --- a/lib/trento/application/projectors/host_projector.ex +++ b/lib/trento/application/projectors/host_projector.ex @@ -34,8 +34,7 @@ defmodule Trento.HostProjector do }, fn multi -> changeset = - %HostReadModel{id: id} - |> HostReadModel.changeset(%{ + HostReadModel.changeset(%HostReadModel{id: id}, %{ hostname: hostname, ip_addresses: ip_addresses, ssh_address: ssh_address, @@ -57,8 +56,7 @@ defmodule Trento.HostProjector do }, fn multi -> changeset = - %HostReadModel{id: id} - |> HostReadModel.changeset(%{ + HostReadModel.changeset(%HostReadModel{id: id}, %{ cluster_id: cluster_id }) @@ -79,8 +77,7 @@ defmodule Trento.HostProjector do }, fn multi -> changeset = - %HostReadModel{id: id} - |> HostReadModel.changeset(%{ + HostReadModel.changeset(%HostReadModel{id: id}, %{ hostname: hostname, ip_addresses: ip_addresses, ssh_address: ssh_address, @@ -95,8 +92,7 @@ defmodule Trento.HostProjector do %HeartbeatSucceded{host_id: id}, fn multi -> changeset = - %HostReadModel{id: id} - |> HostReadModel.changeset(%{ + HostReadModel.changeset(%HostReadModel{id: id}, %{ heartbeat: :passing }) @@ -108,8 +104,7 @@ defmodule Trento.HostProjector do %HeartbeatFailed{host_id: id}, fn multi -> changeset = - %HostReadModel{id: id} - |> HostReadModel.changeset(%{ + HostReadModel.changeset(%HostReadModel{id: id}, %{ heartbeat: :critical }) @@ -121,8 +116,7 @@ defmodule Trento.HostProjector do %ProviderUpdated{host_id: id, provider: provider, provider_data: provider_data}, fn multi -> changeset = - %HostReadModel{id: id} - |> HostReadModel.changeset(%{ + HostReadModel.changeset(%HostReadModel{id: id}, %{ provider: provider, provider_data: handle_provider_data(provider_data) }) @@ -132,7 +126,7 @@ defmodule Trento.HostProjector do ) def handle_provider_data(provider_data) when is_map(provider_data) do - provider_data |> Map.from_struct() + Map.from_struct(provider_data) end def handle_provider_data(_), do: nil @@ -150,7 +144,7 @@ defmodule Trento.HostProjector do TrentoWeb.Endpoint.broadcast( "monitoring:hosts", "host_registered", - host |> to_map() + to_map(host) ) end diff --git a/lib/trento/application/projectors/sap_system_projector.ex b/lib/trento/application/projectors/sap_system_projector.ex index e5341274a9..8eb03ca57c 100644 --- a/lib/trento/application/projectors/sap_system_projector.ex +++ b/lib/trento/application/projectors/sap_system_projector.ex @@ -32,8 +32,7 @@ defmodule Trento.SapSystemProjector do }, fn multi -> changeset = - %SapSystemReadModel{} - |> SapSystemReadModel.changeset(%{ + SapSystemReadModel.changeset(%SapSystemReadModel{}, %{ id: sap_system_id, sid: sid, tenant: tenant, @@ -52,8 +51,7 @@ defmodule Trento.SapSystemProjector do }, fn multi -> changeset = - %SapSystemReadModel{id: sap_system_id} - |> SapSystemReadModel.changeset(%{health: health}) + SapSystemReadModel.changeset(%SapSystemReadModel{id: sap_system_id}, %{health: health}) Ecto.Multi.update(multi, :sap_system, changeset) end @@ -74,8 +72,7 @@ defmodule Trento.SapSystemProjector do }, fn multi -> changeset = - %ApplicationInstanceReadModel{} - |> ApplicationInstanceReadModel.changeset(%{ + ApplicationInstanceReadModel.changeset(%ApplicationInstanceReadModel{}, %{ sap_system_id: sap_system_id, sid: sid, instance_number: instance_number, @@ -101,12 +98,14 @@ defmodule Trento.SapSystemProjector do }, fn multi -> changeset = - %ApplicationInstanceReadModel{ - sap_system_id: sap_system_id, - host_id: host_id, - instance_number: instance_number - } - |> ApplicationInstanceReadModel.changeset(%{health: health}) + ApplicationInstanceReadModel.changeset( + %ApplicationInstanceReadModel{ + sap_system_id: sap_system_id, + host_id: host_id, + instance_number: instance_number + }, + %{health: health} + ) Ecto.Multi.update(multi, :application_instance, changeset) end diff --git a/lib/trento/application/projectors/telemetry_projector.ex b/lib/trento/application/projectors/telemetry_projector.ex index e660a3cf0d..52b2684a24 100644 --- a/lib/trento/application/projectors/telemetry_projector.ex +++ b/lib/trento/application/projectors/telemetry_projector.ex @@ -28,16 +28,18 @@ defmodule Trento.TelemetryProjector do }, fn multi -> changeset = - %HostTelemetryReadModel{} - |> HostTelemetryReadModel.changeset(%{ - agent_id: agent_id, - hostname: hostname, - cpu_count: cpu_count, - socket_count: socket_count, - total_memory_mb: total_memory_mb, - sles_version: sles_version, - installation_source: installation_source - }) + HostTelemetryReadModel.changeset( + %HostTelemetryReadModel{}, + %{ + agent_id: agent_id, + hostname: hostname, + cpu_count: cpu_count, + socket_count: socket_count, + total_memory_mb: total_memory_mb, + sles_version: sles_version, + installation_source: installation_source + } + ) Ecto.Multi.insert(multi, :host_telemetry, changeset, on_conflict: :replace_all, @@ -58,8 +60,7 @@ defmodule Trento.TelemetryProjector do }, fn multi -> changeset = - %HostTelemetryReadModel{} - |> HostTelemetryReadModel.changeset(%{ + HostTelemetryReadModel.changeset(%HostTelemetryReadModel{}, %{ agent_id: agent_id, hostname: hostname, cpu_count: cpu_count, @@ -83,8 +84,7 @@ defmodule Trento.TelemetryProjector do }, fn multi -> changeset = - %HostTelemetryReadModel{} - |> HostTelemetryReadModel.changeset(%{ + HostTelemetryReadModel.changeset(%HostTelemetryReadModel{}, %{ agent_id: agent_id, provider: provider }) diff --git a/lib/trento/application/usecases/alerting/alerting.ex b/lib/trento/application/usecases/alerting/alerting.ex index 3b3ab658e7..87928671e5 100644 --- a/lib/trento/application/usecases/alerting/alerting.ex +++ b/lib/trento/application/usecases/alerting/alerting.ex @@ -38,8 +38,7 @@ defmodule Trento.Application.UseCases.Alerting do defp maybe_notify_heartbeat_failed(true, host_id) do %HostReadModel{hostname: hostname} = Trento.Repo.get!(HostReadModel, host_id) - EmailAlert.alert("Host", "hostname", hostname, "heartbeat failed") - |> deliver_notification() + deliver_notification(EmailAlert.alert("Host", "hostname", hostname, "heartbeat failed")) end defp maybe_notify_critical_cluster_health(false, _), do: :ok @@ -47,8 +46,9 @@ defmodule Trento.Application.UseCases.Alerting do defp maybe_notify_critical_cluster_health(true, cluster_id) do %ClusterReadModel{name: name} = Trento.Repo.get!(ClusterReadModel, cluster_id) - EmailAlert.alert("Cluster", "name", name, "health is now in critical state") - |> deliver_notification() + deliver_notification( + EmailAlert.alert("Cluster", "name", name, "health is now in critical state") + ) end defp maybe_notify_critical_database_health(false, _), do: :ok @@ -56,8 +56,9 @@ defmodule Trento.Application.UseCases.Alerting do defp maybe_notify_critical_database_health(true, id) do %DatabaseReadModel{sid: sid} = Trento.Repo.get!(DatabaseReadModel, id) - EmailAlert.alert("Database", "SID", sid, "health is now in critical state") - |> deliver_notification() + deliver_notification( + EmailAlert.alert("Database", "SID", sid, "health is now in critical state") + ) end defp maybe_notify_critical_sap_system_health(false, _), do: :ok @@ -65,8 +66,9 @@ defmodule Trento.Application.UseCases.Alerting do defp maybe_notify_critical_sap_system_health(true, id) do %SapSystemReadModel{sid: sid} = Trento.Repo.get!(SapSystemReadModel, id) - EmailAlert.alert("Sap System", "SID", sid, "health is now in critical state") - |> deliver_notification() + deliver_notification( + EmailAlert.alert("Sap System", "SID", sid, "health is now in critical state") + ) end @spec deliver_notification(Swoosh.Email.t()) :: :ok diff --git a/lib/trento/application/usecases/hosts/heartbeats.ex b/lib/trento/application/usecases/hosts/heartbeats.ex index 6d25af3682..48d2fb2db4 100644 --- a/lib/trento/application/usecases/hosts/heartbeats.ex +++ b/lib/trento/application/usecases/hosts/heartbeats.ex @@ -39,8 +39,7 @@ defmodule Trento.Heartbeats do @spec dispatch_heartbeat_failed_commands :: :ok def dispatch_heartbeat_failed_commands do - get_all_expired_heartbeats() - |> Enum.each(fn %{agent_id: agent_id} -> + Enum.each(get_all_expired_heartbeats(), fn %{agent_id: agent_id} -> dispatch_command(agent_id, :critical) end) end diff --git a/lib/trento/application/usecases/hosts/host_connection_settings.ex b/lib/trento/application/usecases/hosts/host_connection_settings.ex index 365000f22b..f134f548f9 100644 --- a/lib/trento/application/usecases/hosts/host_connection_settings.ex +++ b/lib/trento/application/usecases/hosts/host_connection_settings.ex @@ -14,7 +14,8 @@ defmodule Trento.HostConnectionSettings do @spec changeset(t() | Ecto.Changeset.t(), map) :: Ecto.Changeset.t() def changeset(connection_settings, attrs) do - cast(connection_settings, attrs, [:id, :user]) + connection_settings + |> cast(attrs, [:id, :user]) |> validate_required([:user]) end end diff --git a/lib/trento/application/usecases/sap_systems/health_summary_service.ex b/lib/trento/application/usecases/sap_systems/health_summary_service.ex index 33884a8e64..f28e5a57ed 100644 --- a/lib/trento/application/usecases/sap_systems/health_summary_service.ex +++ b/lib/trento/application/usecases/sap_systems/health_summary_service.ex @@ -42,15 +42,14 @@ defmodule Trento.SapSystems.HealthSummaryService do }) do all_instances = application_instances ++ database_instances - %{ + HealthSummaryDto.new!(%{ id: id, sid: sid, sapsystem_health: health, database_health: compute_database_health(database_instances), clusters_health: compute_clusters_health(all_instances), hosts_health: compute_hosts_health(all_instances) - } - |> HealthSummaryDto.new!() + }) end @spec compute_database_health([DatabaseInstanceReadModel.t()]) :: Health.t() diff --git a/lib/trento/domain/cluster/cluster.ex b/lib/trento/domain/cluster/cluster.ex index 3f27736d68..4e512f1a48 100644 --- a/lib/trento/domain/cluster/cluster.ex +++ b/lib/trento/domain/cluster/cluster.ex @@ -625,8 +625,7 @@ defmodule Trento.Domain.Cluster do cluster_id, hosts_executions ) do - multi - |> Multi.execute(fn _ -> + Multi.execute(multi, fn _ -> %HostChecksExecutionCompleted{ cluster_id: cluster_id, host_id: host_id, @@ -656,8 +655,7 @@ defmodule Trento.Domain.Cluster do cluster_id, _hosts_executions ) do - multi - |> Multi.execute(fn _ -> + Multi.execute(multi, fn _ -> %HostChecksExecutionCompleted{ cluster_id: cluster_id, host_id: host_id, diff --git a/lib/trento/support/mix/tasks/dump_scenario.ex b/lib/trento/support/mix/tasks/dump_scenario.ex index 5cbe4c725f..67247c805c 100644 --- a/lib/trento/support/mix/tasks/dump_scenario.ex +++ b/lib/trento/support/mix/tasks/dump_scenario.ex @@ -54,12 +54,13 @@ defmodule Mix.Tasks.DumpScenario do end defp dump_scenario(scenario_name, path) do - Discovery.get_current_discovery_events() - |> Enum.map(fn %DiscoveryEvent{ - agent_id: agent_id, - discovery_type: discovery_type, - payload: payload - } -> + events = Discovery.get_current_discovery_events() + + Enum.map(events, fn %DiscoveryEvent{ + agent_id: agent_id, + discovery_type: discovery_type, + payload: payload + } -> data = Jason.encode!(%{ agent_id: agent_id, @@ -94,7 +95,6 @@ defmodule Mix.Tasks.DumpScenario do end) |> Jason.encode!(pretty: true) - discarded_events_file - |> File.write!(json_data, [:append]) + File.write!(discarded_events_file, json_data, [:append]) end end diff --git a/lib/trento/support/mix/tasks/helper.ex b/lib/trento/support/mix/tasks/helper.ex index 9e1905deb6..001784a1b4 100644 --- a/lib/trento/support/mix/tasks/helper.ex +++ b/lib/trento/support/mix/tasks/helper.ex @@ -4,8 +4,7 @@ defmodule Trento.Tasks.Helper do """ def start_repo do - [:postgrex, :ecto] - |> Enum.each(&Application.ensure_all_started/1) + Enum.each([:postgrex, :ecto], &Application.ensure_all_started/1) Trento.Repo.start_link() end diff --git a/lib/trento_web/controllers/catalog_controller.ex b/lib/trento_web/controllers/catalog_controller.ex index 3f93537cb9..d32e010b17 100644 --- a/lib/trento_web/controllers/catalog_controller.ex +++ b/lib/trento_web/controllers/catalog_controller.ex @@ -72,8 +72,7 @@ defmodule TrentoWeb.CatalogController do defp filter_by_provider(catalog, %{"provider" => provider}) do provider = get_provider(provider) - catalog - |> Enum.filter(fn x -> Atom.to_string(x.provider) == provider end) + Enum.filter(catalog, fn x -> Atom.to_string(x.provider) == provider end) end defp filter_by_provider(catalog, _), do: catalog diff --git a/lib/trento_web/controllers/host_controller.ex b/lib/trento_web/controllers/host_controller.ex index 59aa88a947..4fe9f7546a 100644 --- a/lib/trento_web/controllers/host_controller.ex +++ b/lib/trento_web/controllers/host_controller.ex @@ -24,7 +24,7 @@ defmodule TrentoWeb.HostController do @spec list(Plug.Conn.t(), map) :: Plug.Conn.t() def list(conn, _) do # TODO: replace to_map with DTO approach - hosts = Hosts.get_all_hosts() |> StructHelper.to_map() + hosts = StructHelper.to_map(Hosts.get_all_hosts()) json(conn, hosts) end diff --git a/lib/trento_web/controllers/sap_system_controller.ex b/lib/trento_web/controllers/sap_system_controller.ex index b42ee3ae20..86b252a104 100644 --- a/lib/trento_web/controllers/sap_system_controller.ex +++ b/lib/trento_web/controllers/sap_system_controller.ex @@ -20,10 +20,8 @@ defmodule TrentoWeb.SapSystemController do ## TODO Fix sanitization def list(conn, _) do - sap_systems = - SapSystems.get_all_sap_systems() - # TODO: fix me with DTOs - |> StructHelper.to_map() + # TODO: fix me with DTOs + sap_systems = StructHelper.to_map(SapSystems.get_all_sap_systems()) json(conn, sap_systems) end @@ -38,10 +36,8 @@ defmodule TrentoWeb.SapSystemController do ] def list_databases(conn, _) do - databases = - SapSystems.get_all_databases() - # TODO: fix me with DTOs - |> StructHelper.to_map() + # TODO: fix me with DTOs + databases = StructHelper.to_map(SapSystems.get_all_databases()) json(conn, databases) end diff --git a/lib/trento_web/controllers/settings_controller.ex b/lib/trento_web/controllers/settings_controller.ex index 05add15c46..bf656737bc 100644 --- a/lib/trento_web/controllers/settings_controller.ex +++ b/lib/trento_web/controllers/settings_controller.ex @@ -17,8 +17,7 @@ defmodule TrentoWeb.SettingsController do @spec settings(Plug.Conn.t(), any) :: Plug.Conn.t() def settings(conn, _) do - conn - |> json(%{ + json(conn, %{ eula_accepted: Installation.eula_accepted?(), premium_subscription: Installation.premium?() }) @@ -38,6 +37,6 @@ defmodule TrentoWeb.SettingsController do def accept_eula(conn, _) do :ok = Installation.accept_eula() - conn |> json(%{}) + json(conn, %{}) end end diff --git a/lib/trento_web/openapi/api_spec.ex b/lib/trento_web/openapi/api_spec.ex index a28bb993fb..c041b175a9 100644 --- a/lib/trento_web/openapi/api_spec.ex +++ b/lib/trento_web/openapi/api_spec.ex @@ -9,7 +9,7 @@ defmodule TrentoWeb.OpenApi.ApiSpec do @impl OpenApi def spec do - %OpenApi{ + OpenApiSpex.resolve_schema_modules(%OpenApi{ servers: [ # Populate the Server info from a phoenix endpoint Server.from_endpoint(Endpoint) @@ -35,8 +35,6 @@ defmodule TrentoWeb.OpenApi.ApiSpec do description: "Providing access to Trento Platform features" } ] - } - # Discover request/response schemas from path specs - |> OpenApiSpex.resolve_schema_modules() + }) end end diff --git a/test/trento/application/integration/checks/checks_test.exs b/test/trento/application/integration/checks/checks_test.exs index 1e9fb1de35..a7b41169c4 100644 --- a/test/trento/application/integration/checks/checks_test.exs +++ b/test/trento/application/integration/checks/checks_test.exs @@ -57,8 +57,9 @@ defmodule Trento.Integration.ChecksTest do test "should return a flat catalog" do raw_catalog = load_runner_fixture("catalog") - Trento.Integration.Checks.Mock - |> expect(:get_catalog, fn -> FlatCatalogDto.new(%{checks: raw_catalog}) end) + expect(Trento.Integration.Checks.Mock, :get_catalog, fn -> + FlatCatalogDto.new(%{checks: raw_catalog}) + end) flat_catalog = %FlatCatalogDto{ checks: [ @@ -192,8 +193,9 @@ defmodule Trento.Integration.ChecksTest do test "should return a catalog grouped by provider" do raw_catalog = load_runner_fixture("catalog") - Trento.Integration.Checks.Mock - |> expect(:get_catalog, fn -> FlatCatalogDto.new(%{checks: raw_catalog}) end) + expect(Trento.Integration.Checks.Mock, :get_catalog, fn -> + FlatCatalogDto.new(%{checks: raw_catalog}) + end) catalog_by_provider = %CatalogDto{ providers: [ diff --git a/test/trento/application/integration/discovery/discovery_test.exs b/test/trento/application/integration/discovery/discovery_test.exs index 734b4724e6..a89fc79459 100644 --- a/test/trento/application/integration/discovery/discovery_test.exs +++ b/test/trento/application/integration/discovery/discovery_test.exs @@ -120,7 +120,7 @@ defmodule Trento.Integration.DiscoveryTest do {:error, _} = Discovery.handle(event) - discarded_events = DiscardedDiscoveryEvent |> Trento.Repo.all() + discarded_events = Trento.Repo.all(DiscardedDiscoveryEvent) [ %DiscardedDiscoveryEvent{payload: ^event} diff --git a/test/trento/application/usecases/hosts_test.exs b/test/trento/application/usecases/hosts_test.exs index f7f5206782..e03f050ab5 100644 --- a/test/trento/application/usecases/hosts_test.exs +++ b/test/trento/application/usecases/hosts_test.exs @@ -13,13 +13,12 @@ defmodule Trento.HostsTest do describe "SLES Subscriptions" do test "No SLES4SAP Subscriptions detected" do - assert 0 = Repo.all(SlesSubscriptionReadModel) |> length + assert 0 = SlesSubscriptionReadModel |> Repo.all() |> length() assert 0 = Hosts.get_all_sles_subscriptions() end test "Detects the correct number of SLES4SAP Subscriptions" do - 0..5 - |> Enum.map(fn _ -> + Enum.map(0..5, fn _ -> insert(:sles_subscription, identifier: "SLES_SAP") insert(:sles_subscription, identifier: "sle-module-server-applications") end) diff --git a/test/trento_web/controllers/catalog_controller_test.exs b/test/trento_web/controllers/catalog_controller_test.exs index dba425e2a9..f59a82cad0 100644 --- a/test/trento_web/controllers/catalog_controller_test.exs +++ b/test/trento_web/controllers/catalog_controller_test.exs @@ -17,8 +17,9 @@ defmodule TrentoWeb.CatalogControllerTest do test "should return a catalog grouped by providers", %{conn: conn} do raw_catalog = load_runner_fixture("catalog") - Trento.Integration.Checks.Mock - |> expect(:get_catalog, fn -> FlatCatalogDto.new(%{checks: raw_catalog}) end) + expect(Trento.Integration.Checks.Mock, :get_catalog, fn -> + FlatCatalogDto.new(%{checks: raw_catalog}) + end) conn = get(conn, Routes.catalog_path(conn, :checks_catalog)) @@ -180,8 +181,9 @@ defmodule TrentoWeb.CatalogControllerTest do test "should return a filtered flat catalog", %{conn: conn} do raw_catalog = load_runner_fixture("catalog") - Trento.Integration.Checks.Mock - |> expect(:get_catalog, fn -> FlatCatalogDto.new(%{checks: raw_catalog}) end) + expect(Trento.Integration.Checks.Mock, :get_catalog, fn -> + FlatCatalogDto.new(%{checks: raw_catalog}) + end) conn = get(conn, Routes.catalog_path(conn, :checks_catalog), %{ @@ -253,8 +255,9 @@ defmodule TrentoWeb.CatalogControllerTest do test "should return a default flat catalog when unknown provider is used", %{conn: conn} do raw_catalog = load_runner_fixture("catalog") - Trento.Integration.Checks.Mock - |> expect(:get_catalog, fn -> FlatCatalogDto.new(%{checks: raw_catalog}) end) + expect(Trento.Integration.Checks.Mock, :get_catalog, fn -> + FlatCatalogDto.new(%{checks: raw_catalog}) + end) conn = get(conn, Routes.catalog_path(conn, :checks_catalog), %{ @@ -282,8 +285,9 @@ defmodule TrentoWeb.CatalogControllerTest do test "should return a flat catalog", %{conn: conn} do raw_catalog = load_runner_fixture("catalog") - Trento.Integration.Checks.Mock - |> expect(:get_catalog, fn -> FlatCatalogDto.new(%{checks: raw_catalog}) end) + expect(Trento.Integration.Checks.Mock, :get_catalog, fn -> + FlatCatalogDto.new(%{checks: raw_catalog}) + end) conn = get(conn, Routes.catalog_path(conn, :checks_catalog), %{