Current section
Files
Jump to
Current section
Files
src/aws_trustedadvisor.erl
%% WARNING: DO NOT EDIT, AUTO-GENERATED CODE!
%% See https://github.com/aws-beam/aws-codegen for more details.
%% @doc TrustedAdvisor Public API
-module(aws_trustedadvisor).
-export([get_organization_recommendation/2,
get_organization_recommendation/4,
get_organization_recommendation/5,
get_recommendation/2,
get_recommendation/4,
get_recommendation/5,
list_checks/1,
list_checks/3,
list_checks/4,
list_organization_recommendation_accounts/2,
list_organization_recommendation_accounts/4,
list_organization_recommendation_accounts/5,
list_organization_recommendation_resources/2,
list_organization_recommendation_resources/4,
list_organization_recommendation_resources/5,
list_organization_recommendations/1,
list_organization_recommendations/3,
list_organization_recommendations/4,
list_recommendation_resources/2,
list_recommendation_resources/4,
list_recommendation_resources/5,
list_recommendations/1,
list_recommendations/3,
list_recommendations/4,
update_organization_recommendation_lifecycle/3,
update_organization_recommendation_lifecycle/4,
update_recommendation_lifecycle/3,
update_recommendation_lifecycle/4]).
-include_lib("hackney/include/hackney_lib.hrl").
%%====================================================================
%% API
%%====================================================================
%% @doc Get a specific recommendation within an AWS Organizations
%% organization.
%%
%% This API supports only prioritized recommendations.
get_organization_recommendation(Client, OrganizationRecommendationIdentifier)
when is_map(Client) ->
get_organization_recommendation(Client, OrganizationRecommendationIdentifier, #{}, #{}).
get_organization_recommendation(Client, OrganizationRecommendationIdentifier, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
get_organization_recommendation(Client, OrganizationRecommendationIdentifier, QueryMap, HeadersMap, []).
get_organization_recommendation(Client, OrganizationRecommendationIdentifier, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/v1/organization-recommendations/", aws_util:encode_uri(OrganizationRecommendationIdentifier), ""],
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 Get a specific Recommendation
get_recommendation(Client, RecommendationIdentifier)
when is_map(Client) ->
get_recommendation(Client, RecommendationIdentifier, #{}, #{}).
get_recommendation(Client, RecommendationIdentifier, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
get_recommendation(Client, RecommendationIdentifier, QueryMap, HeadersMap, []).
get_recommendation(Client, RecommendationIdentifier, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/v1/recommendations/", aws_util:encode_uri(RecommendationIdentifier), ""],
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 List a filterable set of Checks
list_checks(Client)
when is_map(Client) ->
list_checks(Client, #{}, #{}).
list_checks(Client, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
list_checks(Client, QueryMap, HeadersMap, []).
list_checks(Client, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/v1/checks"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false}
| Options0],
Headers = [],
Query0_ =
[
{<<"awsService">>, maps:get(<<"awsService">>, QueryMap, undefined)},
{<<"language">>, maps:get(<<"language">>, QueryMap, undefined)},
{<<"maxResults">>, maps:get(<<"maxResults">>, QueryMap, undefined)},
{<<"nextToken">>, maps:get(<<"nextToken">>, QueryMap, undefined)},
{<<"pillar">>, maps:get(<<"pillar">>, QueryMap, undefined)},
{<<"source">>, maps:get(<<"source">>, QueryMap, undefined)}
],
Query_ = [H || {_, V} = H <- Query0_, V =/= undefined],
request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode).
%% @doc Lists the accounts that own the resources for an organization
%% aggregate recommendation.
%%
%% This API only supports prioritized recommendations.
list_organization_recommendation_accounts(Client, OrganizationRecommendationIdentifier)
when is_map(Client) ->
list_organization_recommendation_accounts(Client, OrganizationRecommendationIdentifier, #{}, #{}).
list_organization_recommendation_accounts(Client, OrganizationRecommendationIdentifier, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
list_organization_recommendation_accounts(Client, OrganizationRecommendationIdentifier, QueryMap, HeadersMap, []).
list_organization_recommendation_accounts(Client, OrganizationRecommendationIdentifier, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/v1/organization-recommendations/", aws_util:encode_uri(OrganizationRecommendationIdentifier), "/accounts"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false}
| Options0],
Headers = [],
Query0_ =
[
{<<"affectedAccountId">>, maps:get(<<"affectedAccountId">>, QueryMap, undefined)},
{<<"maxResults">>, maps:get(<<"maxResults">>, QueryMap, undefined)},
{<<"nextToken">>, maps:get(<<"nextToken">>, QueryMap, undefined)}
],
Query_ = [H || {_, V} = H <- Query0_, V =/= undefined],
request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode).
%% @doc List Resources of a Recommendation within an Organization.
%%
%% This API only supports prioritized recommendations.
list_organization_recommendation_resources(Client, OrganizationRecommendationIdentifier)
when is_map(Client) ->
list_organization_recommendation_resources(Client, OrganizationRecommendationIdentifier, #{}, #{}).
list_organization_recommendation_resources(Client, OrganizationRecommendationIdentifier, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
list_organization_recommendation_resources(Client, OrganizationRecommendationIdentifier, QueryMap, HeadersMap, []).
list_organization_recommendation_resources(Client, OrganizationRecommendationIdentifier, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/v1/organization-recommendations/", aws_util:encode_uri(OrganizationRecommendationIdentifier), "/resources"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false}
| Options0],
Headers = [],
Query0_ =
[
{<<"affectedAccountId">>, maps:get(<<"affectedAccountId">>, QueryMap, undefined)},
{<<"maxResults">>, maps:get(<<"maxResults">>, QueryMap, undefined)},
{<<"nextToken">>, maps:get(<<"nextToken">>, QueryMap, undefined)},
{<<"regionCode">>, maps:get(<<"regionCode">>, QueryMap, undefined)},
{<<"status">>, maps:get(<<"status">>, QueryMap, undefined)}
],
Query_ = [H || {_, V} = H <- Query0_, V =/= undefined],
request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode).
%% @doc List a filterable set of Recommendations within an Organization.
%%
%% This API only supports prioritized recommendations.
list_organization_recommendations(Client)
when is_map(Client) ->
list_organization_recommendations(Client, #{}, #{}).
list_organization_recommendations(Client, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
list_organization_recommendations(Client, QueryMap, HeadersMap, []).
list_organization_recommendations(Client, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/v1/organization-recommendations"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false}
| Options0],
Headers = [],
Query0_ =
[
{<<"afterLastUpdatedAt">>, maps:get(<<"afterLastUpdatedAt">>, QueryMap, undefined)},
{<<"awsService">>, maps:get(<<"awsService">>, QueryMap, undefined)},
{<<"beforeLastUpdatedAt">>, maps:get(<<"beforeLastUpdatedAt">>, QueryMap, undefined)},
{<<"checkIdentifier">>, maps:get(<<"checkIdentifier">>, QueryMap, undefined)},
{<<"maxResults">>, maps:get(<<"maxResults">>, QueryMap, undefined)},
{<<"nextToken">>, maps:get(<<"nextToken">>, QueryMap, undefined)},
{<<"pillar">>, maps:get(<<"pillar">>, QueryMap, undefined)},
{<<"source">>, maps:get(<<"source">>, QueryMap, undefined)},
{<<"status">>, maps:get(<<"status">>, QueryMap, undefined)},
{<<"type">>, maps:get(<<"type">>, QueryMap, undefined)}
],
Query_ = [H || {_, V} = H <- Query0_, V =/= undefined],
request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode).
%% @doc List Resources of a Recommendation
list_recommendation_resources(Client, RecommendationIdentifier)
when is_map(Client) ->
list_recommendation_resources(Client, RecommendationIdentifier, #{}, #{}).
list_recommendation_resources(Client, RecommendationIdentifier, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
list_recommendation_resources(Client, RecommendationIdentifier, QueryMap, HeadersMap, []).
list_recommendation_resources(Client, RecommendationIdentifier, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/v1/recommendations/", aws_util:encode_uri(RecommendationIdentifier), "/resources"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false}
| Options0],
Headers = [],
Query0_ =
[
{<<"maxResults">>, maps:get(<<"maxResults">>, QueryMap, undefined)},
{<<"nextToken">>, maps:get(<<"nextToken">>, QueryMap, undefined)},
{<<"regionCode">>, maps:get(<<"regionCode">>, QueryMap, undefined)},
{<<"status">>, maps:get(<<"status">>, QueryMap, undefined)}
],
Query_ = [H || {_, V} = H <- Query0_, V =/= undefined],
request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode).
%% @doc List a filterable set of Recommendations
list_recommendations(Client)
when is_map(Client) ->
list_recommendations(Client, #{}, #{}).
list_recommendations(Client, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
list_recommendations(Client, QueryMap, HeadersMap, []).
list_recommendations(Client, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/v1/recommendations"],
SuccessStatusCode = 200,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false}
| Options0],
Headers = [],
Query0_ =
[
{<<"afterLastUpdatedAt">>, maps:get(<<"afterLastUpdatedAt">>, QueryMap, undefined)},
{<<"awsService">>, maps:get(<<"awsService">>, QueryMap, undefined)},
{<<"beforeLastUpdatedAt">>, maps:get(<<"beforeLastUpdatedAt">>, QueryMap, undefined)},
{<<"checkIdentifier">>, maps:get(<<"checkIdentifier">>, QueryMap, undefined)},
{<<"maxResults">>, maps:get(<<"maxResults">>, QueryMap, undefined)},
{<<"nextToken">>, maps:get(<<"nextToken">>, QueryMap, undefined)},
{<<"pillar">>, maps:get(<<"pillar">>, QueryMap, undefined)},
{<<"source">>, maps:get(<<"source">>, QueryMap, undefined)},
{<<"status">>, maps:get(<<"status">>, QueryMap, undefined)},
{<<"type">>, maps:get(<<"type">>, QueryMap, undefined)}
],
Query_ = [H || {_, V} = H <- Query0_, V =/= undefined],
request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode).
%% @doc Update the lifecyle of a Recommendation within an Organization.
%%
%% This API only supports prioritized recommendations.
update_organization_recommendation_lifecycle(Client, OrganizationRecommendationIdentifier, Input) ->
update_organization_recommendation_lifecycle(Client, OrganizationRecommendationIdentifier, Input, []).
update_organization_recommendation_lifecycle(Client, OrganizationRecommendationIdentifier, Input0, Options0) ->
Method = put,
Path = ["/v1/organization-recommendations/", aws_util:encode_uri(OrganizationRecommendationIdentifier), "/lifecycle"],
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 Update the lifecyle of a Recommendation.
%%
%% This API only supports prioritized recommendations.
update_recommendation_lifecycle(Client, RecommendationIdentifier, Input) ->
update_recommendation_lifecycle(Client, RecommendationIdentifier, Input, []).
update_recommendation_lifecycle(Client, RecommendationIdentifier, Input0, Options0) ->
Method = put,
Path = ["/v1/recommendations/", aws_util:encode_uri(RecommendationIdentifier), "/lifecycle"],
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 => <<"trustedadvisor">>},
Host = build_host(<<"trustedadvisor">>, 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)
when StatusCode =:= 503 ->
%% Retriable error if retries are enabled
{error, service_unavailable};
handle_response({ok, StatusCode, ResponseHeaders, Client}, _, _DecodeBody) ->
{ok, Body} = hackney:body(Client),
try
DecodedError = jsx:decode(Body),
{error, DecodedError, {StatusCode, ResponseHeaders, Client}}
catch
Error:Reason:Stack ->
erlang:raise(error, {body_decode_failed, Error, Reason, StatusCode, Body}, Stack)
end;
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 = aws_client:proto(Client),
Path = erlang:iolist_to_binary(Path0),
Port = aws_client: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).