Scott Hiett commited on
Commit
76486d3
1 Parent(s): ef22da3

Code cleaning

Browse files
README.md CHANGED
@@ -2,7 +2,7 @@
2
  A Redis connection pooler for serverless applications. This allows your serverless functions to talk to Redis via HTTP,
3
  while also not having to worry about the Redis max connection limits.
4
 
5
- The idea is you host this alongside your Redis server, so minimise latency. The serverless functions can then talk to
6
  this via HTTP.
7
 
8
  ## Features
 
2
  A Redis connection pooler for serverless applications. This allows your serverless functions to talk to Redis via HTTP,
3
  while also not having to worry about the Redis max connection limits.
4
 
5
+ The idea is you host this alongside your Redis server, to minimise latency. Your serverless functions can then talk to
6
  this via HTTP.
7
 
8
  ## Features
config/config.exs CHANGED
@@ -2,7 +2,6 @@ import Config
2
 
3
  config :srh,
4
  mode: "file",
5
- file_path: "srh-config/tokens.json",
6
- file_hard_reload: false
7
 
8
  import_config "#{config_env()}.exs"
 
2
 
3
  config :srh,
4
  mode: "file",
5
+ file_path: "srh-config/tokens.json"
 
6
 
7
  import_config "#{config_env()}.exs"
config/dev.exs CHANGED
@@ -1,4 +1 @@
1
  import Config
2
-
3
- config :srh,
4
- file_hard_reload: true
 
1
  import Config
 
 
 
lib/srh/auth/token_resolver.ex CHANGED
@@ -3,7 +3,6 @@ defmodule Srh.Auth.TokenResolver do
3
 
4
  @mode Application.fetch_env!(:srh, :mode)
5
  @file_path Application.fetch_env!(:srh, :file_path)
6
- @file_hard_reload Application.fetch_env!(:srh, :file_hard_reload)
7
 
8
  @ets_table_name :srh_token_resolver
9
 
@@ -74,7 +73,7 @@ defmodule Srh.Auth.TokenResolver do
74
  end
75
  end
76
 
77
- defp do_resolve("redis", token) do
78
  {
79
  :ok,
80
  # This is done to replicate what will eventually be API endpoints, so they keys are not atoms
 
3
 
4
  @mode Application.fetch_env!(:srh, :mode)
5
  @file_path Application.fetch_env!(:srh, :file_path)
 
6
 
7
  @ets_table_name :srh_token_resolver
8
 
 
73
  end
74
  end
75
 
76
+ defp do_resolve("redis", _token) do
77
  {
78
  :ok,
79
  # This is done to replicate what will eventually be API endpoints, so they keys are not atoms
lib/srh/http/base_router.ex CHANGED
@@ -49,7 +49,7 @@ defmodule Srh.Http.BaseRouter do
49
  {:malformed_data, message} -> %{code: 400, message: message, json: false}
50
  {:not_authorized, message} -> %{code: 401, message: message, json: false}
51
  {:server_error, _} -> %{code: 500, message: "An error occurred internally", json: false}
52
- other ->
53
  %{code: 500, message: "An error occurred internally", json: false}
54
  end
55
 
 
49
  {:malformed_data, message} -> %{code: 400, message: message, json: false}
50
  {:not_authorized, message} -> %{code: 401, message: message, json: false}
51
  {:server_error, _} -> %{code: 500, message: "An error occurred internally", json: false}
52
+ _ ->
53
  %{code: 500, message: "An error occurred internally", json: false}
54
  end
55
 
lib/srh/http/command_handler.ex CHANGED
@@ -38,7 +38,9 @@ defmodule Srh.Http.CommandHandler do
38
  end
39
  end
40
 
41
- defp dispatch_command_array([current | rest], connection_info, responses \\ []) do
 
 
42
  updated_responses = case dispatch_command(current, connection_info) do
43
  {:ok, result_map} ->
44
  [result_map | responses]
@@ -50,7 +52,7 @@ defmodule Srh.Http.CommandHandler do
50
  dispatch_command_array(rest, connection_info, updated_responses)
51
  end
52
 
53
- defp dispatch_command_array([], connection_info, responses) do
54
  # The responses will be in reverse order, as we're adding them to the list with the faster method of putting them at head.
55
  {:ok, Enum.reverse(responses)}
56
  end
 
38
  end
39
  end
40
 
41
+ defp dispatch_command_array(_arr, _connection_info, responses \\ [])
42
+
43
+ defp dispatch_command_array([current | rest], connection_info, responses) do
44
  updated_responses = case dispatch_command(current, connection_info) do
45
  {:ok, result_map} ->
46
  [result_map | responses]
 
52
  dispatch_command_array(rest, connection_info, updated_responses)
53
  end
54
 
55
+ defp dispatch_command_array([], _connection_info, responses) do
56
  # The responses will be in reverse order, as we're adding them to the list with the faster method of putting them at head.
57
  {:ok, Enum.reverse(responses)}
58
  end
lib/srh/http/request_validator.ex CHANGED
@@ -1,7 +1,7 @@
1
  defmodule Srh.Http.RequestValidator do
2
  def validate_redis_body(%{"_json" => command_array}) when is_list(command_array), do: {:ok, command_array}
3
 
4
- def validate_redis_body(payload),
5
  do: {:error, "Invalid command array. Expected a string array at root of the command and its arguments."}
6
 
7
  def validate_pipeline_redis_body(%{"_json" => array_of_command_arrays}) when is_list(array_of_command_arrays) do
@@ -20,7 +20,7 @@ defmodule Srh.Http.RequestValidator do
20
 
21
  defp do_validate_pipeline_item(item) when is_list(item), do: :ok
22
 
23
- defp do_validate_pipeline_item(item), do: :error
24
 
25
  def validate_bearer_header(header_value_array) when is_list(header_value_array) do
26
  do_validate_bearer_header(header_value_array)
 
1
  defmodule Srh.Http.RequestValidator do
2
  def validate_redis_body(%{"_json" => command_array}) when is_list(command_array), do: {:ok, command_array}
3
 
4
+ def validate_redis_body(_),
5
  do: {:error, "Invalid command array. Expected a string array at root of the command and its arguments."}
6
 
7
  def validate_pipeline_redis_body(%{"_json" => array_of_command_arrays}) when is_list(array_of_command_arrays) do
 
20
 
21
  defp do_validate_pipeline_item(item) when is_list(item), do: :ok
22
 
23
+ defp do_validate_pipeline_item(_), do: :error
24
 
25
  def validate_bearer_header(header_value_array) when is_list(header_value_array) do
26
  do_validate_bearer_header(header_value_array)
lib/srh/redis/client_worker.ex CHANGED
@@ -32,7 +32,7 @@ defmodule Srh.Redis.ClientWorker do
32
  end
33
  end
34
 
35
- def handle_call(msg, _from, state) do
36
  {:reply, :ok, state}
37
  end
38
 
 
32
  end
33
  end
34
 
35
+ def handle_call(_msg, _from, state) do
36
  {:reply, :ok, state}
37
  end
38