mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-03-20 15:41:39 +00:00
TODO: - [x] Cluster formation for all API and web nodes - [x] Injest Docker logs to Stackdriver - [x] Fix assets building for prod To finish later: - [ ] Structured logging: https://issuetracker.google.com/issues/285950891 - [ ] Better networking policy (eg. use public postmark ranges and deny all unwanted egress) - [ ] OpenTelemetry collector for Google Stackdriver - [ ] LoggerJSON.Plug integration --------- Signed-off-by: Andrew Dryga <andrew@dryga.com> Co-authored-by: Jamil <jamilbk@users.noreply.github.com>
44 lines
1.1 KiB
Elixir
44 lines
1.1 KiB
Elixir
defmodule API.Gateway.Socket do
|
|
use Phoenix.Socket
|
|
alias Domain.Gateways
|
|
require Logger
|
|
|
|
## Channels
|
|
|
|
channel "gateway", API.Gateway.Channel
|
|
|
|
## Authentication
|
|
|
|
@impl true
|
|
def connect(%{"token" => encrypted_secret} = attrs, socket, connect_info) do
|
|
%{user_agent: user_agent, peer_data: %{address: remote_ip}} = connect_info
|
|
|
|
attrs =
|
|
attrs
|
|
|> Map.take(~w[external_id name_suffix public_key])
|
|
|> Map.put("last_seen_user_agent", user_agent)
|
|
|> Map.put("last_seen_remote_ip", remote_ip)
|
|
|
|
with {:ok, token} <- Gateways.authorize_gateway(encrypted_secret),
|
|
{:ok, gateway} <- Gateways.upsert_gateway(token, attrs) do
|
|
socket =
|
|
socket
|
|
|> assign(:gateway, gateway)
|
|
|
|
{:ok, socket}
|
|
else
|
|
{:error, reason} ->
|
|
Logger.debug("Error connecting gateway websocket: #{inspect(reason)}")
|
|
{:error, reason}
|
|
end
|
|
end
|
|
|
|
def connect(_params, _socket, _connect_info) do
|
|
{:error, :missing_token}
|
|
end
|
|
|
|
@impl true
|
|
def id(%Gateways.Gateway{} = gateway), do: "gateway:#{gateway.id}"
|
|
def id(socket), do: id(socket.assigns.gateway)
|
|
end
|