%% WARNING: DO NOT EDIT, AUTO-GENERATED CODE! %% See https://github.com/aws-beam/aws-codegen for more details. -module(aws_identitystore). -export([describe_group/2, describe_group/3, describe_user/2, describe_user/3, list_groups/2, list_groups/3, list_users/2, list_users/3]). -include_lib("hackney/include/hackney_lib.hrl"). %%==================================================================== %% API %%==================================================================== %% @doc Retrieves the group metadata and attributes from `GroupId' in an %% identity store. describe_group(Client, Input) when is_map(Client), is_map(Input) -> describe_group(Client, Input, []). describe_group(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"DescribeGroup">>, Input, Options). %% @doc Retrieves the user metadata and attributes from `UserId' in an %% identity store. describe_user(Client, Input) when is_map(Client), is_map(Input) -> describe_user(Client, Input, []). describe_user(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"DescribeUser">>, Input, Options). %% @doc Lists the attribute name and value of the group that you specified in %% the search. %% %% We only support `DisplayName' as a valid filter attribute path currently, %% and filter is required. This API returns minimum attributes, including %% `GroupId' and group `DisplayName' in the response. list_groups(Client, Input) when is_map(Client), is_map(Input) -> list_groups(Client, Input, []). list_groups(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"ListGroups">>, Input, Options). %% @doc Lists the attribute name and value of the user that you specified in %% the search. %% %% We only support `UserName' as a valid filter attribute path currently, and %% filter is required. This API returns minimum attributes, including %% `UserId' and `UserName' in the response. list_users(Client, Input) when is_map(Client), is_map(Input) -> list_users(Client, Input, []). list_users(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"ListUsers">>, 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 :: map(). request(Client, Action, Input0, Options) -> Client1 = Client#{service => <<"identitystore">>}, Host = build_host(<<"identitystore">>, Client1), URL = build_url(Host, Client1), Headers = [ {<<"Host">>, Host}, {<<"Content-Type">>, <<"application/x-amz-json-1.1">>}, {<<"X-Amz-Target">>, <<"AWSIdentityStore.", Action/binary>>} ], Input = Input0, 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), {ok, Result, {200, ResponseHeaders, Client}} end; handle_response({ok, StatusCode, ResponseHeaders, Client}) -> {ok, Body} = hackney:body(Client), Error = jsx:decode(Body), {error, Error, {StatusCode, ResponseHeaders, Client}}; handle_response({error, Reason}) -> {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, Client) -> Proto = maps:get(proto, Client), Port = maps:get(port, Client), aws_util:binary_join([Proto, <<"://">>, Host, <<":">>, Port, <<"/">>], <<"">>).