Spaces:
Sleeping
Sleeping
hiett
commited on
Commit
·
f085bb2
1
Parent(s):
7edc4a0
SSL support
Browse files
lib/srh/http/base_router.ex
CHANGED
|
@@ -26,7 +26,10 @@ defmodule Srh.Http.BaseRouter do
|
|
| 26 |
end
|
| 27 |
|
| 28 |
match _ do
|
| 29 |
-
handle_response(
|
|
|
|
|
|
|
|
|
|
| 30 |
end
|
| 31 |
|
| 32 |
defp do_command_request(conn, success_lambda) do
|
|
|
|
| 26 |
end
|
| 27 |
|
| 28 |
match _ do
|
| 29 |
+
handle_response(
|
| 30 |
+
{:not_found, "SRH: Endpoint not found. SRH might not support this feature yet."},
|
| 31 |
+
conn
|
| 32 |
+
)
|
| 33 |
end
|
| 34 |
|
| 35 |
defp do_command_request(conn, success_lambda) do
|
lib/srh/http/content_type_check_plug.ex
CHANGED
|
@@ -35,7 +35,10 @@ defmodule Srh.Http.ContentTypeCheckPlug do
|
|
| 35 |
# Return a custom error, ensuring the same format as the other errors
|
| 36 |
conn
|
| 37 |
|> put_resp_content_type("application/json")
|
| 38 |
-
|> send_resp(
|
|
|
|
|
|
|
|
|
|
| 39 |
|> halt()
|
| 40 |
end
|
| 41 |
end
|
|
|
|
| 35 |
# Return a custom error, ensuring the same format as the other errors
|
| 36 |
conn
|
| 37 |
|> put_resp_content_type("application/json")
|
| 38 |
+
|> send_resp(
|
| 39 |
+
400,
|
| 40 |
+
Jason.encode!(%{error: "Invalid content type. Expected application/json."})
|
| 41 |
+
)
|
| 42 |
|> halt()
|
| 43 |
end
|
| 44 |
end
|
lib/srh/redis/client.ex
CHANGED
|
@@ -3,7 +3,7 @@ defmodule Srh.Redis.Client do
|
|
| 3 |
alias Srh.Redis.ClientRegistry
|
| 4 |
alias Srh.Redis.ClientWorker
|
| 5 |
|
| 6 |
-
@idle_death_time 1000 * 15
|
| 7 |
|
| 8 |
def start_link(max_connections, connection_info) do
|
| 9 |
GenServer.start_link(__MODULE__, {max_connections, connection_info}, [])
|
|
|
|
| 3 |
alias Srh.Redis.ClientRegistry
|
| 4 |
alias Srh.Redis.ClientWorker
|
| 5 |
|
| 6 |
+
@idle_death_time 1000 * 60 * 15 # 15 minutes
|
| 7 |
|
| 8 |
def start_link(max_connections, connection_info) do
|
| 9 |
GenServer.start_link(__MODULE__, {max_connections, connection_info}, [])
|
lib/srh/redis/client_worker.ex
CHANGED
|
@@ -62,9 +62,29 @@ defmodule Srh.Redis.ClientWorker do
|
|
| 62 |
} = state
|
| 63 |
)
|
| 64 |
when is_binary(connection_string) do
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# NOTE: Redix only seems to open the connection when the first command is sent
|
| 66 |
# This means that this will return :ok even if the connection string may not actually be connectable
|
| 67 |
-
{:ok, pid} =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
{:noreply, %{state | redix_pid: pid}}
|
| 69 |
end
|
| 70 |
|
|
|
|
| 62 |
} = state
|
| 63 |
)
|
| 64 |
when is_binary(connection_string) do
|
| 65 |
+
enable_ssl = String.starts_with?(connection_string, "rediss://")
|
| 66 |
+
|
| 67 |
+
socket_opts =
|
| 68 |
+
case enable_ssl do
|
| 69 |
+
true ->
|
| 70 |
+
[
|
| 71 |
+
customize_hostname_check: [
|
| 72 |
+
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
|
| 73 |
+
]
|
| 74 |
+
]
|
| 75 |
+
|
| 76 |
+
false ->
|
| 77 |
+
[]
|
| 78 |
+
end
|
| 79 |
+
|
| 80 |
# NOTE: Redix only seems to open the connection when the first command is sent
|
| 81 |
# This means that this will return :ok even if the connection string may not actually be connectable
|
| 82 |
+
{:ok, pid} =
|
| 83 |
+
Redix.start_link(connection_string,
|
| 84 |
+
ssl: enable_ssl,
|
| 85 |
+
socket_opts: socket_opts
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
{:noreply, %{state | redix_pid: pid}}
|
| 89 |
end
|
| 90 |
|