Current section

Files

Jump to
aws_erlang src aws_inspector2.erl
Raw

src/aws_inspector2.erl

%% WARNING: DO NOT EDIT, AUTO-GENERATED CODE!
%% See https://github.com/aws-beam/aws-codegen for more details.
%% @doc Amazon Inspector is a vulnerability discovery service that automates
%% continuous scanning for security vulnerabilities within your Amazon EC2
%% and Amazon ECR environments.
-module(aws_inspector2).
-export([associate_member/2,
associate_member/3,
batch_get_account_status/2,
batch_get_account_status/3,
batch_get_free_trial_info/2,
batch_get_free_trial_info/3,
cancel_findings_report/2,
cancel_findings_report/3,
create_filter/2,
create_filter/3,
create_findings_report/2,
create_findings_report/3,
delete_filter/2,
delete_filter/3,
describe_organization_configuration/2,
describe_organization_configuration/3,
disable/2,
disable/3,
disable_delegated_admin_account/2,
disable_delegated_admin_account/3,
disassociate_member/2,
disassociate_member/3,
enable/2,
enable/3,
enable_delegated_admin_account/2,
enable_delegated_admin_account/3,
get_configuration/2,
get_configuration/3,
get_delegated_admin_account/2,
get_delegated_admin_account/3,
get_findings_report_status/2,
get_findings_report_status/3,
get_member/2,
get_member/3,
list_account_permissions/2,
list_account_permissions/3,
list_coverage/2,
list_coverage/3,
list_coverage_statistics/2,
list_coverage_statistics/3,
list_delegated_admin_accounts/2,
list_delegated_admin_accounts/3,
list_filters/2,
list_filters/3,
list_finding_aggregations/2,
list_finding_aggregations/3,
list_findings/2,
list_findings/3,
list_members/2,
list_members/3,
list_tags_for_resource/2,
list_tags_for_resource/4,
list_tags_for_resource/5,
list_usage_totals/2,
list_usage_totals/3,
tag_resource/3,
tag_resource/4,
untag_resource/3,
untag_resource/4,
update_configuration/2,
update_configuration/3,
update_filter/2,
update_filter/3,
update_organization_configuration/2,
update_organization_configuration/3]).
-include_lib("hackney/include/hackney_lib.hrl").
%%====================================================================
%% API
%%====================================================================
%% @doc Associates an Amazon Web Services account with an Amazon Inspector
%% delegated administrator.
associate_member(Client, Input) ->
associate_member(Client, Input, []).
associate_member(Client, Input0, Options0) ->
Method = post,
Path = ["/members/associate"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Retrieves the Amazon Inspector status of multiple Amazon Web Services
%% accounts within your environment.
batch_get_account_status(Client, Input) ->
batch_get_account_status(Client, Input, []).
batch_get_account_status(Client, Input0, Options0) ->
Method = post,
Path = ["/status/batch/get"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Gets free trial status for multiple Amazon Web Services accounts.
batch_get_free_trial_info(Client, Input) ->
batch_get_free_trial_info(Client, Input, []).
batch_get_free_trial_info(Client, Input0, Options0) ->
Method = post,
Path = ["/freetrialinfo/batchget"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Cancels the given findings report.
cancel_findings_report(Client, Input) ->
cancel_findings_report(Client, Input, []).
cancel_findings_report(Client, Input0, Options0) ->
Method = post,
Path = ["/reporting/cancel"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Creates a filter resource using specified filter criteria.
create_filter(Client, Input) ->
create_filter(Client, Input, []).
create_filter(Client, Input0, Options0) ->
Method = post,
Path = ["/filters/create"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Creates a finding report.
create_findings_report(Client, Input) ->
create_findings_report(Client, Input, []).
create_findings_report(Client, Input0, Options0) ->
Method = post,
Path = ["/reporting/create"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Deletes a filter resource.
delete_filter(Client, Input) ->
delete_filter(Client, Input, []).
delete_filter(Client, Input0, Options0) ->
Method = post,
Path = ["/filters/delete"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Describe Amazon Inspector configuration settings for an Amazon Web
%% Services organization.
describe_organization_configuration(Client, Input) ->
describe_organization_configuration(Client, Input, []).
describe_organization_configuration(Client, Input0, Options0) ->
Method = post,
Path = ["/organizationconfiguration/describe"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Disables Amazon Inspector scans for one or more Amazon Web Services
%% accounts.
%%
%% Disabling all scan types in an account disables the Amazon Inspector
%% service.
disable(Client, Input) ->
disable(Client, Input, []).
disable(Client, Input0, Options0) ->
Method = post,
Path = ["/disable"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Disables the Amazon Inspector delegated administrator for your
%% organization.
disable_delegated_admin_account(Client, Input) ->
disable_delegated_admin_account(Client, Input, []).
disable_delegated_admin_account(Client, Input0, Options0) ->
Method = post,
Path = ["/delegatedadminaccounts/disable"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Disassociates a member account from an Amazon Inspector delegated
%% administrator.
disassociate_member(Client, Input) ->
disassociate_member(Client, Input, []).
disassociate_member(Client, Input0, Options0) ->
Method = post,
Path = ["/members/disassociate"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Enables Amazon Inspector scans for one or more Amazon Web Services
%% accounts.
enable(Client, Input) ->
enable(Client, Input, []).
enable(Client, Input0, Options0) ->
Method = post,
Path = ["/enable"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Enables the Amazon Inspector delegated administrator for your
%% Organizations organization.
enable_delegated_admin_account(Client, Input) ->
enable_delegated_admin_account(Client, Input, []).
enable_delegated_admin_account(Client, Input0, Options0) ->
Method = post,
Path = ["/delegatedadminaccounts/enable"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Retrieves setting configurations for Inspector scans.
get_configuration(Client, Input) ->
get_configuration(Client, Input, []).
get_configuration(Client, Input0, Options0) ->
Method = post,
Path = ["/configuration/get"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Retrieves information about the Amazon Inspector delegated
%% administrator for your organization.
get_delegated_admin_account(Client, Input) ->
get_delegated_admin_account(Client, Input, []).
get_delegated_admin_account(Client, Input0, Options0) ->
Method = post,
Path = ["/delegatedadminaccounts/get"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Gets the status of a findings report.
get_findings_report_status(Client, Input) ->
get_findings_report_status(Client, Input, []).
get_findings_report_status(Client, Input0, Options0) ->
Method = post,
Path = ["/reporting/status/get"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Gets member information for your organization.
get_member(Client, Input) ->
get_member(Client, Input, []).
get_member(Client, Input0, Options0) ->
Method = post,
Path = ["/members/get"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Lists the permissions an account has to configure Amazon Inspector.
list_account_permissions(Client, Input) ->
list_account_permissions(Client, Input, []).
list_account_permissions(Client, Input0, Options0) ->
Method = post,
Path = ["/accountpermissions/list"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Lists coverage details for you environment.
list_coverage(Client, Input) ->
list_coverage(Client, Input, []).
list_coverage(Client, Input0, Options0) ->
Method = post,
Path = ["/coverage/list"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Lists Amazon Inspector coverage statistics for your environment.
list_coverage_statistics(Client, Input) ->
list_coverage_statistics(Client, Input, []).
list_coverage_statistics(Client, Input0, Options0) ->
Method = post,
Path = ["/coverage/statistics/list"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Lists information about the Amazon Inspector delegated administrator
%% of your organization.
list_delegated_admin_accounts(Client, Input) ->
list_delegated_admin_accounts(Client, Input, []).
list_delegated_admin_accounts(Client, Input0, Options0) ->
Method = post,
Path = ["/delegatedadminaccounts/list"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Lists the filters associated with your account.
list_filters(Client, Input) ->
list_filters(Client, Input, []).
list_filters(Client, Input0, Options0) ->
Method = post,
Path = ["/filters/list"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Lists aggregated finding data for your environment based on specific
%% criteria.
list_finding_aggregations(Client, Input) ->
list_finding_aggregations(Client, Input, []).
list_finding_aggregations(Client, Input0, Options0) ->
Method = post,
Path = ["/findings/aggregation/list"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Lists findings for your environment.
list_findings(Client, Input) ->
list_findings(Client, Input, []).
list_findings(Client, Input0, Options0) ->
Method = post,
Path = ["/findings/list"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc List members associated with the Amazon Inspector delegated
%% administrator for your organization.
list_members(Client, Input) ->
list_members(Client, Input, []).
list_members(Client, Input0, Options0) ->
Method = post,
Path = ["/members/list"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Lists all tags attached to a given resource.
list_tags_for_resource(Client, ResourceArn)
when is_map(Client) ->
list_tags_for_resource(Client, ResourceArn, #{}, #{}).
list_tags_for_resource(Client, ResourceArn, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
list_tags_for_resource(Client, ResourceArn, QueryMap, HeadersMap, []).
list_tags_for_resource(Client, ResourceArn, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/tags/", aws_util:encode_uri(ResourceArn), ""],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false}
| Options0],
Headers = [],
Query_ = [],
request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode).
%% @doc Lists the Amazon Inspector usage totals over the last 30 days.
list_usage_totals(Client, Input) ->
list_usage_totals(Client, Input, []).
list_usage_totals(Client, Input0, Options0) ->
Method = post,
Path = ["/usage/list"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Adds tags to a resource.
tag_resource(Client, ResourceArn, Input) ->
tag_resource(Client, ResourceArn, Input, []).
tag_resource(Client, ResourceArn, Input0, Options0) ->
Method = post,
Path = ["/tags/", aws_util:encode_uri(ResourceArn), ""],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Removes tags from a resource.
untag_resource(Client, ResourceArn, Input) ->
untag_resource(Client, ResourceArn, Input, []).
untag_resource(Client, ResourceArn, Input0, Options0) ->
Method = delete,
Path = ["/tags/", aws_util:encode_uri(ResourceArn), ""],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
QueryMapping = [
{<<"tagKeys">>, <<"tagKeys">>}
],
{Query_, Input} = aws_request:build_headers(QueryMapping, Input2),
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Updates setting configurations for your Amazon Inspector account.
%%
%% When you use this API as an Amazon Inspector delegated administrator this
%% updates the setting for all accounts you manage. Member accounts in an
%% organization cannot update this setting.
update_configuration(Client, Input) ->
update_configuration(Client, Input, []).
update_configuration(Client, Input0, Options0) ->
Method = post,
Path = ["/configuration/update"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Specifies the action that is to be applied to the findings that match
%% the filter.
update_filter(Client, Input) ->
update_filter(Client, Input, []).
update_filter(Client, Input0, Options0) ->
Method = post,
Path = ["/filters/update"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Updates the configurations for your Amazon Inspector organization.
update_organization_configuration(Client, Input) ->
update_organization_configuration(Client, Input, []).
update_organization_configuration(Client, Input0, Options0) ->
Method = post,
Path = ["/organizationconfiguration/update"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%%====================================================================
%% Internal functions
%%====================================================================
-spec request(aws_client:aws_client(), atom(), iolist(), list(),
list(), map() | undefined, list(), pos_integer() | undefined) ->
{ok, {integer(), list()}} |
{ok, Result, {integer(), list(), hackney:client()}} |
{error, Error, {integer(), list(), hackney:client()}} |
{error, term()} when
Result :: map(),
Error :: map().
request(Client, Method, Path, Query, Headers0, Input, Options, SuccessStatusCode) ->
RequestFun = fun() -> do_request(Client, Method, Path, Query, Headers0, Input, Options, SuccessStatusCode) end,
aws_request:request(RequestFun, Options).
do_request(Client, Method, Path, Query, Headers0, Input, Options, SuccessStatusCode) ->
Client1 = Client#{service => <<"inspector2">>},
Host = build_host(<<"inspector2">>, Client1),
URL0 = build_url(Host, Path, Client1),
URL = aws_request:add_query(URL0, Query),
AdditionalHeaders1 = [ {<<"Host">>, Host}
, {<<"Content-Type">>, <<"application/x-amz-json-1.1">>}
],
Payload =
case proplists:get_value(send_body_as_binary, Options) of
true ->
maps:get(<<"Body">>, Input, <<"">>);
false ->
encode_payload(Input)
end,
AdditionalHeaders = case proplists:get_value(append_sha256_content_hash, Options, false) of
true ->
add_checksum_hash_header(AdditionalHeaders1, Payload);
false ->
AdditionalHeaders1
end,
Headers1 = aws_request:add_headers(AdditionalHeaders, Headers0),
MethodBin = aws_request:method_to_binary(Method),
SignedHeaders = aws_request:sign_request(Client1, MethodBin, URL, Headers1, Payload),
Response = hackney:request(Method, URL, SignedHeaders, Payload, Options),
DecodeBody = not proplists:get_value(receive_body_as_binary, Options),
handle_response(Response, SuccessStatusCode, DecodeBody).
add_checksum_hash_header(Headers, Body) ->
[ {<<"X-Amz-CheckSum-SHA256">>, base64:encode(crypto:hash(sha256, Body))}
| Headers
].
handle_response({ok, StatusCode, ResponseHeaders}, SuccessStatusCode, _DecodeBody)
when StatusCode =:= 200;
StatusCode =:= 202;
StatusCode =:= 204;
StatusCode =:= 206;
StatusCode =:= SuccessStatusCode ->
{ok, {StatusCode, ResponseHeaders}};
handle_response({ok, StatusCode, ResponseHeaders}, _, _DecodeBody) ->
{error, {StatusCode, ResponseHeaders}};
handle_response({ok, StatusCode, ResponseHeaders, Client}, SuccessStatusCode, DecodeBody)
when StatusCode =:= 200;
StatusCode =:= 202;
StatusCode =:= 204;
StatusCode =:= 206;
StatusCode =:= SuccessStatusCode ->
case hackney:body(Client) of
{ok, <<>>} when StatusCode =:= 200;
StatusCode =:= SuccessStatusCode ->
{ok, #{}, {StatusCode, ResponseHeaders, Client}};
{ok, Body} ->
Result = case DecodeBody of
true ->
try
jsx:decode(Body)
catch
Error:Reason:Stack ->
erlang:raise(error, {body_decode_failed, Error, Reason, StatusCode, Body}, Stack)
end;
false -> #{<<"Body">> => Body}
end,
{ok, Result, {StatusCode, ResponseHeaders, Client}}
end;
handle_response({ok, StatusCode, ResponseHeaders, Client}, _, _DecodeBody) ->
{ok, Body} = hackney:body(Client),
Error = jsx:decode(Body),
{error, Error, {StatusCode, ResponseHeaders, Client}};
handle_response({error, Reason}, _, _DecodeBody) ->
{error, Reason}.
build_host(_EndpointPrefix, #{region := <<"local">>, endpoint := Endpoint}) ->
Endpoint;
build_host(_EndpointPrefix, #{region := <<"local">>}) ->
<<"localhost">>;
build_host(EndpointPrefix, #{region := Region, endpoint := Endpoint}) ->
aws_util:binary_join([EndpointPrefix, Region, Endpoint], <<".">>).
build_url(Host, Path0, Client) ->
Proto = maps:get(proto, Client),
Path = erlang:iolist_to_binary(Path0),
Port = maps:get(port, Client),
aws_util:binary_join([Proto, <<"://">>, Host, <<":">>, Port, Path], <<"">>).
-spec encode_payload(undefined | map()) -> binary().
encode_payload(undefined) ->
<<>>;
encode_payload(Input) ->
jsx:encode(Input).