Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
[RTI-9513] Adjust for OTP23 (#18)
Browse files Browse the repository at this point in the history
* [RTI-9513] Adjust for OTP23

* [RTI-9513] Temporarily preserve http_uri functions until we move out of OTP22

* [RTI-9513] Fix pattern

* [RTI-9513] Fix it with macros

* [RTI-9513] Also remove http_uri:encode

* [RTI-9513] normalize is required before percent_decoding
  • Loading branch information
Brujo Benavides authored May 25, 2021
1 parent d66034b commit a24c1ad
Show file tree
Hide file tree
Showing 46 changed files with 297 additions and 278 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ifeq ($(REBAR_VSN),2)
@$(REBAR) compile
@$(REBAR) eunit skip_deps=true
else
@$(REBAR) eunit
@$(REBAR) do eunit, cover
endif

check:
Expand Down
12 changes: 8 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{erl_opts,
[debug_info,
{platform_define, "^19.|^2", 'ERLANG_OTP_VERSION_19'},
{platform_define, "^22.|^2", 'ERLANG_OTP_VERSION_22'},
strict_validation,
warn_bif_clash,
warn_deprecated_function,
Expand All @@ -17,9 +18,9 @@
warn_unused_vars]}.

{deps, [
{jsx, "2.10.0"},
{eini, "1.2.7"},
{base16, "1.0.0"}
{jsx, "3.1.0"},
{eini, "1.2.9"},
{base16, "2.0.0"}
]}.

{overrides,
Expand All @@ -31,6 +32,9 @@


{profiles, [
{test, [{deps, [{meck, "0.9.1"}]}]}
{test, [{deps, [{meck, "0.9.2"}]}]}
,{warnings, [{erl_opts, [warnings_as_errors]}]}
]}.

{cover_enabled, true}.
{cover_opts, [verbose]}.
18 changes: 9 additions & 9 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{"1.2.0",
[{<<"base16">>,{pkg,<<"base16">>,<<"1.0.0">>},0},
{<<"eini">>,{pkg,<<"eini">>,<<"1.2.7">>},0},
{<<"jsx">>,{pkg,<<"jsx">>,<<"2.10.0">>},0}]}.
[{<<"base16">>,{pkg,<<"base16">>,<<"2.0.0">>},0},
{<<"eini">>,{pkg,<<"eini">>,<<"1.2.9">>},0},
{<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},0}]}.
[
{pkg_hash,[
{<<"base16">>, <<"283644E2B21BD5915ACB7178BED7851FB07C6E5749B8FAD68A53C501092176D9">>},
{<<"eini">>, <<"EFC9D836E88591A47550BD34CE964E21CA1369F8716B24F73CFEA513FA99F666">>},
{<<"jsx">>, <<"77760560D6AC2B8C51FD4C980E9E19B784016AA70BE354CE746472C33BEB0B1C">>}]},
{<<"base16">>, <<"9DA694FA0778DF31522A1B9EB349BA4AC9063B497234DC49509C1F5C37F336A2">>},
{<<"eini">>, <<"FCC3CBD49BBDD9A1D9735C7365DAFFCD84481CCE81E6CB80537883AA44AC4895">>},
{<<"jsx">>, <<"D12516BAA0BB23A59BB35DCCAF02A1BD08243FCBB9EFE24F2D9D056CCFF71268">>}]},
{pkg_hash_ext,[
{<<"base16">>, <<"02AFD0827E61A7B07093873E063575CA3A2B07520567C7F8CEC7C5D42F052D76">>},
{<<"eini">>, <<"CD604597DCDB8AD76CCBAAF8C303EF94136729BA4AD6ABC88A4AB800E6D8E99A">>},
{<<"jsx">>, <<"9A83E3704807298016968DB506F9FAD0F027DE37546EB838B3AE1064C3A0AD62">>}]}
{<<"base16">>, <<"63067A9F73D2422F15344A1EAF7033C3B339DC64DA0229DE3DF26F0F6F1E4F82">>},
{<<"eini">>, <<"DA64AE8DB7C2F502E6F20CDF44CD3D9BE364412B87FF49FEBF282540F673DFCB">>},
{<<"jsx">>, <<"0C5CC8FDC11B53CC25CF65AC6705AD39E54ECC56D1C22E4ADB8F5A53FB9427F3">>}]}
].
2 changes: 1 addition & 1 deletion src/erlcloud_athena.erl
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ request(Config, Request) ->
Result = erlcloud_retry:request(Config, Request, fun handle_result/1),
case erlcloud_aws:request_to_return(Result) of
{ok, {_, <<>>}} -> {ok, #{}};
{ok, {_, RespBody}} -> {ok, jsx:decode(RespBody, [return_maps])};
{ok, {_, RespBody}} -> {ok, jsx:decode(RespBody)};
{error, _} = Error -> Error
end.

Expand Down
8 changes: 4 additions & 4 deletions src/erlcloud_aws.erl
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ region(Config) ->
{error, Reason} ->
{error, Reason};
{ok, Json} ->
Doc = jsx:decode(Json),
Doc = jsx:decode(Json, [{return_maps, false}]),
{ok, prop_to_list_defined(<<"region">>, Doc)}
end.

Expand All @@ -850,7 +850,7 @@ get_credentials_from_metadata(Config) ->
{error, Reason} ->
{error, Reason};
{ok, Json} ->
Creds = jsx:decode(Json),
Creds = jsx:decode(Json, [{return_maps, false}]),
get_credentials_from_metadata_xform( Creds )
end
end.
Expand All @@ -863,7 +863,7 @@ get_credentials_from_task_metadata(Config) ->
{error, Reason} ->
{error, Reason};
{ok, Json} ->
Creds = jsx:decode(Json),
Creds = jsx:decode(Json, [{return_maps, false}]),
get_credentials_from_metadata_xform( Creds )
end.

Expand Down Expand Up @@ -1114,7 +1114,7 @@ get_service_status(ServiceNames) when is_list(ServiceNames) ->
"/data.json", "", [], default_config()),

case get_filtered_statuses(ServiceNames,
proplists:get_value(<<"current">>, jsx:decode(Json)))
proplists:get_value(<<"current">>, jsx:decode(Json, [{return_maps, false}])))
of
[] -> ok;
ReturnStatuses -> ReturnStatuses
Expand Down
4 changes: 2 additions & 2 deletions src/erlcloud_cloudsearch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ cloudsearch_query(Config, Action, Params, ApiVersion) ->
[{"Accept", "application/json"}],
Config) of
{ok, Response} ->
{ok, jsx:decode(Response)};
{ok, jsx:decode(Response, [{return_maps, false}])};
{error, Reason} ->
{error, Reason}
end.
Expand All @@ -736,7 +736,7 @@ cloudsearch_post_json(Host, Path, Body,
[{"content-type", "application/json"} | Headers],
Config) of
{ok, RespBody} ->
{ok, jsx:decode(RespBody)};
{ok, jsx:decode(RespBody, [{return_maps, false}])};
{error, Reason} ->
{error, Reason}
end.
Expand Down
28 changes: 14 additions & 14 deletions src/erlcloud_cloudtrail.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ configure(AccessKeyID, SecretAccessKey, Host) ->
%%
-spec create_trail(string(), string(), aws_config()) -> ct_return().
create_trail(Trail, S3BucketName, Config) ->
Json = [{<<"Name">>, list_to_binary(Trail)},
Json = [{<<"Name">>, list_to_binary(Trail)},
{<<"S3BucketName">>, list_to_binary(S3BucketName)}
],
ct_request("CreateTrail", Json, Config).

-spec create_trail(string(), string(), string(), aws_config()) -> ct_return().
create_trail(Trail, S3BucketName, SnsTopicName, Config) ->
Json = [{<<"Name">>, list_to_binary(Trail)},
Json = [{<<"Name">>, list_to_binary(Trail)},
{<<"S3BucketName">>, list_to_binary(S3BucketName)},
{<<"SnsTopicName">>, list_to_binary(SnsTopicName)}
],
ct_request("CreateTrail", Json, Config).

-spec create_trail(string(), string(), string(), boolean(), aws_config()) -> ct_return().
create_trail(Trail, S3BucketName, SnsTopicName, IncludeGlobalServiceEvents, Config) ->
Json = [{<<"Name">>, list_to_binary(Trail)},
Json = [{<<"Name">>, list_to_binary(Trail)},
{<<"S3BucketName">>, list_to_binary(S3BucketName)},
{<<"SnsTopicName">>, list_to_binary(SnsTopicName)},
{<<"IncludeGlobalServiceEvents">>, list_to_binary(atom_to_list(IncludeGlobalServiceEvents))}
Expand All @@ -76,7 +76,7 @@ create_trail(Trail, S3BucketName, SnsTopicName, IncludeGlobalServiceEvents, Conf

-spec create_trail(string(), string(), string(), string(), boolean(), aws_config()) -> ct_return().
create_trail(Trail, S3BucketName, S3KeyPrefix, SnsTopicName, IncludeGlobalServiceEvents, Config) ->
Json = [{<<"Name">>, list_to_binary(Trail)},
Json = [{<<"Name">>, list_to_binary(Trail)},
{<<"S3BucketName">>, list_to_binary(S3BucketName)},
{<<"S3KeyPrefix">>, list_to_binary(S3KeyPrefix)},
{<<"SnsTopicName">>, list_to_binary(SnsTopicName)},
Expand Down Expand Up @@ -156,15 +156,15 @@ stop_logging(Trail, Config) ->

-spec update_trail(string(), string(), string(), aws_config()) -> ct_return().
update_trail(Trail, S3BucketName, SnsTopicName, Config) ->
Json = [{<<"Name">>, list_to_binary(Trail)},
Json = [{<<"Name">>, list_to_binary(Trail)},
{<<"S3BucketName">>, list_to_binary(S3BucketName)},
{<<"SnsTopicName">>, list_to_binary(SnsTopicName)}
],
ct_request("UpdateTrail", Json, Config).

-spec update_trail(string(), string(), string(), boolean(), aws_config()) -> ct_return().
update_trail(Trail, S3BucketName, SnsTopicName, IncludeGlobalServiceEvents, Config) ->
Json = [{<<"Name">>, list_to_binary(Trail)},
Json = [{<<"Name">>, list_to_binary(Trail)},
{<<"S3BucketName">>, list_to_binary(S3BucketName)},
{<<"SnsTopicName">>, list_to_binary(SnsTopicName)},
{<<"IncludeGlobalServiceEvents">>, list_to_binary(atom_to_list(IncludeGlobalServiceEvents))}
Expand All @@ -174,7 +174,7 @@ update_trail(Trail, S3BucketName, SnsTopicName, IncludeGlobalServiceEvents, Conf

-spec update_trail(string(), string(), string(), string(), boolean(), aws_config()) -> ct_return().
update_trail(Trail, S3BucketName, S3KeyPrefix, SnsTopicName, IncludeGlobalServiceEvents, Config) ->
Json = [{<<"Name">>, list_to_binary(Trail)},
Json = [{<<"Name">>, list_to_binary(Trail)},
{<<"S3BucketName">>, list_to_binary(S3BucketName)},
{<<"S3KeyPrefix">>, list_to_binary(S3KeyPrefix)},
{<<"SnsTopicName">>, list_to_binary(SnsTopicName)},
Expand All @@ -184,28 +184,28 @@ update_trail(Trail, S3BucketName, S3KeyPrefix, SnsTopicName, IncludeGlobalServic

% Json parameter must be a list of binary key/value tuples.
ct_request(Operation, [], Config) ->
#aws_config{cloudtrail_scheme = Scheme,
#aws_config{cloudtrail_scheme = Scheme,
cloudtrail_host = Host} = Config,
request_impl(post, Scheme, Host, port_spec(Config), "/", Operation, [], "{}", Config);

ct_request(Operation, Body, Config) ->
#aws_config{cloudtrail_scheme = Scheme,
#aws_config{cloudtrail_scheme = Scheme,
cloudtrail_host = Host} = Config,
request_impl(post, Scheme, Host, port_spec(Config), "/", Operation, [], jsx:encode(Body), Config).

request_impl(Method, Scheme, Host, Port, Path, Operation, Params, Body, #aws_config{} = Config) ->
%% TODO: Make api prefix a part of aws_config
Api_Operation = lists:flatten(?CLOUD_TRAIL_API_PREFIX, Operation),
Headers = headers(Config, Api_Operation, Params, Body, ?SERVICE_NAME),

case erlcloud_aws:aws_request_form_raw(
Method, Scheme, Host, Port, Path, Body,
[{"content-type", "application/x-amz-json-1.1"} | Headers],
Method, Scheme, Host, Port, Path, Body,
[{"content-type", "application/x-amz-json-1.1"} | Headers],
Config) of
{ok, RespBody} ->
case Config#aws_config.cloudtrail_raw_result of
true -> {ok, RespBody};
_ -> {ok, jsx:decode(RespBody)}
_ -> {ok, jsx:decode(RespBody, [{return_maps, false}])}
end;
{error, Reason} ->
{error, Reason}
Expand Down
2 changes: 1 addition & 1 deletion src/erlcloud_cloudwatch_logs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ maybe_cw_request({error, _} = Error, _Action, _Params) ->
maybe_json({ok, <<>>}) ->
{ok, []};
maybe_json({ok, Response}) ->
{ok, jsx:decode(Response)};
{ok, jsx:decode(Response, [{return_maps, false}])};
maybe_json({error, _} = Error) ->
Error.

Expand Down
2 changes: 1 addition & 1 deletion src/erlcloud_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ request(Config, Request) ->
Result = erlcloud_retry:request(Config, Request, fun handle_result/1),
case erlcloud_aws:request_to_return(Result) of
{ok, {_, <<>>}} -> {ok, #{}};
{ok, {_, RespBody}} -> {ok, jsx:decode(RespBody, [return_maps])};
{ok, {_, RespBody}} -> {ok, jsx:decode(RespBody)};
{error, _} = Error -> Error
end.

Expand Down
4 changes: 2 additions & 2 deletions src/erlcloud_cur.erl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ request(Config, Request) ->
case erlcloud_aws:request_to_return(Result) of
{ok, {_, <<>>}} -> {ok, #{}};
{ok, {_, RespBody}} ->
{ok, jsx:decode(RespBody, [return_maps])};
{ok, jsx:decode(RespBody)};
{error, _} = Error -> Error
end.

Expand Down Expand Up @@ -130,4 +130,4 @@ get_url(#aws_config{cur_scheme = Scheme,
Scheme ++ Host ++ ":" ++ integer_to_list(Port).

make_amz_target(Operation) ->
"AWSOrigamiServiceGatewayService." ++ binary_to_list(Operation).
"AWSOrigamiServiceGatewayService." ++ binary_to_list(Operation).
4 changes: 2 additions & 2 deletions src/erlcloud_ddb_impl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ request_and_retry(Config, Headers, Body, {attempt, Attempt}) ->

{ok, {{200, _}, _, RespBody}} ->
%% TODO check crc
{ok, jsx:decode(RespBody)};
{ok, jsx:decode(RespBody, [{return_maps, false}])};

Error ->
DDBError = #ddb2_error{attempt = Attempt,
Expand Down Expand Up @@ -230,7 +230,7 @@ client_error(Body, DDBError) ->
false ->
DDBError#ddb2_error{error_type = http, should_retry = false};
true ->
Json = jsx:decode(Body),
Json = jsx:decode(Body, [{return_maps, false}]),
case proplists:get_value(<<"__type">>, Json) of
undefined ->
DDBError#ddb2_error{error_type = http, should_retry = false};
Expand Down
4 changes: 2 additions & 2 deletions src/erlcloud_ddb_streams.erl
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ request2(Config, Operation, Json) ->
request_to_return(#aws_request{response_type = ok,
response_body = Body}) ->
%% TODO check crc
{ok, jsx:decode(Body)};
{ok, jsx:decode(Body, [{return_maps, false}])};
request_to_return(#aws_request{response_type = error,
error_type = aws,
httpc_error_reason = undefined,
Expand Down Expand Up @@ -868,7 +868,7 @@ client_error(#aws_request{response_body = Body} = Request) ->
false ->
Request#aws_request{should_retry = false};
true ->
Json = jsx:decode(Body),
Json = jsx:decode(Body, [{return_maps, false}]),
case proplists:get_value(<<"__type">>, Json) of
undefined ->
Request#aws_request{should_retry = false};
Expand Down
2 changes: 1 addition & 1 deletion src/erlcloud_directconnect.erl
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ dc_query(Operation, Params, Config) ->
[{<<"content-type">>, <<"application/x-amz-json-1.1">>} | Headers],
Body, 1000, Config)) of
{ok, {_RespHeader, RespBody}} ->
{ok, jsx:decode(RespBody)};
{ok, jsx:decode(RespBody, [{return_maps, false}])};
{error, Reason} ->
{error, Reason}
end.
Expand Down
2 changes: 1 addition & 1 deletion src/erlcloud_ecs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2466,7 +2466,7 @@ ecs_request_no_update(Config, Operation, Body) ->
request_body = Payload},
case erlcloud_aws:request_to_return(erlcloud_retry:request(Config, Request, fun ecs_result_fun/1)) of
{ok, {_RespHeaders, <<>>}} -> {ok, []};
{ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody)};
{ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody, [{return_maps, false}])};
{error, _} = Error-> Error
end.

Expand Down
4 changes: 2 additions & 2 deletions src/erlcloud_emr.erl
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ request_no_update(Action, Json, Scheme, Host, Port, Service, Opts, Cfg) ->
raw -> {ok, Body};
_ -> case Body of
<<>> -> {ok, <<>>};
_ -> {ok, jsx:decode(Body)}
_ -> {ok, jsx:decode(Body, [{return_maps, false}])}
end
end;
{error, {http_error, _Code, _StatusLine, ErrBody}} ->
{error, {aws_error, jsx:decode(ErrBody)}};
{error, {aws_error, jsx:decode(ErrBody, [{return_maps, false}])}};
{error, {socket_error, Reason}} ->
{error, {socket_error, Reason}}
end.
2 changes: 1 addition & 1 deletion src/erlcloud_glue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ request(Config, Request) ->
Result = erlcloud_retry:request(Config, Request, fun handle_result/1),
case erlcloud_aws:request_to_return(Result) of
{ok, {_, <<>>}} -> {ok, #{}};
{ok, {_, RespBody}} -> {ok, jsx:decode(RespBody, [return_maps])};
{ok, {_, RespBody}} -> {ok, jsx:decode(RespBody)};
{error, _} = Error -> Error
end.

Expand Down
2 changes: 1 addition & 1 deletion src/erlcloud_guardduty.erl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ guardduty_request_no_update(Config, Method, Path, QParam) ->
Method, Config#aws_config.guardduty_scheme, Config#aws_config.guardduty_host,
Config#aws_config.guardduty_port, Path, <<>>, Headers, Config) of
{ok, Data} ->
{ok, jsx:decode(Data)};
{ok, jsx:decode(Data, [{return_maps, false}])};
E ->
E
end.
Expand Down
8 changes: 7 additions & 1 deletion src/erlcloud_iam.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
-include("erlcloud.hrl").
-include("erlcloud_aws.hrl").
-include("erlcloud_iam.hrl").
-include_lib("xmerl/include/xmerl.hrl").

%% Library initialization.
-export([configure/2, configure/3, new/2, new/3, iam_query/5]).
Expand Down Expand Up @@ -1054,8 +1053,15 @@ data_fun("Integer") -> {erlcloud_xml, get_integer};
data_fun("Boolean") -> {erlcloud_xml, get_bool};
data_fun("Uri") -> {?MODULE, get_uri}.

-ifdef(ERLANG_OTP_VERSION_22).
get_uri(Key, Item) ->
http_uri:decode(erlcloud_xml:get_text(Key, Item)).
-else.
get_uri(Key, Item) ->
uri_string:percent_decode(
uri_string:normalize(
erlcloud_xml:get_text(Key, Item))).
-endif.

make_list_virtual_mfa_devices_params(undefined, undefined, undefined) ->
[];
Expand Down
2 changes: 1 addition & 1 deletion src/erlcloud_inspector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ inspector_request_no_update(Config, Operation, Body) ->
request_body = Payload},
case erlcloud_aws:request_to_return(erlcloud_retry:request(Config, Request, fun inspector_result_fun/1)) of
{ok, {_RespHeaders, <<>>}} -> {ok, []};
{ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody)};
{ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody, [{return_maps, false}])};
{error, _} = Error-> Error
end.

Expand Down
4 changes: 2 additions & 2 deletions src/erlcloud_kinesis_impl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ request_and_retry(Config, Headers, Body, ShouldDecode, {attempt, Attempt}) ->

-spec client_error(pos_integer(), string(), binary()) -> {retry, term()} | {error, term()}.
client_error(Status, StatusLine, Body) ->
try jsx:decode(Body) of
try jsx:decode(Body, [{return_maps, false}]) of
Json ->
Message = proplists:get_value(<<"message">>, Json, <<>>),
case proplists:get_value(<<"__type">>, Json) of
Expand Down Expand Up @@ -176,4 +176,4 @@ port_spec(#aws_config{kinesis_port=Port}) ->
[":", erlang:integer_to_list(Port)].

decode(<<>>) -> [];
decode(JSON) -> jsx:decode(JSON).
decode(JSON) -> jsx:decode(JSON, [{return_maps, false}]).
Loading

0 comments on commit a24c1ad

Please sign in to comment.