diff --git a/lib/process/public/view/process.ex b/lib/process/public/view/process.ex index 8c5932a4..e6a3765f 100644 --- a/lib/process/public/view/process.ex +++ b/lib/process/public/view/process.ex @@ -19,7 +19,7 @@ defmodule Helix.Process.Public.View.Process do :full | :partial - @typep process(access_type) :: + @typep process(access) :: %{ process_id: String.t, target_ip: String.t, @@ -28,7 +28,7 @@ defmodule Helix.Process.Public.View.Process do file: file, state: String.t, type: String.t, - access: access_type + access: access } @typep full_access :: diff --git a/lib/server/event/motherboard.ex b/lib/server/event/motherboard.ex index 56f415cb..b10c11c7 100644 --- a/lib/server/event/motherboard.ex +++ b/lib/server/event/motherboard.ex @@ -27,13 +27,13 @@ defmodule Helix.Server.Event.Motherboard do @event :motherboard_updated - def generate_payload(event, %{assigns: %{meta: %{access_type: :local}}}) do + def generate_payload(event, %{assigns: %{meta: %{access: :local}}}) do data = HardwareIndex.render_index(event.index_cache) {:ok, data} end - def generate_payload(event, %{assigns: %{meta: %{access_type: :remote}}}) do + def generate_payload(event, %{assigns: %{meta: %{access: :remote}}}) do data = event.index_cache |> HardwareIndex.render_index() @@ -75,7 +75,7 @@ defmodule Helix.Server.Event.Motherboard do @event :motherboard_update_failed - def generate_payload(event, %{assigns: %{meta: %{access_type: :local}}}) do + def generate_payload(event, %{assigns: %{meta: %{access: :local}}}) do data = %{reason: event.reason} {:ok, data} diff --git a/lib/server/public/index/hardware.ex b/lib/server/public/index/hardware.ex index 156df3f8..b80b16df 100644 --- a/lib/server/public/index/hardware.ex +++ b/lib/server/public/index/hardware.ex @@ -13,9 +13,9 @@ defmodule Helix.Server.Public.Index.Hardware do motherboard: MotherboardIndex.rendered_index | nil } - @typep access_type :: :local | :remote + @typep access :: :local | :remote - @spec index(Server.t, access_type) :: + @spec index(Server.t, access) :: index def index(server = %Server{}, :local) do %{ diff --git a/lib/server/websocket/channel/server.ex b/lib/server/websocket/channel/server.ex index a60ccfa8..2a410411 100644 --- a/lib/server/websocket/channel/server.ex +++ b/lib/server/websocket/channel/server.ex @@ -326,7 +326,7 @@ channel Helix.Server.Websocket.Channel.Server do ServerWebsocketChannelState. """ def terminate(_reason, socket) do - if socket.assigns.meta.access_type == :remote do + if socket.assigns.meta.access == :remote do entity_id = socket.assigns.gateway.entity_id server_id = socket.assigns.destination.server_id counter = socket.assigns.meta.counter diff --git a/lib/server/websocket/channel/server/join.ex b/lib/server/websocket/channel/server/join.ex index 294bedd9..ee5aaa0b 100644 --- a/lib/server/websocket/channel/server/join.ex +++ b/lib/server/websocket/channel/server/join.ex @@ -40,14 +40,14 @@ join Helix.Server.Websocket.Channel.Server.Join do method. """ def check_params(request = %ServerJoin{type: nil}, socket) do - access_type = + access = if request.unsafe["gateway_ip"] do :remote else :local end - %{request| type: access_type} + %{request| type: access} |> check_params(socket) end @@ -186,13 +186,13 @@ join Helix.Server.Websocket.Channel.Server.Join do defp build_meta(%ServerJoin{type: :local}) do %{ - access_type: :local + access: :local } end defp build_meta(request = %ServerJoin{type: :remote}) do %{ - access_type: :remote, + access: :remote, counter: request.meta.counter, network_id: request.params.network_id } @@ -216,7 +216,7 @@ join Helix.Server.Websocket.Channel.Server.Join do socket = socket - |> assign.(:access_type, :local) + |> assign.(:access, :local) |> assign.(:gateway, gateway_data) |> assign.(:destination, gateway_data) |> assign.(:meta, build_meta(request)) diff --git a/lib/server/websocket/requests/bootstrap.ex b/lib/server/websocket/requests/bootstrap.ex index ff3f65b5..7cf61c71 100644 --- a/lib/server/websocket/requests/bootstrap.ex +++ b/lib/server/websocket/requests/bootstrap.ex @@ -25,7 +25,7 @@ request Helix.Server.Websocket.Requests.Bootstrap do server = ServerQuery.fetch(server_id) bootstrap = - if socket.assigns.meta.access_type == :local do + if socket.assigns.meta.access == :local do ServerPublic.bootstrap_gateway(server, entity_id) else ServerPublic.bootstrap_remote(server, entity_id) @@ -36,7 +36,7 @@ request Helix.Server.Websocket.Requests.Bootstrap do render(request, socket) do data = - if socket.assigns.meta.access_type == :local do + if socket.assigns.meta.access == :local do ServerPublic.render_bootstrap_gateway(request.meta.bootstrap) else ServerPublic.render_bootstrap_remote(request.meta.bootstrap) diff --git a/lib/server/websocket/requests/motherboard_update.ex b/lib/server/websocket/requests/motherboard_update.ex index dec4fcd5..27334387 100644 --- a/lib/server/websocket/requests/motherboard_update.ex +++ b/lib/server/websocket/requests/motherboard_update.ex @@ -22,7 +22,7 @@ request Helix.Server.Websocket.Requests.MotherboardUpdate do def check_detach(request, socket) do with \ - true <- socket.assigns.meta.access_type == :local || :bad_src + true <- socket.assigns.meta.access == :local || :bad_src do update_params(request, %{cmd: :detach}, reply: true) else @@ -36,7 +36,7 @@ request Helix.Server.Websocket.Requests.MotherboardUpdate do def check_update(request, socket) do with \ - true <- socket.assigns.meta.access_type == :local || :bad_src, + true <- socket.assigns.meta.access == :local || :bad_src, {:ok, mobo_id} <- Component.ID.cast(request.unsafe["motherboard_id"]), {:ok, slots} <- cast_slots(request.unsafe["slots"]), {:ok, ncs} <- cast_ncs(request.unsafe["network_connections"]) diff --git a/lib/software/websocket/requests/cracker/bruteforce.ex b/lib/software/websocket/requests/cracker/bruteforce.ex index a5f2f88f..04b4d930 100644 --- a/lib/software/websocket/requests/cracker/bruteforce.ex +++ b/lib/software/websocket/requests/cracker/bruteforce.ex @@ -17,7 +17,7 @@ request Helix.Software.Websocket.Requests.Cracker.Bruteforce do Network.ID.cast(request.unsafe["network_id"]), true <- IPv4.valid?(request.unsafe["ip"]), {:ok, bounces} = cast_bounces(request.unsafe["bounces"]), - true <- socket.assigns.meta.access_type == :local || :bad_attack_src + true <- socket.assigns.meta.access == :local || :bad_attack_src do params = %{ bounces: bounces, diff --git a/lib/software/websocket/requests/file/download.ex b/lib/software/websocket/requests/file/download.ex index 81863047..d4da6c0b 100644 --- a/lib/software/websocket/requests/file/download.ex +++ b/lib/software/websocket/requests/file/download.ex @@ -23,7 +23,7 @@ request Helix.Software.Websocket.Requests.File.Download do end with \ - true <- socket.assigns.meta.access_type == :remote || :bad_access, + true <- socket.assigns.meta.access == :remote || :bad_access, {:ok, file_id} <- File.ID.cast(request.unsafe["file_id"]), {:ok, storage_id} <- Storage.ID.cast(unsafe_storage_id) do diff --git a/lib/software/websocket/requests/pftp/file/add.ex b/lib/software/websocket/requests/pftp/file/add.ex index 8025a083..5efc3375 100644 --- a/lib/software/websocket/requests/pftp/file/add.ex +++ b/lib/software/websocket/requests/pftp/file/add.ex @@ -15,7 +15,7 @@ request Helix.Software.Websocket.Requests.PFTP.File.Add do """ def check_params(request, socket) do with \ - true <- socket.assigns.meta.access_type == :local || :not_local, + true <- socket.assigns.meta.access == :local || :not_local, {:ok, file_id} <- File.ID.cast(request.unsafe["file_id"]) do params = %{ diff --git a/lib/software/websocket/requests/pftp/file/download.ex b/lib/software/websocket/requests/pftp/file/download.ex index eff3801b..b1fc04f1 100644 --- a/lib/software/websocket/requests/pftp/file/download.ex +++ b/lib/software/websocket/requests/pftp/file/download.ex @@ -18,7 +18,7 @@ request Helix.Software.Websocket.Requests.PFTP.File.Download do end with \ - true <- socket.assigns.meta.access_type == :local || :not_local, + true <- socket.assigns.meta.access == :local || :not_local, {:ok, file_id} <- File.ID.cast(request.unsafe["file_id"]), {:ok, network_id, ip} <- validate_nip(request.unsafe["network_id"], request.unsafe["ip"]), diff --git a/lib/software/websocket/requests/pftp/file/remove.ex b/lib/software/websocket/requests/pftp/file/remove.ex index 6cf91629..810dc885 100644 --- a/lib/software/websocket/requests/pftp/file/remove.ex +++ b/lib/software/websocket/requests/pftp/file/remove.ex @@ -16,7 +16,7 @@ request Helix.Software.Websocket.Requests.PFTP.File.Remove do """ def check_params(request, socket) do with \ - true <- socket.assigns.meta.access_type == :local || :not_local, + true <- socket.assigns.meta.access == :local || :not_local, {:ok, file_id} <- File.ID.cast(request.unsafe["file_id"]) do params = %{ diff --git a/lib/software/websocket/requests/pftp/server/disable.ex b/lib/software/websocket/requests/pftp/server/disable.ex index db32c408..070b9eb3 100644 --- a/lib/software/websocket/requests/pftp/server/disable.ex +++ b/lib/software/websocket/requests/pftp/server/disable.ex @@ -14,7 +14,7 @@ request Helix.Software.Websocket.Requests.PFTP.Server.Disable do local socket. """ def check_params(request, socket) do - if socket.assigns.meta.access_type == :local do + if socket.assigns.meta.access == :local do reply_ok(request) else reply_error(request, "pftp_must_be_local") diff --git a/lib/software/websocket/requests/pftp/server/enable.ex b/lib/software/websocket/requests/pftp/server/enable.ex index a0630cb2..5e99cde7 100644 --- a/lib/software/websocket/requests/pftp/server/enable.ex +++ b/lib/software/websocket/requests/pftp/server/enable.ex @@ -14,7 +14,7 @@ request Helix.Software.Websocket.Requests.PFTP.Server.Enable do local socket. """ def check_params(request, socket) do - if socket.assigns.meta.access_type == :local do + if socket.assigns.meta.access == :local do reply_ok(request) else reply_error(request, "pftp_must_be_local") diff --git a/test/server/event/motherboard_test.exs b/test/server/event/motherboard_test.exs index 7ce7222b..75be31fe 100644 --- a/test/server/event/motherboard_test.exs +++ b/test/server/event/motherboard_test.exs @@ -7,8 +7,8 @@ defmodule Helix.Server.Event.MotherboardTest do alias Helix.Test.Channel.Setup, as: ChannelSetup alias Helix.Test.Event.Setup, as: EventSetup - @socket_local ChannelSetup.mock_server_socket(access_type: :local) - @socket_remote ChannelSetup.mock_server_socket(access_type: :remote) + @socket_local ChannelSetup.mock_server_socket(access: :local) + @socket_remote ChannelSetup.mock_server_socket(access: :remote) describe "MotherboardUpdatedEvent.generate_payload/2" do test "generates full hardware index on gateway (local)" do diff --git a/test/server/websocket/channel/server/join_test.exs b/test/server/websocket/channel/server/join_test.exs index a02c0df5..eb2be674 100644 --- a/test/server/websocket/channel/server/join_test.exs +++ b/test/server/websocket/channel/server/join_test.exs @@ -33,7 +33,7 @@ defmodule Helix.Server.Websocket.Channel.Server.JoinTest do assert new_socket.assigns.gateway.entity_id == entity_id # metadata is valid - assert new_socket.assigns.meta.access_type == :local + assert new_socket.assigns.meta.access == :local # Does not have assigns exclusive to remote joins refute Map.has_key?(new_socket.assigns.gateway, :ip) @@ -168,7 +168,7 @@ defmodule Helix.Server.Websocket.Channel.Server.JoinTest do assert new_socket.assigns.destination.entity_id == destination_entity_id # Metadata is correct - assert new_socket.assigns.meta.access_type == :remote + assert new_socket.assigns.meta.access == :remote assert new_socket.assigns.meta.network_id == @internet_id # Other stuff diff --git a/test/server/websocket/requests/motherboard_update_test.exs b/test/server/websocket/requests/motherboard_update_test.exs index 189babab..c35bd650 100644 --- a/test/server/websocket/requests/motherboard_update_test.exs +++ b/test/server/websocket/requests/motherboard_update_test.exs @@ -26,7 +26,7 @@ defmodule Helix.Server.Websocket.Requests.MotherboardUpdateTest do @internet_id NetworkHelper.internet_id() - @mock_socket ChannelSetup.mock_server_socket(access_type: :local) + @mock_socket ChannelSetup.mock_server_socket(access: :local) describe "MotherboardUpdateRequest.check_params" do test "casts the params to internal Helix format" do @@ -215,7 +215,7 @@ defmodule Helix.Server.Websocket.Requests.MotherboardUpdateTest do ChannelSetup.mock_server_socket( gateway_id: server.server_id, gateway_entity_id: entity.entity_id, - access_type: :local + access: :local ) request = MotherboardUpdateRequest.new(params) @@ -267,7 +267,7 @@ defmodule Helix.Server.Websocket.Requests.MotherboardUpdateTest do ChannelSetup.mock_server_socket( gateway_id: server.server_id, gateway_entity_id: entity.entity_id, - access_type: :local + access: :local ) request = MotherboardUpdateRequest.new(params) @@ -287,7 +287,7 @@ defmodule Helix.Server.Websocket.Requests.MotherboardUpdateTest do ChannelSetup.mock_server_socket( gateway_id: server.server_id, gateway_entity_id: entity.entity_id, - access_type: :local + access: :local ) request = MotherboardUpdateRequest.new(params) @@ -354,7 +354,7 @@ defmodule Helix.Server.Websocket.Requests.MotherboardUpdateTest do ChannelSetup.mock_server_socket( gateway_id: server.server_id, gateway_entity_id: entity.entity_id, - access_type: :local + access: :local ) request = MotherboardUpdateRequest.new(params) @@ -419,7 +419,7 @@ defmodule Helix.Server.Websocket.Requests.MotherboardUpdateTest do ChannelSetup.mock_server_socket( gateway_id: server.server_id, gateway_entity_id: entity.entity_id, - access_type: :local + access: :local ) request = MotherboardUpdateRequest.new(params) diff --git a/test/support/channel/setup.ex b/test/support/channel/setup.ex index 89806171..bb141bba 100644 --- a/test/support/channel/setup.ex +++ b/test/support/channel/setup.ex @@ -252,7 +252,7 @@ defmodule Helix.Test.Channel.Setup do - destination_ip - destination_entity_id - network_id - - access_type: Inferred if not set + - access: Inferred if not set - own_server: Force socket to represent own server channel. Defaults to false. - counter: Defaults to 0. - connect_opts: Opts that will be relayed to the `mock_connection_socket` @@ -273,10 +273,10 @@ defmodule Helix.Test.Channel.Setup do {server_id, server_ip, entity_id} end - access_type = + access = cond do - opts[:access_type] -> - opts[:access_type] + opts[:access] -> + opts[:access] gateway_id == destination_id -> :local @@ -288,7 +288,7 @@ defmodule Helix.Test.Channel.Setup do network_id = Keyword.get(opts, :network_id, Network.ID.generate()) counter = Keyword.get(opts, :counter, 0) meta = %{ - access_type: access_type, + access: access, network_id: network_id, counter: counter } diff --git a/test/support/process/helper/view.ex b/test/support/process/helper/view.ex index 8f970b42..b98307ab 100644 --- a/test/support/process/helper/view.ex +++ b/test/support/process/helper/view.ex @@ -30,8 +30,8 @@ defmodule Helix.Test.Process.View.Helper do If `data` is expected to be empty, simply omit its parameter. """ - def assert_keys(rendered, access_type), - do: assert_keys(rendered, access_type, &empty_data_function/1) + def assert_keys(rendered, access), + do: assert_keys(rendered, access, &empty_data_function/1) def assert_keys(rendered, :full, data_function), do: check_view(rendered, :full, &pview_access_full/0, data_function) def assert_keys(rendered, :partial, data_function),