Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Rename 'access_type' to 'access'
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomassaro committed Dec 16, 2017
1 parent 5d4faa0 commit 4c0844b
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions lib/process/public/view/process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 ::
Expand Down
6 changes: 3 additions & 3 deletions lib/server/event/motherboard.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions lib/server/public/index/hardware.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
%{
Expand Down
2 changes: 1 addition & 1 deletion lib/server/websocket/channel/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/server/websocket/channel/server/join.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions lib/server/websocket/requests/bootstrap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/server/websocket/requests/motherboard_update.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion lib/software/websocket/requests/cracker/bruteforce.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/software/websocket/requests/file/download.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/software/websocket/requests/pftp/file/add.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 = %{
Expand Down
2 changes: 1 addition & 1 deletion lib/software/websocket/requests/pftp/file/download.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
Expand Down
2 changes: 1 addition & 1 deletion lib/software/websocket/requests/pftp/file/remove.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 = %{
Expand Down
2 changes: 1 addition & 1 deletion lib/software/websocket/requests/pftp/server/disable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion lib/software/websocket/requests/pftp/server/enable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions test/server/event/motherboard_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/server/websocket/channel/server/join_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions test/server/websocket/requests/motherboard_update_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions test/support/channel/setup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions test/support/process/helper/view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 4c0844b

Please sign in to comment.