From 066341a108f42002305e767b5da207ed6cac6c53 Mon Sep 17 00:00:00 2001 From: T Floyd Wright Date: Sun, 4 Oct 2020 10:21:53 -0500 Subject: [PATCH] Add support for overriding host --- priv/post.erl.eex | 2 ++ priv/post.ex.eex | 3 +++ priv/rest.erl.eex | 2 ++ priv/rest.ex.eex | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/priv/post.erl.eex b/priv/post.erl.eex index 91ca73e..eaf6903 100644 --- a/priv/post.erl.eex +++ b/priv/post.erl.eex @@ -69,6 +69,8 @@ handle_response({error, Reason}) -> build_host(_EndpointPrefix, #{region := <<"local">>, endpoint := Endpoint}) -> Endpoint; +build_host(_EndpointPrefix, #{host := Host}) when is_binary(Host) -> + Host; build_host(_EndpointPrefix, #{region := <<"local">>}) -> <<"localhost">>;<%= if context.is_global do %> build_host(EndpointPrefix, #{endpoint := Endpoint}) -> diff --git a/priv/post.ex.eex b/priv/post.ex.eex index 8c6a0f8..926dd39 100644 --- a/priv/post.ex.eex +++ b/priv/post.ex.eex @@ -52,6 +52,9 @@ defmodule <%= context.module_name %> do defp build_host(_endpoint_prefix, %{region: "local", endpoint: endpoint}) do endpoint end + defp build_host(_endpoint_prefix, %{host: host}) when is_binary(host) do + host + end defp build_host(_endpoint_prefix, %{region: "local"}) do "localhost" end<%= if context.is_global do %> diff --git a/priv/rest.erl.eex b/priv/rest.erl.eex index 3aebea0..582260c 100644 --- a/priv/rest.erl.eex +++ b/priv/rest.erl.eex @@ -150,6 +150,8 @@ handle_response({ok, StatusCode, ResponseHeaders, Client}, _) -> {error, Error, {StatusCode, ResponseHeaders, Client}}; handle_response({error, Reason}, _) -> {error, Reason}. +build_host(_AccountId, _EndpointPrefix, #{host := Host}) when is_binary(Host) -> + Host; <%= if context.endpoint_prefix == "s3-control" do %> build_host(_AccountId, _EndpointPrefix, #{region := <<"local">>, endpoint := Endpoint}) -> Endpoint; diff --git a/priv/rest.ex.eex b/priv/rest.ex.eex index 8fc86cf..50620b1 100644 --- a/priv/rest.ex.eex +++ b/priv/rest.ex.eex @@ -133,6 +133,10 @@ defmodule <%= context.module_name %> do {:error, %HTTPoison.Error{reason: reason}} end end + + defp build_host(_endpoint_prefix, %{host: host}) when is_binary(host) do + host + end <%= if context.endpoint_prefix == "s3-control" do %> defp build_host(_account_id, _endpoint_prefix, %{region: "local", endpoint: endpoint}) do endpoint