%% WARNING: DO NOT EDIT, AUTO-GENERATED CODE!
%% See https://github.com/aws-beam/aws-codegen for more details.
%% @doc DeleteTrail cannot be called on
%% the shadow trails (replicated trails in other regions) of a trail that is
%% enabled in all regions.
delete_trail(Client, Input)
when is_map(Client), is_map(Input) ->
delete_trail(Client, Input, []).
delete_trail(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"DeleteTrail">>, Input, Options).
%% @doc Retrieves settings for one or more trails associated with the current
%% region for your account.
describe_trails(Client, Input)
when is_map(Client), is_map(Input) ->
describe_trails(Client, Input, []).
describe_trails(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"DescribeTrails">>, Input, Options).
%% @doc Describes the settings for the event selectors that you configured
%% for your trail. The information returned for your event selectors includes
%% the following:
%%
%%
GetInsightSelectors shows if
%% CloudTrail Insights event logging is enabled on the trail, and if it is,
%% which insight types are enabled. If you run
%% GetInsightSelectors on a trail that does not have Insights
%% events enabled, the operation throws the exception
%% InsightNotEnabledException
%%
%% For more information, see Logging
%% CloudTrail Insights Events for Trails in the AWS CloudTrail User
%% Guide.
get_insight_selectors(Client, Input)
when is_map(Client), is_map(Input) ->
get_insight_selectors(Client, Input, []).
get_insight_selectors(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"GetInsightSelectors">>, Input, Options).
%% @doc Returns settings information for a specified trail.
get_trail(Client, Input)
when is_map(Client), is_map(Input) ->
get_trail(Client, Input, []).
get_trail(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"GetTrail">>, Input, Options).
%% @doc Returns a JSON-formatted list of information about the specified
%% trail. Fields include information on delivery errors, Amazon SNS and
%% Amazon S3 errors, and start and stop logging times for each trail. This
%% operation returns trail status from a single region. To return trail
%% status from all regions, you must call the operation on each region.
get_trail_status(Client, Input)
when is_map(Client), is_map(Input) ->
get_trail_status(Client, Input, []).
get_trail_status(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"GetTrailStatus">>, Input, Options).
%% @doc Returns all public keys whose private keys were used to sign the
%% digest files within the specified time range. The public key is needed to
%% validate digest files that were signed with its corresponding private key.
%%
%% GetConsoleOutput and
%% RunInstances API operations occur in your account.
%%
%% RunInstances is a write-only event and it
%% matches your event selector. The trail logs the event.
%%
%% GetConsoleOutput is a read-only event but it
%% doesn't match your event selector. The trail doesn't log the event.
%%
%% PutEventSelectors operation must be called
%% from the region in which the trail was created; otherwise, an
%% InvalidHomeRegionException is thrown.
%%
%% You can configure up to five event selectors for each trail. For more
%% information, see Logging
%% Data and Management Events for Trails and Limits
%% in AWS CloudTrail in the AWS CloudTrail User Guide.
put_event_selectors(Client, Input)
when is_map(Client), is_map(Input) ->
put_event_selectors(Client, Input, []).
put_event_selectors(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"PutEventSelectors">>, Input, Options).
%% @doc Lets you enable Insights event logging by specifying the Insights
%% selectors that you want to enable on an existing trail. You also use
%% PutInsightSelectors to turn off Insights event logging, by
%% passing an empty list of insight types. In this release, only
%% ApiCallRateInsight is supported as an Insights selector.
put_insight_selectors(Client, Input)
when is_map(Client), is_map(Input) ->
put_insight_selectors(Client, Input, []).
put_insight_selectors(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"PutInsightSelectors">>, Input, Options).
%% @doc Removes the specified tags from a trail.
remove_tags(Client, Input)
when is_map(Client), is_map(Input) ->
remove_tags(Client, Input, []).
remove_tags(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"RemoveTags">>, Input, Options).
%% @doc Starts the recording of AWS API calls and log file delivery for a
%% trail. For a trail that is enabled in all regions, this operation must be
%% called from the region in which the trail was created. This operation
%% cannot be called on the shadow trails (replicated trails in other regions)
%% of a trail that is enabled in all regions.
start_logging(Client, Input)
when is_map(Client), is_map(Input) ->
start_logging(Client, Input, []).
start_logging(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"StartLogging">>, Input, Options).
%% @doc Suspends the recording of AWS API calls and log file delivery for the
%% specified trail. Under most circumstances, there is no need to use this
%% action. You can update a trail without stopping it first. This action is
%% the only way to stop recording. For a trail enabled in all regions, this
%% operation must be called from the region in which the trail was created,
%% or an InvalidHomeRegionException will occur. This operation
%% cannot be called on the shadow trails (replicated trails in other regions)
%% of a trail enabled in all regions.
stop_logging(Client, Input)
when is_map(Client), is_map(Input) ->
stop_logging(Client, Input, []).
stop_logging(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"StopLogging">>, Input, Options).
%% @doc Updates the settings that specify delivery of log files. Changes to a
%% trail do not require stopping the CloudTrail service. Use this action to
%% designate an existing bucket for log delivery. If the existing bucket has
%% previously been a target for CloudTrail log files, an IAM policy exists
%% for the bucket. UpdateTrail must be called from the region in
%% which the trail was created; otherwise, an
%% InvalidHomeRegionException is thrown.
update_trail(Client, Input)
when is_map(Client), is_map(Input) ->
update_trail(Client, Input, []).
update_trail(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"UpdateTrail">>, Input, Options).
%%====================================================================
%% Internal functions
%%====================================================================
-spec request(aws_client:aws_client(), binary(), map(), list()) ->
{ok, Result, {integer(), list(), hackney:client()}} |
{error, Error, {integer(), list(), hackney:client()}} |
{error, term()} when
Result :: map() | undefined,
Error :: {binary(), binary()}.
request(Client, Action, Input, Options) ->
Client1 = Client#{service => <<"cloudtrail">>},
Host = get_host(<<"cloudtrail">>, Client1),
URL = get_url(Host, Client1),
Headers = [
{<<"Host">>, Host},
{<<"Content-Type">>, <<"application/x-amz-json-1.1">>},
{<<"X-Amz-Target">>, << <<"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.">>/binary, Action/binary>>}
],
Payload = jsx:encode(Input),
SignedHeaders = aws_request:sign_request(Client1, <<"POST">>, URL, Headers, Payload),
Response = hackney:request(post, URL, SignedHeaders, Payload, Options),
handle_response(Response).
handle_response({ok, 200, ResponseHeaders, Client}) ->
case hackney:body(Client) of
{ok, <<>>} ->
{ok, undefined, {200, ResponseHeaders, Client}};
{ok, Body} ->
Result = jsx:decode(Body, [return_maps]),
{ok, Result, {200, ResponseHeaders, Client}}
end;
handle_response({ok, StatusCode, ResponseHeaders, Client}) ->
{ok, Body} = hackney:body(Client),
Error = jsx:decode(Body, [return_maps]),
Exception = maps:get(<<"__type">>, Error, undefined),
Reason = maps:get(<<"message">>, Error, undefined),
{error, {Exception, Reason}, {StatusCode, ResponseHeaders, Client}};
handle_response({error, Reason}) ->
{error, Reason}.
get_host(_EndpointPrefix, #{region := <<"local">>}) ->
<<"localhost">>;
get_host(EndpointPrefix, #{region := Region, endpoint := Endpoint}) ->
aws_util:binary_join([EndpointPrefix, <<".">>, Region, <<".">>, Endpoint], <<"">>).
get_url(Host, Client) ->
Proto = maps:get(proto, Client),
Port = maps:get(port, Client),
aws_util:binary_join([Proto, <<"://">>, Host, <<":">>, Port, <<"/">>], <<"">>).