Spaces:
Sleeping
Sleeping
File size: 1,993 Bytes
2e92879 b2ff4b5 2e92879 76486d3 b2ff4b5 2e92879 b2ff4b5 0b53aa4 76486d3 0b53aa4 a8d7371 2e92879 b2ff4b5 2e92879 0b53aa4 2e92879 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
defmodule Srh.Http.RequestValidator do
def validate_redis_body(%{"_json" => command_array}) when is_list(command_array),
do: {:ok, command_array}
def validate_redis_body(_),
do:
{:error,
"Invalid command array. Expected a string array at root of the command and its arguments."}
def validate_pipeline_redis_body(%{"_json" => array_of_command_arrays})
when is_list(array_of_command_arrays) do
do_validate_pipeline_redis_body(array_of_command_arrays, array_of_command_arrays)
end
# any amount of items left
defp do_validate_pipeline_redis_body([first_item | rest], original) do
case do_validate_pipeline_item(first_item) do
:ok -> do_validate_pipeline_redis_body(rest, original)
:error -> {:error, "Invalid command array. Expected an array of string arrays at root."}
end
end
defp do_validate_pipeline_redis_body([], original), do: {:ok, original}
defp do_validate_pipeline_item(item) when is_list(item), do: :ok
defp do_validate_pipeline_item(_), do: :error
def validate_encoding_header(header_value_array) when is_list(header_value_array) do
do_validate_encoding_header(header_value_array)
end
# This has been broken up like this to future-proof different encoding modes in the future
defp do_validate_encoding_header([first_item | rest]) do
case first_item do
"base64" -> {:ok, true}
_ -> do_validate_encoding_header(rest)
end
end
defp do_validate_encoding_header([]), do: {:error, :not_found}
def validate_bearer_header(header_value_array) when is_list(header_value_array) do
do_validate_bearer_header(header_value_array)
end
# any amount of items left
defp do_validate_bearer_header([first_item | rest]) do
case first_item
|> String.split(" ") do
["Bearer", token] ->
{:ok, token}
_ ->
do_validate_bearer_header(rest)
end
end
# no items left
defp do_validate_bearer_header([]), do: {:error, :not_found}
end
|